import { Injectable } from '@angular/core' ; import { GlobalsService } from './globals.service' ; import { SessionManagerService } from './session-manager.service' ; import { SharedService } from './shared.service' ; import { Socket } from 'ngx-socket-io' ; import { NotifyService } from './notify.service' ; @ Injectable ( { providedIn : 'root' } ) export class RoomService { constructor ( public globals , private session , private shared , private notify , private socket ) { } join ( ) { this . session . getSession ( ) . then ( res => { if ( res === 'OK' ) { this . socket . emit ( 'join_session' , { session : this . globals . sessionValue , name : localStorage . getItem ( 'clientName' ) } , ( { client , status } ) => { switch ( status ) { case 'USERNAME_EXIST' : console . log ( 'you joined with used name' ) ; break ; case 'USERNAME_EMPTY' : this . shared . updateClientName ( client . name ) ; break ; case 'USERNAME_OK' : this . shared . updateClientName ( client . name ) ; break ; default : break ; } } ) ; this . shared . findPlaylistItem ( ) ; } } ) ; } leave ( ) { this . socket . emit ( 'leave_session' , this . globals . sessionValue ) ; this . shared . findPlaylistItem ( ) ; } }