From 32f63f50a38414b36f84907b604b3fb4ceeb33b2 Mon Sep 17 00:00:00 2001 From: cruizba Date: Thu, 10 Sep 2020 11:07:43 +0200 Subject: [PATCH] Change POST /api/sessions to return all session information, fixed default parameters in session object on clients and fixed recorder --- openvidu-browser/src/OpenVidu/Connection.ts | 2 +- .../java/io/openvidu/java/client/Session.java | 23 ++++++++++++-- openvidu-node-client/src/OpenVidu.ts | 4 +-- openvidu-node-client/src/Session.ts | 31 ++++++++++++------- .../server/rest/SessionRestController.java | 5 ++- .../test/e2e/OpenViduTestAppE2eTest.java | 11 +++---- 6 files changed, 49 insertions(+), 27 deletions(-) diff --git a/openvidu-browser/src/OpenVidu/Connection.ts b/openvidu-browser/src/OpenVidu/Connection.ts index 2002550b..8dbf38db 100644 --- a/openvidu-browser/src/OpenVidu/Connection.ts +++ b/openvidu-browser/src/OpenVidu/Connection.ts @@ -142,7 +142,7 @@ export class Connection { }; // TODO: CLEAN 2.15.0 LEGACY CODE // THIS LINE: - const stream = this.session.openvidu.openviduServerVersion.startsWith('2.16') ? new Stream(this.session, streamOptions) : new StreamLEGACY(this.session, streamOptions); + const stream = (this.session.openvidu.recorder || this.session.openvidu.openviduServerVersion.startsWith('2.16')) ? new Stream(this.session, streamOptions) : new StreamLEGACY(this.session, streamOptions); // SHOULD GET BACK TO: // const stream = new Stream(this.session, streamOptions); diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java index a5d0574f..a7fc8d56 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java @@ -54,14 +54,14 @@ public class Session { protected Session(OpenVidu openVidu) throws OpenViduJavaClientException, OpenViduHttpException { this.openVidu = openVidu; this.properties = new SessionProperties.Builder().build(); - this.getSessionIdHttp(); + this.getSessionHttp(); } protected Session(OpenVidu openVidu, SessionProperties properties) throws OpenViduJavaClientException, OpenViduHttpException { this.openVidu = openVidu; this.properties = properties; - this.getSessionIdHttp(); + this.getSessionHttp(); } protected Session(OpenVidu openVidu, JsonObject json) { @@ -444,7 +444,7 @@ public class Session { return (this.sessionId != null && !this.sessionId.isEmpty()); } - private void getSessionIdHttp() throws OpenViduJavaClientException, OpenViduHttpException { + private void getSessionHttp() throws OpenViduJavaClientException, OpenViduHttpException { if (this.hasSessionId()) { return; } @@ -458,6 +458,9 @@ public class Session { json.addProperty("defaultRecordingLayout", properties.defaultRecordingLayout().name()); json.addProperty("defaultCustomLayout", properties.defaultCustomLayout()); json.addProperty("customSessionId", properties.customSessionId()); + + // forcedVideoCodec codec and allowTranscoding could be null because + // both default values are loaded by openvidu server if (properties.forcedVideoCodec() != null) { json.addProperty("forcedVideoCodec", properties.forcedVideoCodec().name()); } @@ -487,6 +490,20 @@ public class Session { JsonObject responseJson = httpResponseToJson(response); this.sessionId = responseJson.get("id").getAsString(); this.createdAt = responseJson.get("createdAt").getAsLong(); + VideoCodec forcedVideoCodec = VideoCodec.valueOf(responseJson.get("forcedVideoCodec").getAsString()); + Boolean allowTranscoding = responseJson.get("allowTranscoding").getAsBoolean(); + + SessionProperties responseProperties = new SessionProperties.Builder() + .mediaMode(properties.mediaMode()) + .recordingMode(properties.recordingMode()) + .defaultOutputMode(properties.defaultOutputMode()) + .defaultRecordingLayout(properties.defaultRecordingLayout()) + .defaultCustomLayout(properties.defaultCustomLayout()) + .forcedVideoCodec(forcedVideoCodec) + .allowTranscoding(allowTranscoding) + .build(); + + this.properties = responseProperties; log.info("Session '{}' created", this.sessionId); } else if (statusCode == org.apache.http.HttpStatus.SC_CONFLICT) { // 'customSessionId' already existed diff --git a/openvidu-node-client/src/OpenVidu.ts b/openvidu-node-client/src/OpenVidu.ts index f6d6a318..7b14ab71 100644 --- a/openvidu-node-client/src/OpenVidu.ts +++ b/openvidu-node-client/src/OpenVidu.ts @@ -99,8 +99,8 @@ export class OpenVidu { public createSession(properties?: SessionProperties): Promise { return new Promise((resolve, reject) => { const session = new Session(this, properties); - session.getSessionIdHttp() - .then(sessionId => { + session.getSessionHttp() + .then(response => { this.activeSessions.push(session); resolve(session); }) diff --git a/openvidu-node-client/src/Session.ts b/openvidu-node-client/src/Session.ts index 7435b5f4..3eb7c3de 100644 --- a/openvidu-node-client/src/Session.ts +++ b/openvidu-node-client/src/Session.ts @@ -391,23 +391,25 @@ export class Session { /** * @hidden */ - public getSessionIdHttp(): Promise { + public getSessionHttp(): Promise { return new Promise((resolve, reject) => { if (!!this.sessionId) { resolve(this.sessionId); } - const data = JSON.stringify({ - mediaMode: !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED, - recordingMode: !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL, - defaultOutputMode: !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED, - defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT, - defaultCustomLayout: !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : '', - customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : '', - forcedVideoCodec: !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : null, - allowTranscoding: !!this.properties.allowTranscoding ? this.properties.allowTranscoding : null - + const mediaMode = !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED; + const recordingMode = !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL; + const defaultOutputMode = !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED; + const defaultRecordingLayout = !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT; + const defaultCustomLayout = !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : ''; + const customSessionId = !!this.properties.customSessionId ? this.properties.customSessionId : ''; + const forcedVideoCodec = !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : null; + const allowTranscoding = !!this.properties.allowTranscoding ? this.properties.allowTranscoding : null; + + const data = JSON.stringify({ mediaMode, recordingMode, + defaultOutputMode, defaultRecordingLayout, defaultCustomLayout, + customSessionId, forcedVideoCodec, allowTranscoding }); axios.post( @@ -425,6 +427,13 @@ export class Session { // SUCCESS response from openvidu-server. Resolve token this.sessionId = res.data.id; this.createdAt = res.data.createdAt; + this.properties.mediaMode = mediaMode; + this.properties.recordingMode = recordingMode; + this.properties.defaultOutputMode = defaultOutputMode; + this.properties.defaultRecordingLayout = defaultRecordingLayout; + this.properties.customSessionId = customSessionId; + this.properties.forcedVideoCodec = res.data.forcedVideoCodec; + this.properties.allowTranscoding = res.data.allowTranscoding; resolve(this.sessionId); } else { // ERROR response from openvidu-server. Resolve HTTP status diff --git a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java index 76b1470b..606efcb1 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java @@ -190,10 +190,9 @@ public class SessionRestController { Session sessionNotActive = sessionManager.storeSessionNotActive(sessionId, sessionProperties); log.info("New session {} initialized {}", sessionId, this.sessionManager.getSessionsWithNotActive().stream() .map(Session::getSessionId).collect(Collectors.toList()).toString()); - JsonObject responseJson = new JsonObject(); + JsonObject responseJson = sessionNotActive.toJson(); + responseJson.remove("sessionId"); responseJson.addProperty("id", sessionNotActive.getSessionId()); - responseJson.addProperty("createdAt", sessionNotActive.getStartTime()); - return new ResponseEntity<>(responseJson.toString(), getResponseHeaders(), HttpStatus.OK); } diff --git a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java index 7f838043..f3d1e788 100644 --- a/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java +++ b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java @@ -2162,13 +2162,10 @@ public class OpenViduTestAppE2eTest { SessionProperties properties = new SessionProperties.Builder().customSessionId(customSessionId) .mediaMode(MediaMode.ROUTED).recordingMode(RecordingMode.ALWAYS) - .defaultOutputMode(OutputMode.INDIVIDUAL) - .forcedVideoCodec(VideoCodec.VP8) - .allowTranscoding(false) - .build(); + .defaultOutputMode(OutputMode.INDIVIDUAL).build(); Session session = OV.createSession(properties); - Assert.assertFalse("Session.fetch() should return true after OpenVidu.createSession() because some default properties are created in the server", session.fetch()); + Assert.assertFalse("Session.fetch() should return false after OpenVidu.createSession()", session.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false after OpenVidu.createSession()", OV.fetch()); sessions = OV.getActiveSessions(); Assert.assertEquals("Expected 1 active session but found " + sessions.size(), 1, sessions.size()); @@ -2357,7 +2354,7 @@ public class OpenViduTestAppE2eTest { Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus()); } Session sessionAux = OV.createSession(); - Assert.assertTrue("OpenVidu.fetch() should return true", OV.fetch()); + Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch()); try { OV.startRecording(sessionAux.getSessionId()); } catch (OpenViduHttpException e) { @@ -2452,7 +2449,7 @@ public class OpenViduTestAppE2eTest { OV.deleteRecording(recording2.getId()); recording2 = OV.startRecording(session.getSessionId(), recordingProperties); - user.getEventManager().waitUntilEventReaches("recordingStarted", 2); + // user.getEventManager().waitUntilEventReaches("recordingStarted", 2); Assert.assertEquals("Wrong recording name", customRecordingName, recording2.getName()); Assert.assertEquals("Wrong recording id", session.getSessionId() + "-1", recording2.getId());