import { io , Socket } from "socket.io-client" ; import { GameServerToClient } from "@creature-chess/networking" ; export const getSocket = ( idToken ) => { const socket = io ( { path : "/game/socket.io" } , { transports : [ "websocket" , "polling" ] } ) ; return new Promise < Socket > ( ( resolve , reject ) => { socket . on ( "connect" , ( ) => { socket . emit ( "authenticate" , { idToken } ) ; } ) ; const onAuthenticated = ( { error } ) => { if ( ! error ) { socket . off ( "authenticate_response" , onAuthenticated ) ; resolve ( socket ) ; return ; } socket . disconnect ( ) ; reject ( error ) ; } ; socket . on ( "authenticate_response" , onAuthenticated ) ; } ) ; } ;