Skip to content

Commit

Permalink
front: Listen to onNodeCrashed event for reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Nov 7, 2022
1 parent 2813a5c commit d04c3e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(onToolbarStopRecordingClicked)="onStopRecordingClicked()"
(onActivitiesPanelStopRecordingClicked)="onStopRecordingClicked()"
(onActivitiesPanelDeleteRecordingClicked)="onDeleteRecordingClicked($event)"
(onNodeCrashed)="onNodeCrashed()"
[activitiesPanelRecordingActivity]="recordingEnabled"
[toolbarRecordingButton]="recordingEnabled"
>
Expand Down
35 changes: 23 additions & 12 deletions openvidu-call-front/src/app/components/call/call.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CallComponent implements OnInit {
recordingError: any;
serverError: string = '';
loading: boolean = true;
private isDebugSession: boolean = false;

constructor(
private restService: RestService,
Expand All @@ -33,30 +34,25 @@ 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;
} finally {
this.loading = false;
}
}

async onNodeCrashed() {
// Request the tokens again for reconnect to the session
await this.initializeTokens();
}
onLeaveButtonClicked() {
this.isSessionAlive = false;
this.closeClicked = true;
Expand Down Expand Up @@ -85,4 +81,19 @@ export class CallComponent implements OnInit {
this.recordingError = error;
}
}

private async initializeTokens(): Promise<void> {
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
};
}
}

0 comments on commit d04c3e7

Please sign in to comment.