Skip to content

Commit 118e0ef

Browse files
committed
Added websocket client ping (#30)
1 parent 1d12093 commit 118e0ef

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ const defaultConfiguration = {
5252
}
5353
},
5454
ws: {
55-
port: null
55+
port: null,
56+
ping: 30 * 1000
5657
},
5758
proxy: [
5859
/*

src/providers/core.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ class CoreServiceProvider extends ServiceProvider {
165165
ws.upgradeReq = ws.upgradeReq || req;
166166
ws._osjs_client = Object.assign({}, req.session.user);
167167

168+
const interval = this.core.config('ws.ping', 0);
169+
170+
const pingInterval = interval ? setInterval(() => {
171+
ws.send(JSON.stringify({
172+
name: 'osjs/core:ping'
173+
}));
174+
}, interval) : undefined;
175+
176+
ws.on('close', () => {
177+
clearInterval(pingInterval);
178+
});
179+
168180
ws.on('message', msg => {
169181
try {
170182
const {name, params} = JSON.parse(msg);

0 commit comments

Comments
 (0)