Compare commits

...

2 Commits

Author SHA1 Message Date
ThePendulum aeb405967b 1.28.1 2024-01-13 02:26:05 +01:00
ThePendulum 73e60b81f1 Added ping. 2024-01-13 02:26:03 +01:00
3 changed files with 26 additions and 4 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.28.0",
"version": "1.28.1",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.28.0",
"version": "1.28.1",
"license": "ISC",
"dependencies": {
"better-sqlite3": "^8.3.0",

View File

@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.28.0",
"version": "1.28.1",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {

View File

@ -149,7 +149,14 @@ async function connect(bot, games) {
},
});
socket.ws.on('message', async (msg) => {
socket.ws.on('message', async (msgData) => {
const msg = msgData.toString();
if (typeof msg === 'string' && msg.includes('pong')) {
logger.debug(`Received pong ${msg.split(':')[1]}`);
return;
}
const [domain, data] = JSON.parse(msg);
logger.debug(`Received ${domain}: ${JSON.stringify(data)}`);
@ -187,6 +194,21 @@ async function connect(bot, games) {
socket.ws.send(JSON.stringify([domain, data]));
};
function ping() {
setTimeout(() => {
if (socket.ws && socket.ws?.readyState === socket.ws?.OPEN) {
const now = Date.now();
socket.ws.send(`ping:${now}`);
logger.debug(`Sent ping ${now}`);
}
ping();
}, 10000);
}
ping();
socket.connect();
return socket;