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