Attempt to reconnect?

Attempt to reconnect?
This commit is contained in:
eTronic
2018-06-24 21:43:07 -04:00
parent bdc3ab3d62
commit be86ec14a8

View File

@@ -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);
};