dsql-admin/dsql-app/docker/web-socket/app/functions/socket-close.ts

20 lines
501 B
TypeScript
Raw Normal View History

2025-02-16 16:12:40 +00:00
import { type ServerWebSocket } from "bun";
import type { WebSocketData } from "@WS/.";
type Param = {
ws: ServerWebSocket<WebSocketData>;
};
export default async function socketClose({ ws }: Param) {
const user = ws.data.user;
console.log(`Web Closed by ${user.first_name}`);
const userSessionIndex = global.ACTIVE_USERS.findIndex(
(session) => session.id == user.id
);
if (userSessionIndex >= 0) {
global.ACTIVE_USERS.splice(userSessionIndex, 1);
}
}