import SocketService from './SocketService' ; import { SOCKET_EVENTS } from '../constants/SocketEvents' ; import { getSlugRoute } from '../routes' ; class RoomService { returns createRoom = ( ) : Promise < string > => { return new Promise ( ( resolve , reject ) => { fetch ( getSlugRoute ) . then ( ( response ) => { if ( ! response . ok ) { throw response ; } response . json ( ) . then ( ( json ) => { resolve ( json && json . data && json . data . slug ) ; } ) . catch ( ( error ) => { throw error ; } ) ; } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } ) ; } ; param roomSlug joinRoom = ( roomSlug ) : void => { SocketService . emitEvent ( SOCKET_EVENTS . JOIN_ROOM , roomSlug ) ; } ; returns getCurrentRoomSlug = ( ) : string | null => { const currentURL = window . location . href ; return currentURL . split ( 'room/' ) ?. [ 1 ] ; } ; } export default new RoomService ( ) ;