mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 22:17:31 +03:00
Added browser ping/pong settings.
This commit is contained in:
parent
cf9ac8d2b3
commit
268cd82b7d
13
meshuser.js
13
meshuser.js
@ -75,11 +75,23 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
// Clean a IPv6 address that encodes a IPv4 address
|
||||
function cleanRemoteAddr(addr) { if (addr.startsWith('::ffff:')) { return addr.substring(7); } else { return addr; } }
|
||||
|
||||
// Send a PING/PONG message
|
||||
function sendPing() { obj.ws.send('{"action":"ping"}'); }
|
||||
function sendPong() { obj.ws.send('{"action":"pong"}'); }
|
||||
|
||||
// Setup the agent PING/PONG timers
|
||||
if ((typeof args.browserping == 'number') && (obj.pingtimer == null)) { obj.pingtimer = setInterval(sendPing, args.browserping * 1000); }
|
||||
else if ((typeof args.browserpong == 'number') && (obj.pongtimer == null)) { obj.pongtimer = setInterval(sendPong, args.browserpong * 1000); }
|
||||
|
||||
// Disconnect this user
|
||||
obj.close = function (arg) {
|
||||
if ((arg == 1) || (arg == null)) { try { ws.close(); parent.parent.debug('user', 'Soft disconnect'); } catch (e) { console.log(e); } } // Soft close, close the websocket
|
||||
if (arg == 2) { try { ws._socket._parent.end(); parent.parent.debug('user', 'Hard disconnect'); } catch (e) { console.log(e); } } // Hard close, close the TCP socket
|
||||
|
||||
// Perform timer cleanup
|
||||
if (obj.pingtimer) { clearInterval(obj.pingtimer); delete obj.pingtimer; }
|
||||
if (obj.pongtimer) { clearInterval(obj.pongtimer); delete obj.pongtimer; }
|
||||
|
||||
// Perform cleanup
|
||||
parent.parent.RemoveAllEventDispatch(ws);
|
||||
if (obj.serverStatsTimer != null) { clearInterval(obj.serverStatsTimer); delete obj.serverStatsTimer; }
|
||||
@ -418,6 +430,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (common.validateString(command.action, 3, 32) == false) return; // Action must be a string between 3 and 32 chars
|
||||
|
||||
switch (command.action) {
|
||||
case 'pong': { break; } // NOP
|
||||
case 'ping': { try { ws.send(JSON.stringify({ action: 'pong' })); } catch (ex) { } break; }
|
||||
case 'intersession':
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ var MeshServerCreateControl = function (domain, authCookie) {
|
||||
var message;
|
||||
try { message = JSON.parse(e.data); } catch (e) { return; }
|
||||
if ((typeof message != 'object') || (message.action == 'pong')) { return; }
|
||||
if (message.action == 'ping') { obj.send({ action: 'pong' }); }
|
||||
if (message.action == 'close') { if (message.msg) { console.log(message.msg); } obj.Stop(message.cause); return; }
|
||||
if (obj.trace) { console.log('RECV', message); }
|
||||
if (obj.onMessage) obj.onMessage(obj, message);
|
||||
|
@ -35,6 +35,8 @@
|
||||
"_Nice404": false,
|
||||
"_ClickOnce": false,
|
||||
"_SelfUpdate": true,
|
||||
"_BrowserPing": 60,
|
||||
"_BrowserPong": 60,
|
||||
"_AgentPing": 60,
|
||||
"_AgentPong": 60,
|
||||
"_AgentIdleTimeout": 150,
|
||||
|
Loading…
Reference in New Issue
Block a user