Fix issue with websockets being closed
This commit is contained in:
21
main.js
21
main.js
@@ -1170,8 +1170,6 @@ class HTTPServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WSServer {
|
class WSServer {
|
||||||
// TODO: Implement center adding and removing...
|
|
||||||
// TODO: This will probably have to be reworked a little to accommodate centers.
|
|
||||||
clients = {};
|
clients = {};
|
||||||
unknownClients = [];
|
unknownClients = [];
|
||||||
|
|
||||||
@@ -1241,17 +1239,22 @@ class WSServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeClient(ws) {
|
removeClient(ws) {
|
||||||
// TODO: Fix this
|
this.clients.client = this.removeFromArray(this.clients.client, ws);
|
||||||
for (let sessionId in this.clients) {
|
this.clients.center = this.removeFromArray(this.clients.center, ws);
|
||||||
let index = this.clients[sessionId].indexOf(ws);
|
}
|
||||||
|
|
||||||
|
removeFromArray(array, element) {
|
||||||
|
for (let sessionId in array) {
|
||||||
|
let index = array[sessionId].indexOf(element);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
delete this.clients[sessionId][index];
|
delete array[sessionId][index];
|
||||||
}
|
}
|
||||||
this.clients[sessionId] = this.clients[sessionId].filter(Boolean);
|
array[sessionId] = array[sessionId].filter(Boolean);
|
||||||
if (this.clients[sessionId].length === 0) {
|
if (array[sessionId].length === 0) {
|
||||||
delete this.clients[sessionId];
|
delete array[sessionId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
onClientSessionStatusChange(sessionId, newStatus) {
|
onClientSessionStatusChange(sessionId, newStatus) {
|
||||||
|
|||||||
Reference in New Issue
Block a user