add typings for outgoing ws messages
All checks were successful
Build / build (pull_request) Successful in 1m19s

This commit is contained in:
Sainan 2025-06-21 04:08:12 +02:00
parent e151f97380
commit 21d46d3caa

View File

@ -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 = <T>(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 = <T>(data: T): void => {
}
};
export const sendWsBroadcastTo = <T>(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) {