fix not sending latest syncs to client

This commit is contained in:
zadam 2019-10-29 20:19:28 +01:00
parent 2f2a14d4b8
commit 68faa47c6f
2 changed files with 2 additions and 5 deletions

View file

@ -106,7 +106,7 @@ function checkSyncIdListeners() {
.filter(l => l.desiredSyncId > lastSyncId);
syncIdReachedListeners.filter(l => Date.now() > l.start - 60000)
.forEach(l => console.log(`Waiting for syncId ${l.desiredSyncId} while current is ${lastSyncId} for ${Date.now() - l.start}`));
.forEach(l => console.log(`Waiting for syncId ${l.desiredSyncId} while current is ${lastSyncId} for ${Math.floor((Date.now() - l.start) / 1000)}s`));
}
async function consumeSyncData() {

View file

@ -5,7 +5,6 @@ const sql = require('./sql');
const syncMutexService = require('./sync_mutex');
let webSocketServer;
let lastSyncId = 0;
function init(httpServer, sessionParser) {
webSocketServer = new WebSocket.Server({
@ -29,13 +28,11 @@ function init(httpServer, sessionParser) {
ws.on('message', messageJson => {
const message = JSON.parse(messageJson);
lastSyncId = Math.max(lastSyncId, message.lastSyncId);
if (message.type === 'log-error') {
log.error('JS Error: ' + message.error);
}
else if (message.type === 'ping') {
syncMutexService.doExclusively(async () => await sendPing(ws, lastSyncId));
syncMutexService.doExclusively(async () => await sendPing(ws, message.lastSyncId));
}
else {
log.error('Unrecognized message: ');