From d04c3e7c4a092f813a5285bd59a54e6b9874126b Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Mon, 7 Nov 2022 11:58:58 +0100 Subject: [PATCH] front: Listen to onNodeCrashed event for reconnection --- .../app/components/call/call.component.html | 1 + .../src/app/components/call/call.component.ts | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/openvidu-call-front/src/app/components/call/call.component.html b/openvidu-call-front/src/app/components/call/call.component.html index b4034ebb..7d94bd2a 100644 --- a/openvidu-call-front/src/app/components/call/call.component.html +++ b/openvidu-call-front/src/app/components/call/call.component.html @@ -9,6 +9,7 @@ (onToolbarStopRecordingClicked)="onStopRecordingClicked()" (onActivitiesPanelStopRecordingClicked)="onStopRecordingClicked()" (onActivitiesPanelDeleteRecordingClicked)="onDeleteRecordingClicked($event)" + (onNodeCrashed)="onNodeCrashed()" [activitiesPanelRecordingActivity]="recordingEnabled" [toolbarRecordingButton]="recordingEnabled" > diff --git a/openvidu-call-front/src/app/components/call/call.component.ts b/openvidu-call-front/src/app/components/call/call.component.ts index c520241b..a4a40a63 100644 --- a/openvidu-call-front/src/app/components/call/call.component.ts +++ b/openvidu-call-front/src/app/components/call/call.component.ts @@ -20,6 +20,7 @@ export class CallComponent implements OnInit { recordingError: any; serverError: string = ''; loading: boolean = true; + private isDebugSession: boolean = false; constructor( private restService: RestService, @@ -33,23 +34,13 @@ export class CallComponent implements OnInit { this.sessionId = params.roomName; }); - let nickname: string = ''; // Just for debugging purposes const regex = /^UNSAFE_DEBUG_USE_CUSTOM_IDS_/gm; const match = regex.exec(this.sessionId); - if (match && match.length > 0) { - console.warn('DEBUGGING SESSION'); - nickname = this.participantService.getLocalParticipant().getNickname(); - } + this.isDebugSession = match && match.length > 0; try { - const response = await this.restService.getTokens(this.sessionId, nickname); - this.recordingEnabled = response.recordingEnabled; - this.recordingList = response.recordings; - this.tokens = { - webcam: response.cameraToken, - screen: response.screenToken - }; + await this.initializeTokens(); } catch (error) { console.error(error); this.serverError = error?.error?.message || error?.statusText; @@ -57,6 +48,11 @@ export class CallComponent implements OnInit { this.loading = false; } } + + async onNodeCrashed() { + // Request the tokens again for reconnect to the session + await this.initializeTokens(); + } onLeaveButtonClicked() { this.isSessionAlive = false; this.closeClicked = true; @@ -85,4 +81,19 @@ export class CallComponent implements OnInit { this.recordingError = error; } } + + private async initializeTokens(): Promise { + let nickname: string = ''; + if (this.isDebugSession) { + console.warn('DEBUGGING SESSION'); + nickname = this.participantService.getLocalParticipant().getNickname(); + } + const response = await this.restService.getTokens(this.sessionId, nickname); + this.recordingEnabled = response.recordingEnabled; + this.recordingList = response.recordings; + this.tokens = { + webcam: response.cameraToken, + screen: response.screenToken + }; + } }