Updated realtime to clear socket queue in all exceptions of connect and disconnect
This commit is contained in:
parent
332413bcaa
commit
ab6d6c77f1
1 changed files with 14 additions and 18 deletions
|
@ -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 isConnectionBusy = false;
|
||||||
var connectionSocketQueue = [];
|
var connectionSocketQueue = [];
|
||||||
var isDisconnectBusy = false;
|
var isDisconnectBusy = false;
|
||||||
|
@ -263,12 +272,7 @@ function finishConnection(socket, note, user) {
|
||||||
emitRefresh(socket);
|
emitRefresh(socket);
|
||||||
|
|
||||||
//clear finished socket in queue
|
//clear finished socket in queue
|
||||||
for (var i = 0; i < connectionSocketQueue.length; i++) {
|
clearSocketQueue(connectionSocketQueue, socket);
|
||||||
if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) {
|
|
||||||
connectionSocketQueue.splice(i, 1);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//seek for next socket
|
//seek for next socket
|
||||||
isConnectionBusy = false;
|
isConnectionBusy = false;
|
||||||
if (connectionSocketQueue.length > 0)
|
if (connectionSocketQueue.length > 0)
|
||||||
|
@ -291,6 +295,7 @@ function startConnection(socket) {
|
||||||
|
|
||||||
var notename = getNotenameFromSocket(socket);
|
var notename = getNotenameFromSocket(socket);
|
||||||
if (!notename) {
|
if (!notename) {
|
||||||
|
clearSocketQueue(connectionSocketQueue, socket);
|
||||||
isConnectionBusy = false;
|
isConnectionBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -303,12 +308,7 @@ function startConnection(socket) {
|
||||||
});
|
});
|
||||||
socket.disconnect(true);
|
socket.disconnect(true);
|
||||||
//clear err socket in queue
|
//clear err socket in queue
|
||||||
for (var i = 0; i < connectionSocketQueue.length; i++) {
|
clearSocketQueue(connectionSocketQueue, socket);
|
||||||
if (!connectionSocketQueue[i] || connectionSocketQueue[i].id == socket.id) {
|
|
||||||
connectionSocketQueue.splice(i, 1);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isConnectionBusy = false;
|
isConnectionBusy = false;
|
||||||
return logger.error(err);
|
return logger.error(err);
|
||||||
}
|
}
|
||||||
|
@ -320,6 +320,7 @@ function startConnection(socket) {
|
||||||
Note.findOrNewNote(notename, permission, function (err, note) {
|
Note.findOrNewNote(notename, permission, function (err, note) {
|
||||||
if (err) {
|
if (err) {
|
||||||
responseError(res, "404", "Not Found", "oops.");
|
responseError(res, "404", "Not Found", "oops.");
|
||||||
|
clearSocketQueue(connectionSocketQueue, socket);
|
||||||
isConnectionBusy = false;
|
isConnectionBusy = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -393,12 +394,7 @@ function disconnect(socket) {
|
||||||
emitOnlineUsers(socket);
|
emitOnlineUsers(socket);
|
||||||
|
|
||||||
//clear finished socket in queue
|
//clear finished socket in queue
|
||||||
for (var i = 0; i < disconnectSocketQueue.length; i++) {
|
clearSocketQueue(disconnectSocketQueue, socket);
|
||||||
if (!disconnectSocketQueue[i] || disconnectSocketQueue[i].id == socket.id) {
|
|
||||||
disconnectSocketQueue.splice(i, 1);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//seek for next socket
|
//seek for next socket
|
||||||
isDisconnectBusy = false;
|
isDisconnectBusy = false;
|
||||||
if (disconnectSocketQueue.length > 0)
|
if (disconnectSocketQueue.length > 0)
|
||||||
|
|
Loading…
Reference in a new issue