Heartbeat debug.

master
Ben Burlingham 5 years ago
parent fe1738e3d7
commit 9e682e795c
  1. 12
      client/connection.js
  2. 2
      server/ricochet.js

@ -17,6 +17,10 @@ const Connection = function() {
this.connect(); this.connect();
}); });
document.addEventListener('G-heartbeat', () => {
this.heartbeat();
});
document.addEventListener('L-newround', () => this.send({ type: 'newround' }) ); document.addEventListener('L-newround', () => this.send({ type: 'newround' }) );
document.addEventListener('L-objective', () => this.send({ type: 'objective' }) ); document.addEventListener('L-objective', () => this.send({ type: 'objective' }) );
@ -49,13 +53,16 @@ Connection.prototype.send = function(json) {
} }
}; };
Connection.prototype.heartbeat = function() {
setTimeout(this.send.bind(this, { type: 'heartbeat' }), 30000);
};
//===== Connection event handlers //===== Connection event handlers
Connection.prototype.onOpen = function() { Connection.prototype.onOpen = function() {
this.retryCounter = 0; this.retryCounter = 0;
clearTimeout(this.heartbeatTimer); this.heartbeat();
this.heartbeatTimer = setTimeout(() => { this.ws.send({ type: 'heartbeat' }); }, 30000);
const evt = new Event('L-conn-open'); const evt = new Event('L-conn-open');
document.dispatchEvent(evt); document.dispatchEvent(evt);
@ -95,6 +102,7 @@ Connection.prototype.onReceiveMessage = function({ data }) {
case 'connected': eventName = 'G-connected'; break; case 'connected': eventName = 'G-connected'; break;
case 'countdown': eventName = 'G-countdown'; break; case 'countdown': eventName = 'G-countdown'; break;
case 'full': eventName = 'G-full'; break; case 'full': eventName = 'G-full'; break;
case 'heartbeat': eventName = 'G-heartbeat'; break;
case 'newround': eventName = 'G-newround'; break; case 'newround': eventName = 'G-newround'; break;
case 'objective': eventName = 'G-objective'; break; case 'objective': eventName = 'G-objective'; break;
case 'players': eventName = 'G-players'; break; case 'players': eventName = 'G-players'; break;

@ -248,7 +248,7 @@ Ricochet.prototype.onMessage = function(ws, rawBody) {
}; };
//===== Message handlers //===== Message handlers
Ricochet.prototype.msgHeartbeat = function() { Ricochet.prototype.msgHeartbeat = function(ws) {
this.messenger.messageOne(ws, { type: 'heartbeat' }); this.messenger.messageOne(ws, { type: 'heartbeat' });
}; };

Loading…
Cancel
Save