mirror of
https://github.com/jetkvm/cloud-api.git
synced 2025-09-16 08:38:15 +00:00
chore: update .gitignore and enhance WebSocket connection handling
* Add .env.development to .gitignore * Improve handling of existing WebSocket connections by waiting for closure before terminating
This commit is contained in:
parent
efce3ebe7b
commit
507ffc06f9
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
.idea
|
||||
.env
|
||||
.env
|
||||
.env.development
|
||||
|
||||
@ -85,10 +85,20 @@ async function handleDeviceSocketRequest(
|
||||
console.log(
|
||||
`[Device] Device ${device.id} already connected. Terminating existing connection.`,
|
||||
);
|
||||
activeConnections.get(device.id)?.[0]?.terminate();
|
||||
activeConnections.delete(device.id);
|
||||
// We don't return here, we just delete the existing connection and let it continue and create a new one.
|
||||
// Why multiple connections are needed, i don't know, but let's cover it.
|
||||
|
||||
const [existingDeviceWs] = activeConnections.get(device.id)!;
|
||||
await new Promise(resolve => {
|
||||
console.log("[Device] Waiting for existing connection to close...");
|
||||
existingDeviceWs.on("close", () => {
|
||||
activeConnections.delete(device.id);
|
||||
console.log("[Device] Existing connection closed.");
|
||||
|
||||
// Now we continue with the new connection
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
existingDeviceWs.terminate();
|
||||
});
|
||||
}
|
||||
|
||||
// Complete the WebSocket upgrade
|
||||
|
||||
Loading…
Reference in New Issue
Block a user