Fix timing issue crashing on undefined when setting openChannel

This commit is contained in:
Pavel Djundik 2018-10-21 11:05:05 +03:00
parent 5b40a6fb58
commit d5aa00b753
2 changed files with 8 additions and 3 deletions

View file

@ -404,9 +404,14 @@ Client.prototype.more = function(data) {
};
Client.prototype.open = function(socketId, target) {
// Due to how socket.io works internally, normal events may arrive later than
// the disconnect event, and because we can't control this timing precisely,
// process this event normally even if there is no attached client anymore.
const attachedClient = this.attachedClients[socketId] || {};
// Opening a window like settings
if (target === null) {
this.attachedClients[socketId].openChannel = -1;
attachedClient.openChannel = -1;
return;
}
@ -420,7 +425,7 @@ Client.prototype.open = function(socketId, target) {
target.chan.unread = 0;
target.chan.highlight = 0;
this.attachedClients[socketId].openChannel = target.chan.id;
attachedClient.openChannel = target.chan.id;
this.lastActiveChannel = target.chan.id;
this.emit("open", target.chan.id);

View file

@ -295,7 +295,7 @@ function initializeClient(socket, client, token, lastMessage) {
}
socket.on("disconnect", function() {
client.clientDetach(socket.id);
process.nextTick(() => client.clientDetach(socket.id));
});
socket.on("input", (data) => {