From ce469bff96d5ae2d784b68b46d3ecaba3c1603a5 Mon Sep 17 00:00:00 2001 From: csantosm <4a.santos@gmail.com> Date: Wed, 22 Jun 2022 13:57:42 +0200 Subject: [PATCH] openvidu-call: Updated recording feature --- .../src/controllers/RecordingController.ts | 6 +++--- .../src/controllers/SessionController.ts | 2 +- .../src/services/OpenViduService.ts | 1 + openvidu-call/openvidu-call-front/package.json | 2 +- .../admin-dashboard/admin-dashboard.component.html | 1 - .../admin-dashboard/admin-dashboard.component.ts | 13 ++++--------- .../src/app/components/call/call.component.html | 3 ++- .../src/app/components/call/call.component.ts | 12 ++---------- .../src/app/services/rest.service.ts | 2 +- 9 files changed, 15 insertions(+), 27 deletions(-) diff --git a/openvidu-call/openvidu-call-back/src/controllers/RecordingController.ts b/openvidu-call/openvidu-call-back/src/controllers/RecordingController.ts index 0edc505e..b2294673 100644 --- a/openvidu-call/openvidu-call-back/src/controllers/RecordingController.ts +++ b/openvidu-call/openvidu-call-back/src/controllers/RecordingController.ts @@ -24,7 +24,6 @@ app.get('/', async (req: Request, res: Response) => { const date = openviduService.getDateFromCookie(req.cookies); recordings = await openviduService.listRecordingsBySessionIdAndDate(sessionId, date); } - console.log('a', recordings) res.status(200).send(JSON.stringify(recordings)); } else { const message = IS_RECORDING_ENABLED ? 'Permissions denied to drive recording' : 'Recording is disabled'; @@ -107,13 +106,13 @@ app.delete('/delete/:recordingId', async (req: Request, res: Response) => { const isAdminDashboard = openviduService.adminTokens.includes(req['session'].token); let recordings = []; if ((!!sessionId && openviduService.isValidToken(sessionId, req.cookies)) || isAdminDashboard) { - console.log('DELETE RECORDING'); const recordingId: string = req.params.recordingId; if (!recordingId) { return res.status(400).send('Missing recording id parameter.'); } + console.log(`Deleting recording ${recordingId}`); await openviduService.deleteRecording(recordingId); - if (isAdminDashboard) { + if (isAdminDashboard && !!req['session']) { recordings = await openviduService.listAllRecordings(true); } else { const date = openviduService.getDateFromCookie(req.cookies); @@ -152,6 +151,7 @@ export const proxyGETRecording = createProxyMiddleware({ if (!recordingId) { return res.status(400).send(JSON.stringify({ message: 'Missing recording id parameter.' })); } else { + proxyReq.setHeader('Connection', 'keep-alive'); proxyReq.setHeader('Authorization', openviduService.getBasicAuth()); proxyReq.setHeader('Range', 'bytes=0-'); } diff --git a/openvidu-call/openvidu-call-back/src/controllers/SessionController.ts b/openvidu-call/openvidu-call-back/src/controllers/SessionController.ts index 9dcc1887..65ccaea2 100644 --- a/openvidu-call/openvidu-call-back/src/controllers/SessionController.ts +++ b/openvidu-call/openvidu-call-back/src/controllers/SessionController.ts @@ -24,7 +24,7 @@ app.post('/', async (req: Request, res: Response) => { const hasValidToken = openviduService.isValidToken(sessionId, req.cookies); const isSessionCreator = hasValidToken || sessionCreated.activeConnections.length === 0; const role: OpenViduRole = isSessionCreator && IS_RECORDING_ENABLED ? OpenViduRole.MODERATOR : OpenViduRole.PUBLISHER; - const response = {cameraToken : '', screenToken: '', recording: IS_RECORDING_ENABLED}; + const response = {cameraToken : '', screenToken: '', recordingEnabled: IS_RECORDING_ENABLED}; const cameraConnection = await openviduService.createConnection(sessionCreated, nickname, role); const screenConnection = await openviduService.createConnection(sessionCreated, nickname, role); response.cameraToken = cameraConnection.token; diff --git a/openvidu-call/openvidu-call-back/src/services/OpenViduService.ts b/openvidu-call/openvidu-call-back/src/services/OpenViduService.ts index 4561fd59..6488e152 100644 --- a/openvidu-call/openvidu-call-back/src/services/OpenViduService.ts +++ b/openvidu-call/openvidu-call-back/src/services/OpenViduService.ts @@ -41,6 +41,7 @@ export class OpenViduService { const cookieTokenUrl = new URL(cookies[this.RECORDING_TOKEN_NAME]); return cookieTokenUrl?.searchParams.get('sessionId'); } catch (error) { + console.log('Recording cookie not found'); console.error(error); return ''; } diff --git a/openvidu-call/openvidu-call-front/package.json b/openvidu-call/openvidu-call-front/package.json index 25765a37..905f9e57 100644 --- a/openvidu-call/openvidu-call-front/package.json +++ b/openvidu-call/openvidu-call-front/package.json @@ -43,7 +43,7 @@ "copy:backend-prod": "mkdir -p ../openvidu-call-back/dist/public && cp -a dist/openvidu-call/. ../openvidu-call-back/dist/public/", "e2e": "ng e2e", "lint": "ng lint", - "start": "ng serve --configuration development", + "start": "ng serve --ssl --configuration development", "start:https": "ng serve --host 192.168.1.161 --ssl --ssl-key cert.key --ssl-cert cert.crt", "test": "ng test openvidu-call --watch=false --code-coverage" }, diff --git a/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html b/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html index 64081243..d0bc672f 100644 --- a/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html +++ b/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html @@ -5,7 +5,6 @@ [recordingsList]="recordings" (onLogoutClicked)="onLogoutClicked()" (onRefreshRecordingsClicked)="onRefreshRecordingsClicked()" - (onPlayRecordingClicked)="onPlayRecordingClicked($event)" (onDownloadRecordingClicked)="onDownloadRecordingClicked($event)" (onDeleteRecordingClicked)="onDeleteRecordingClicked($event)" > diff --git a/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts b/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts index 7a7152fc..14d2d081 100644 --- a/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts +++ b/openvidu-call/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts @@ -15,6 +15,10 @@ export class AdminDashboardComponent implements OnInit { ngOnInit(): void {} + ngOnDestroy() { + this.onLogoutClicked(); + } + async onLoginClicked(pass: string) { try { const resp: any = await this.restService.login(pass); @@ -54,13 +58,4 @@ export class AdminDashboardComponent implements OnInit { console.error(error); } } - - async onPlayRecordingClicked(recordingId: string) { - try { - const file: Blob = await this.restService.downloadRecording(recordingId); - this.recordingService.playRecording(file); - } catch (error) { - console.error(error); - } - } } diff --git a/openvidu-call/openvidu-call-front/src/app/components/call/call.component.html b/openvidu-call/openvidu-call-front/src/app/components/call/call.component.html index fbe2e2a3..e0efddbb 100644 --- a/openvidu-call/openvidu-call-front/src/app/components/call/call.component.html +++ b/openvidu-call/openvidu-call-front/src/app/components/call/call.component.html @@ -9,6 +9,7 @@ (onActivitiesPanelStopRecordingClicked)="onStopRecordingClicked()" (onActivitiesPanelDownloadRecordingClicked)="onDownloadRecordingClicked($event)" (onActivitiesPanelDeleteRecordingClicked)="onDeleteRecordingClicked($event)" - (onActivitiesPanelPlayRecordingClicked)="onPlayRecordingClicked($event)" + [activitiesPanelRecordingActivity]="recordingEnabled" + [toolbarRecordingButton]="recordingEnabled" > diff --git a/openvidu-call/openvidu-call-front/src/app/components/call/call.component.ts b/openvidu-call/openvidu-call-front/src/app/components/call/call.component.ts index 3976d03c..6274671c 100644 --- a/openvidu-call/openvidu-call-front/src/app/components/call/call.component.ts +++ b/openvidu-call/openvidu-call-front/src/app/components/call/call.component.ts @@ -15,8 +15,8 @@ export class CallComponent implements OnInit { joinSessionClicked: boolean = false; closeClicked: boolean = false; isSessionAlive: boolean = false; + recordingEnabled: boolean = true; recordingList: RecordingInfo[] = []; - recordingError: any; constructor( @@ -42,6 +42,7 @@ export class CallComponent implements OnInit { } const response = await this.restService.getTokens(this.sessionId, nickname); + this.recordingEnabled = response.recordingEnabled; this.recordingList = response.recordings; this.tokens = { webcam: response.cameraToken, @@ -84,13 +85,4 @@ export class CallComponent implements OnInit { this.recordingError = error; } } - - async onPlayRecordingClicked(recordingId: string) { - try { - const recording: Blob = await this.restService.downloadRecording(recordingId); - this.recordingService.playRecording(recording); - } catch (error) { - this.recordingError = error; - } - } } diff --git a/openvidu-call/openvidu-call-front/src/app/services/rest.service.ts b/openvidu-call/openvidu-call-front/src/app/services/rest.service.ts index af3dd456..b865564e 100644 --- a/openvidu-call/openvidu-call-front/src/app/services/rest.service.ts +++ b/openvidu-call/openvidu-call-front/src/app/services/rest.service.ts @@ -15,7 +15,7 @@ export class RestService { async getTokens( sessionId: string, nickname?: string - ): Promise<{ cameraToken: string; screenToken: string; recordings?: RecordingInfo[] }> { + ): Promise<{ cameraToken: string; screenToken: string, recordingEnabled: boolean, recordings?: RecordingInfo[] }> { return this.postRequest('sessions', { sessionId, nickname }); } login(password: string): Promise {