From 21d46d3caa60b11af3879dfe996d31d60b1a0aa9 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Sat, 21 Jun 2025 04:08:12 +0200 Subject: [PATCH] add typings for outgoing ws messages --- src/services/webService.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/services/webService.ts b/src/services/webService.ts index 9c38dc15..2f5f3e3f 100644 --- a/src/services/webService.ts +++ b/src/services/webService.ts @@ -108,6 +108,23 @@ interface IWsMsgFromClient { }; } +interface IWsMsgToClient { + ports?: { + http: number | undefined; + https: number | undefined; + }; + config_reloaded?: boolean; + auth_succ?: { + id: string; + DisplayName: string; + Nonce: number; + }; + auth_fail?: { + isRegister: boolean; + }; + logged_out?: boolean; +} + const wsOnConnect = (ws: ws, _req: http.IncomingMessage): void => { // eslint-disable-next-line @typescript-eslint/no-misused-promises ws.on("message", async msg => { @@ -144,7 +161,7 @@ const wsOnConnect = (ws: ws, _req: http.IncomingMessage): void => { DisplayName: account.DisplayName, Nonce: account.Nonce } - }) + } satisfies IWsMsgToClient) ); } else { ws.send( @@ -152,14 +169,14 @@ const wsOnConnect = (ws: ws, _req: http.IncomingMessage): void => { auth_fail: { isRegister: data.auth.isRegister } - }) + } satisfies IWsMsgToClient) ); } } }); }; -export const sendWsBroadcast = (data: T): void => { +export const sendWsBroadcast = (data: IWsMsgToClient): void => { const msg = JSON.stringify(data); if (wsServer) { for (const client of wsServer.clients) { @@ -173,7 +190,7 @@ export const sendWsBroadcast = (data: T): void => { } }; -export const sendWsBroadcastTo = (accountId: string, data: T): void => { +export const sendWsBroadcastTo = (accountId: string, data: IWsMsgToClient): void => { const msg = JSON.stringify(data); if (wsServer) { for (const client of wsServer.clients) {