diff options
author | Wu Cheng-Han | 2015-09-27 11:43:33 +0800 |
---|---|---|
committer | Wu Cheng-Han | 2015-09-27 11:43:33 +0800 |
commit | ab6d6c77f1fb46033d5096aa650c23c589d963c3 (patch) | |
tree | 9cdf6ec6b807014dbb17c9f67f3af1b73afd9f4c /lib | |
parent | 332413bcaa7e1c810f236239474d997eb5d1aa43 (diff) |
Updated realtime to clear socket queue in all exceptions of connect and disconnect
Diffstat (limited to '')
-rw-r--r-- | lib/realtime.js | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/realtime.js b/lib/realtime.js index 23464099..3e99a12d 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -247,6 +247,15 @@ function emitRefresh(socket) { }); } +function clearSocketQueue(queue, socket) { + for (var i = 0; i < queue.length; i++) { + if (!queue[i] || queue[i].id == socket.id) { + queue.splice(i, 1); + i--; + } + } +} + var isConnectionBusy = false; var connectionSocketQueue = []; var isDisconnectBusy = false; @@ -263,12 +272,7 @@ function finishConnection(socket, note, user) { emitRefresh(socket); //clear finished socket in queue - for (var i = 0; i < connectionSocketQueue.length; i++) { - if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) { - connectionSocketQueue.splice(i, 1); - i--; - } - } + clearSocketQueue(connectionSocketQueue, socket); //seek for next socket isConnectionBusy = false; if (connectionSocketQueue.length > 0) @@ -291,6 +295,7 @@ function startConnection(socket) { var notename = getNotenameFromSocket(socket); if (!notename) { + clearSocketQueue(connectionSocketQueue, socket); isConnectionBusy = false; return; } @@ -303,12 +308,7 @@ function startConnection(socket) { }); socket.disconnect(true); //clear err socket in queue - for (var i = 0; i < connectionSocketQueue.length; i++) { - if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) { - connectionSocketQueue.splice(i, 1); - i--; - } - } + clearSocketQueue(connectionSocketQueue, socket); isConnectionBusy = false; return logger.error(err); } @@ -320,6 +320,7 @@ function startConnection(socket) { Note.findOrNewNote(notename, permission, function (err, note) { if (err) { responseError(res, "404", "Not Found", "oops."); + clearSocketQueue(connectionSocketQueue, socket); isConnectionBusy = false; return; } @@ -393,12 +394,7 @@ function disconnect(socket) { emitOnlineUsers(socket); //clear finished socket in queue - for (var i = 0; i < disconnectSocketQueue.length; i++) { - if (!disconnectSocketQueue[i] || disconnectSocketQueue[i].id == socket.id) { - disconnectSocketQueue.splice(i, 1); - i--; - } - } + clearSocketQueue(disconnectSocketQueue, socket); //seek for next socket isDisconnectBusy = false; if (disconnectSocketQueue.length > 0) |