import { ServerWebSocket } from "bun";
import { WebSocketData } from "../types";

type Param = {
    ws: ServerWebSocket<WebSocketData>;
};

export default async function socketOpen({ ws }: Param) {
    const user = ws.data.user;
    console.log(`Web Socket Opened by ${user.first_name}`);

    const existing_connected_user_data =
        global.WEBSOCKET_CONNECTED_USERS_DATA.find((u) => u.user.id == user.id);

    if (!existing_connected_user_data) {
        global.WEBSOCKET_CONNECTED_USERS_DATA.push({
            user,
            child_processes: [],
            ports: [],
        });
    }
}
