From d4a89680d1154b7fc85681aec70a49f84d3fffa8 Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Wed, 3 May 2023 12:52:10 +0200 Subject: [PATCH] Fixed bugs with recording filtered and session creator checks --- .../io/openvidu/call/java/controllers/SessionController.java | 3 ++- .../java/io/openvidu/call/java/services/OpenViduService.java | 2 +- openvidu-call-back/src/controllers/SessionController.ts | 3 ++- openvidu-call-back/src/services/OpenViduService.ts | 5 ++++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openvidu-call-back-java/src/main/java/io/openvidu/call/java/controllers/SessionController.java b/openvidu-call-back-java/src/main/java/io/openvidu/call/java/controllers/SessionController.java index 7cbeb814..8ef7877a 100644 --- a/openvidu-call-back-java/src/main/java/io/openvidu/call/java/controllers/SessionController.java +++ b/openvidu-call-back-java/src/main/java/io/openvidu/call/java/controllers/SessionController.java @@ -71,7 +71,8 @@ public ResponseEntity> createConnection( boolean hasParticipantValidToken = this.openviduService.isParticipantSessionValid(sessionId, participantCookie); boolean hasValidToken = hasModeratorValidToken || hasParticipantValidToken; - boolean isSessionCreator = hasValidToken || sessionCreated.getActiveConnections().size() == 0; + boolean iAmTheFirstConnection = sessionCreated.getActiveConnections().size() == 0; + boolean isSessionCreator = hasModeratorValidToken || iAmTheFirstConnection; OpenViduRole role = isSessionCreator ? OpenViduRole.MODERATOR : OpenViduRole.PUBLISHER; diff --git a/openvidu-call-back-java/src/main/java/io/openvidu/call/java/services/OpenViduService.java b/openvidu-call-back-java/src/main/java/io/openvidu/call/java/services/OpenViduService.java index ada13aa5..b73e973b 100644 --- a/openvidu-call-back-java/src/main/java/io/openvidu/call/java/services/OpenViduService.java +++ b/openvidu-call-back-java/src/main/java/io/openvidu/call/java/services/OpenViduService.java @@ -220,7 +220,7 @@ public List listRecordingsBySessionIdAndDate(String sessionId, long d List recordings = this.listAllRecordings(); List recordingsAux = new ArrayList(); for (Recording recording : recordings) { - if (recording.getSessionId().equals(sessionId) && date <= recording.getCreatedAt()) { + if (recording.getSessionId().equals(sessionId) && recording.getCreatedAt() + recording.getDuration() * 1000 >= date) { recordingsAux.add(recording); } } diff --git a/openvidu-call-back/src/controllers/SessionController.ts b/openvidu-call-back/src/controllers/SessionController.ts index fb844a24..aa71d0b0 100644 --- a/openvidu-call-back/src/controllers/SessionController.ts +++ b/openvidu-call-back/src/controllers/SessionController.ts @@ -27,7 +27,8 @@ app.post('/', async (req: Request, res: Response) => { const hasModeratorValidToken = openviduService.isModeratorSessionValid(sessionId, req.cookies); const hasParticipantValidToken = openviduService.isParticipantSessionValid(sessionId, req.cookies); const hasValidToken = hasModeratorValidToken || hasParticipantValidToken; - const isSessionCreator = hasValidToken || sessionCreated.activeConnections.length === 0; + const iAmFirstConnection = sessionCreated.activeConnections.length === 0; + const isSessionCreator = hasModeratorValidToken || iAmFirstConnection; const role: OpenViduRole = isSessionCreator ? OpenViduRole.MODERATOR : OpenViduRole.PUBLISHER; const response = { diff --git a/openvidu-call-back/src/services/OpenViduService.ts b/openvidu-call-back/src/services/OpenViduService.ts index 225aa20f..08c271d1 100644 --- a/openvidu-call-back/src/services/OpenViduService.ts +++ b/openvidu-call-back/src/services/OpenViduService.ts @@ -144,7 +144,10 @@ export class OpenViduService { public async listRecordingsBySessionIdAndDate(sessionId: string, date: number) { const recordingList: Recording[] = await this.listAllRecordings(); - return recordingList.filter((recording) => recording.sessionId === sessionId && date <= recording.createdAt); + return recordingList.filter((recording) => { + const recordingDateEnd = recording.createdAt + recording.duration * 1000; + return recording.sessionId === sessionId && recordingDateEnd >= date; + }); } public async startBroadcasting(sessionId: string, url: string): Promise {