mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
refactor: improve shutdown cleanup
This commit is contained in:
committed by
Carlos Valente
parent
871a6b46c8
commit
4408bdb0d3
@@ -1,3 +1,3 @@
|
||||
export interface IAdapter {
|
||||
shutdown: () => void;
|
||||
shutdown: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -72,10 +72,17 @@ class OscServer implements IAdapter {
|
||||
});
|
||||
this.udpSocket.bind(port);
|
||||
}
|
||||
shutdown() {
|
||||
shutdown(): Promise<void> {
|
||||
logger.info(LogOrigin.Rx, 'OSC: Closing server');
|
||||
this.udpSocket?.close();
|
||||
const socket = this.udpSocket;
|
||||
this.udpSocket = null;
|
||||
if (!socket) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
socket.close(() => resolve());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,8 +235,25 @@ class SocketServer implements IAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.wss?.close();
|
||||
shutdown(): Promise<void> {
|
||||
const wss = this.wss;
|
||||
if (!wss) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// Notify clients first so they can reconnect gracefully
|
||||
for (const client of wss.clients) {
|
||||
if (client.readyState === WebSocket.OPEN || client.readyState === WebSocket.CONNECTING) {
|
||||
client.close(1001, 'Server shutting down');
|
||||
}
|
||||
}
|
||||
|
||||
wss.close(() => {
|
||||
this.wss = null;
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user