Attempt to reconnect?
Attempt to reconnect?
This commit is contained in:
33
hqnode.js
33
hqnode.js
@@ -19,19 +19,6 @@ const removePlayer = (userId) => {
|
||||
playersInGame = playersInGame.filter((player) => player.userId !== userId);
|
||||
}
|
||||
|
||||
let TIMEOUT = null;
|
||||
|
||||
const ping = (ws) => {
|
||||
ws.ping();
|
||||
TIMEOUT = setTimeout(() => {
|
||||
console.log('Connection Closed');
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const pong = () => {
|
||||
clearTimeout(TIMEOUT);
|
||||
};
|
||||
|
||||
request('https://api-quiz.hype.space/shows/now', (error, response, body) => {
|
||||
const result = JSON.parse(body);
|
||||
|
||||
@@ -44,6 +31,22 @@ request('https://api-quiz.hype.space/shows/now', (error, response, body) => {
|
||||
Authorization: `Bearer ${INIT_TOKEN}`,
|
||||
},
|
||||
};
|
||||
|
||||
let TIMEOUT = null;
|
||||
|
||||
const ping = (ws) => {
|
||||
ws.ping();
|
||||
TIMEOUT = setTimeout(() => {
|
||||
console.log('Master connection closed. Attempting to reconnnect...');
|
||||
ws.terminate();
|
||||
ws = new WebSocket(socketUrl, playerOptions);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
const pong = () => {
|
||||
clearTimeout(TIMEOUT);
|
||||
};
|
||||
|
||||
const ws = new WebSocket(socketUrl, options);
|
||||
|
||||
ws.on('error', (err) => {
|
||||
@@ -67,7 +70,9 @@ request('https://api-quiz.hype.space/shows/now', (error, response, body) => {
|
||||
const ping = (ws) => {
|
||||
ws.ping();
|
||||
pTimeout = setTimeout(() => {
|
||||
console.log(`Player ${player.username} connection closed`);
|
||||
console.log(`Player ${player.username} connection closed. Attempting to reconnect...`);
|
||||
ws.terminate();
|
||||
ws = new WebSocket(socketUrl, playerOptions);
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user