import { MutableRefObject } from 'react' ; import { sharedWebSockets , ReadyState } from './globals' ; import { ReadyStateState } from './types' ; export const createSocket = ( webSocketRef , url , setReadyState ) => { if ( sharedWebSockets [ url ] === undefined ) { setReadyState ( readyState => { readyState [ url ] = ReadyState . CONNECTING ; } ) ; sharedWebSockets [ url ] = new WebSocket ( url ) ; } webSocketRef . current = sharedWebSockets [ url ] || null ; } ;