@@ -184,6 +184,7 @@ export class Launcher extends Observable implements DefaultLauncher {
184
184
this . room ?. presence . off ( Socket . PresenceEvents . JOINED_ROOM ) ;
185
185
this . room ?. presence . off ( Socket . PresenceEvents . LEAVE ) ;
186
186
this . room ?. presence . off ( Socket . PresenceEvents . UPDATE ) ;
187
+ this . ioc . stateSubject . unsubscribe ( ) ;
187
188
this . ioc ?. destroy ( ) ;
188
189
189
190
this . isDestroyed = true ;
@@ -294,13 +295,8 @@ export class Launcher extends Observable implements DefaultLauncher {
294
295
private startIOC = ( ) : void => {
295
296
this . logger . log ( 'launcher service @ startIOC' ) ;
296
297
const { participants } = useStore ( StoreType . GLOBAL ) ;
297
- // retrieve the current participants in the room
298
298
299
- this . ioc . stateSubject . subscribe ( ( state ) => {
300
- if ( state === IOCState . AUTH_ERROR ) {
301
- this . onAuthentication ( false ) ;
302
- }
303
- } ) ;
299
+ this . ioc . stateSubject . subscribe ( this . onConnectionStateChange ) ;
304
300
this . room . presence . get ( ( presences ) => {
305
301
const participantsMap : Record < string , Participant > = { } ;
306
302
@@ -327,9 +323,24 @@ export class Launcher extends Observable implements DefaultLauncher {
327
323
) ;
328
324
this . room . presence . on < Participant > ( Socket . PresenceEvents . LEAVE , this . onParticipantLeaveIOC ) ;
329
325
this . room . presence . on < Participant > ( Socket . PresenceEvents . UPDATE , this . onParticipantUpdatedIOC ) ;
326
+ } ;
330
327
331
- const { hasJoinedRoom } = useStore ( StoreType . GLOBAL ) ;
332
- hasJoinedRoom . publish ( true ) ;
328
+ /**
329
+ * @function onConnectionStateChange
330
+ * @description on connection state change
331
+ * @param state - connection state
332
+ * @returns {void }
333
+ */
334
+ private onConnectionStateChange = ( state : IOCState ) : void => {
335
+ if ( state === IOCState . AUTH_ERROR ) {
336
+ this . onAuthentication ( false ) ;
337
+ return ;
338
+ }
339
+
340
+ if ( state === IOCState . SAME_ACCOUNT_ERROR ) {
341
+ this . onSameAccount ( ) ;
342
+ return ;
343
+ }
333
344
} ;
334
345
335
346
/**
@@ -347,6 +358,9 @@ export class Launcher extends Observable implements DefaultLauncher {
347
358
348
359
this . logger . log ( 'launcher service @ onParticipantJoined - local participant joined' ) ;
349
360
361
+ const { hasJoinedRoom } = useStore ( StoreType . GLOBAL ) ;
362
+ hasJoinedRoom . publish ( true ) ;
363
+
350
364
this . attachComponentsAfterJoin ( ) ;
351
365
this . publish ( ParticipantEvent . LOCAL_JOINED , this . participant ) ;
352
366
this . publish ( ParticipantEvent . JOINED , this . participant ) ;
0 commit comments