import { io , Socket } from 'socket.io-client' ; import { SOCKET_URL } from '../config/app' ; let socket = null ; const getSocket = ( ) => { if ( ! socket ) { socket = io ( SOCKET_URL , { transports : [ 'websocket' ] } ) ; } return socket ; } ; export const subscribe = ( eventKey , callback ) => { getSocket ( ) . on ( eventKey , callback ) ; } ; export const emit = ( eventKey , payload ) => { getSocket ( ) . emit ( eventKey , payload ) ; } ;