From 0e3e82d7e18fe55dcc2c895fcb49e96d6dc238f6 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Fri, 2 Oct 2020 16:40:03 +0200 Subject: [PATCH] OpenVidu SDKs: use new paths to consume REST API --- .../io/openvidu/java/client/OpenVidu.java | 36 +++++----- .../io/openvidu/java/client/Recording.java | 49 +++++++------- .../java/client/RecordingProperties.java | 65 +++++++++++-------- openvidu-node-client/src/OpenVidu.ts | 27 +++++--- openvidu-node-client/src/Recording.ts | 51 +++++++-------- 5 files changed, 125 insertions(+), 103 deletions(-) diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenVidu.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenVidu.java index 298c07ee..1ba75945 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenVidu.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenVidu.java @@ -70,16 +70,19 @@ public class OpenVidu { protected HttpClient httpClient; protected Map activeSessions = new ConcurrentHashMap<>(); - protected final static String API_SESSIONS = "api/sessions"; - protected final static String API_TOKENS = "api/tokens"; - protected final static String API_RECORDINGS = "api/recordings"; - protected final static String API_RECORDINGS_START = "/start"; - protected final static String API_RECORDINGS_STOP = "/stop"; + protected final static String API_PATH = "openvidu/api"; + protected final static String API_SESSIONS = API_PATH + "/sessions"; + protected final static String API_TOKENS = API_PATH + "/tokens"; + protected final static String API_RECORDINGS = API_PATH + "/recordings"; + protected final static String API_RECORDINGS_START = API_RECORDINGS + "/start"; + protected final static String API_RECORDINGS_STOP = API_RECORDINGS + "/stop"; /** - * @param urlOpenViduServer Public accessible IP where your instance of OpenVidu - * Server is up an running - * @param secret Secret used on OpenVidu Server initialization + * @param hostname URL where your instance of OpenVidu Server is up an running. + * It must be the full URL (e.g. + * https://12.34.56.78:1234/) + * + * @param secret Secret used on OpenVidu Server initialization */ public OpenVidu(String hostname, String secret) { @@ -192,7 +195,7 @@ public class OpenVidu { public Recording startRecording(String sessionId, RecordingProperties properties) throws OpenViduJavaClientException, OpenViduHttpException { - HttpPost request = new HttpPost(this.hostname + API_RECORDINGS + API_RECORDINGS_START); + HttpPost request = new HttpPost(this.hostname + API_RECORDINGS_START); JsonObject json = new JsonObject(); json.addProperty("session", sessionId); @@ -201,7 +204,8 @@ public class OpenVidu { json.addProperty("hasAudio", properties.hasAudio()); json.addProperty("hasVideo", properties.hasVideo()); - if ((Recording.OutputMode.COMPOSED.equals(properties.outputMode()) || (Recording.OutputMode.COMPOSED_QUICK_START.equals(properties.outputMode()))) + if ((Recording.OutputMode.COMPOSED.equals(properties.outputMode()) + || (Recording.OutputMode.COMPOSED_QUICK_START.equals(properties.outputMode()))) && properties.hasVideo()) { json.addProperty("resolution", properties.resolution()); json.addProperty("recordingLayout", @@ -236,8 +240,9 @@ public class OpenVidu { if (activeSession != null) { activeSession.setIsBeingRecorded(true); } else { - log.warn("No active session found for sessionId '" + r.getSessionId() - + "'. This instance of OpenVidu Java Client didn't create this session"); + log.warn( + "No active session found for sessionId '{}'. This instance of OpenVidu Java Client didn't create this session", + r.getSessionId()); } return r; } else { @@ -352,7 +357,7 @@ public class OpenVidu { * */ public Recording stopRecording(String recordingId) throws OpenViduJavaClientException, OpenViduHttpException { - HttpPost request = new HttpPost(this.hostname + API_RECORDINGS + API_RECORDINGS_STOP + "/" + recordingId); + HttpPost request = new HttpPost(this.hostname + API_RECORDINGS_STOP + "/" + recordingId); HttpResponse response; try { response = this.httpClient.execute(request); @@ -368,8 +373,9 @@ public class OpenVidu { if (activeSession != null) { activeSession.setIsBeingRecorded(false); } else { - log.warn("No active session found for sessionId '" + r.getSessionId() - + "'. This instance of OpenVidu Java Client didn't create this session"); + log.warn( + "No active session found for sessionId '{}'. This instance of OpenVidu Java Client didn't create this session", + r.getSessionId()); } return r; } else { diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/Recording.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/Recording.java index 305201c6..b984ed8f 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/Recording.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/Recording.java @@ -48,9 +48,8 @@ public class Recording { stopped, /** - * The recording has finished OK and is available for download through OpenVidu - * Server recordings endpoint: - * https://YOUR_OPENVIDUSERVER_IP/recordings/{RECORDING_ID}/{RECORDING_NAME}.{EXTENSION} + * The recording has finished being processed and is available for download + * through property {@link Recording#getUrl} */ ready, @@ -75,27 +74,25 @@ public class Recording { * Record each stream individually */ INDIVIDUAL, - + /** - * Works the same way as COMPOSED mode, but the necessary recorder - * service module will start some time in advance and won't be terminated - * once a specific session recording has ended. This module will remain - * up and running as long as the session remains active.

+ * Works the same way as COMPOSED mode, but the necessary recorder service + * module will start some time in advance and won't be terminated once a + * specific session recording has ended. This module will remain up and running + * as long as the session remains active.
+ *
* * */ COMPOSED_QUICK_START; @@ -129,7 +126,8 @@ public class Recording { OutputMode outputMode = OutputMode.valueOf(json.get("outputMode").getAsString()); RecordingProperties.Builder builder = new RecordingProperties.Builder().name(json.get("name").getAsString()) .outputMode(outputMode).hasAudio(hasAudio).hasVideo(hasVideo); - if ((OutputMode.COMPOSED.equals(outputMode) || OutputMode.COMPOSED_QUICK_START.equals(outputMode)) && hasVideo) { + if ((OutputMode.COMPOSED.equals(outputMode) || OutputMode.COMPOSED_QUICK_START.equals(outputMode)) + && hasVideo) { builder.resolution(json.get("resolution").getAsString()); builder.recordingLayout(RecordingLayout.valueOf(json.get("recordingLayout").getAsString())); JsonElement customLayout = json.get("customLayout"); @@ -219,8 +217,8 @@ public class Recording { /** * URL of the recording. You can access the file from there. It is * null until recording reaches "ready" or "failed" status. If - * OpenVidu Server configuration property + * OpenVidu Server configuration property * OPENVIDU_RECORDING_PUBLIC_ACCESS is false, this path will be * secured with OpenVidu credentials */ @@ -230,7 +228,8 @@ public class Recording { /** * Resolution of the video file. Only defined if OutputMode of the Recording is - * set to {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} + * set to {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} */ public String getResolution() { return this.recordingProperties.resolution(); diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/RecordingProperties.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/RecordingProperties.java index 47f526ae..a76ced2c 100644 --- a/openvidu-java-client/src/main/java/io/openvidu/java/client/RecordingProperties.java +++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/RecordingProperties.java @@ -52,7 +52,8 @@ public class RecordingProperties { * Builder for {@link io.openvidu.java.client.RecordingProperties} */ public RecordingProperties build() { - if (OutputMode.COMPOSED.equals(this.outputMode) || OutputMode.COMPOSED_QUICK_START.equals(this.outputMode)) { + if (OutputMode.COMPOSED.equals(this.outputMode) + || OutputMode.COMPOSED_QUICK_START.equals(this.outputMode)) { this.recordingLayout = this.recordingLayout != null ? this.recordingLayout : RecordingLayout.BEST_FIT; this.resolution = this.resolution != null ? this.resolution : "1920x1080"; if (RecordingLayout.CUSTOM.equals(this.recordingLayout)) { @@ -102,11 +103,14 @@ public class RecordingProperties { * method to set the relative path to the specific custom layout you want to * use.
* Will only have effect if - * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} - * has been called with value - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}.
- * See + * See Custom recording layouts to learn more */ public RecordingProperties.Builder customLayout(String path) { @@ -119,13 +123,15 @@ public class RecordingProperties { * format "WIDTHxHEIGHT", being both WIDTH and HEIGHT the number of pixels * between 100 and 1999.
* Will only have effect if - * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} - * has been called with value - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}. For - * {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all - * individual video files will have the native resolution of the published - * stream + * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode) + * Builder.outputMode()} has been called with value + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED + * OutputMode.COMPOSED} or + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START + * OutputMode.COMPOSED_QUICK_START}. For + * {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL + * OutputMode.INDIVIDUAL} all individual video files will have the native + * resolution of the published stream */ public RecordingProperties.Builder resolution(String resolution) { this.resolution = resolution; @@ -134,7 +140,8 @@ public class RecordingProperties { /** * Call this method to specify whether to record audio or not. Cannot be set to - * false at the same time as {@link hasVideo(boolean)} + * false at the same time as + * {@link RecordingProperties.Builder#hasVideo(boolean)} */ public RecordingProperties.Builder hasAudio(boolean hasAudio) { this.hasAudio = hasAudio; @@ -143,7 +150,8 @@ public class RecordingProperties { /** * Call this method to specify whether to record video or not. Cannot be set to - * false at the same time as {@link hasAudio(boolean)} + * false at the same time as + * {@link RecordingProperties.Builder#hasAudio(boolean)} */ public RecordingProperties.Builder hasVideo(boolean hasVideo) { this.hasVideo = hasVideo; @@ -185,12 +193,12 @@ public class RecordingProperties { /** * Defines the mode of recording: {@link Recording.OutputMode#COMPOSED} or - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} for a - * single archive in a grid layout or {@link Recording.OutputMode#INDIVIDUAL} + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} for + * a single archive in a grid layout or {@link Recording.OutputMode#INDIVIDUAL} * for one archive for each stream.
*
* - * Default to {@link Recording.OutputMode#COMPOSED} + * Default to {@link Recording.OutputMode#COMPOSED OutputMode.COMPOSED} */ public Recording.OutputMode outputMode() { return this.outputMode; @@ -199,12 +207,14 @@ public class RecordingProperties { /** * Defines the layout to be used in the recording.
* Will only have effect if - * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} - * has been called with value {@link Recording.OutputMode#COMPOSED} or - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}.
+ * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode) + * Builder.outputMode()} has been called with value + * {@link Recording.OutputMode#COMPOSED OutputMode.COMPOSED} or + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START + * OutputMode.COMPOSED_QUICK_START}.
*
* - * Default to {@link RecordingLayout#BEST_FIT} + * Default to {@link RecordingLayout#BEST_FIT RecordingLayout.BEST_FIT} */ public RecordingLayout recordingLayout() { return this.recordingLayout; @@ -214,7 +224,8 @@ public class RecordingProperties { * If {@link io.openvidu.java.client.RecordingProperties#recordingLayout()} is * set to {@link io.openvidu.java.client.RecordingLayout#CUSTOM}, this property * defines the relative path to the specific custom layout you want to use.
- * See Custom recording layouts to learn more */ public String customLayout() { @@ -227,8 +238,8 @@ public class RecordingProperties { * {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} * has been called with value * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or - * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}. For - * {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all + * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}. + * For {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all * individual video files will have the native resolution of the published * stream.
*
@@ -241,7 +252,7 @@ public class RecordingProperties { /** * Defines whether to record audio or not. Cannot be set to false at the same - * time as {@link hasVideo()}.
+ * time as {@link RecordingProperties#hasVideo()}.
*
* * Default to true @@ -252,7 +263,7 @@ public class RecordingProperties { /** * Defines whether to record video or not. Cannot be set to false at the same - * time as {@link hasAudio()}.
+ * time as {@link RecordingProperties#hasAudio()}.
*
* * Default to true diff --git a/openvidu-node-client/src/OpenVidu.ts b/openvidu-node-client/src/OpenVidu.ts index f6d6a318..4f572dcb 100644 --- a/openvidu-node-client/src/OpenVidu.ts +++ b/openvidu-node-client/src/OpenVidu.ts @@ -47,23 +47,29 @@ export class OpenVidu { /** * @hidden */ - static readonly API_RECORDINGS: string = '/api/recordings'; + static readonly API_PATH: string = '/openvidu/api'; /** * @hidden */ - static readonly API_RECORDINGS_START: string = '/start'; + static readonly API_SESSIONS = OpenVidu.API_PATH + '/sessions'; /** * @hidden */ - static readonly API_RECORDINGS_STOP: string = '/stop'; + static readonly API_TOKENS = OpenVidu.API_PATH + '/tokens'; /** * @hidden */ - static readonly API_SESSIONS = '/api/sessions'; + static readonly API_RECORDINGS: string = OpenVidu.API_PATH + '/recordings'; /** * @hidden */ - static readonly API_TOKENS = '/api/tokens'; + static readonly API_RECORDINGS_START: string = OpenVidu.API_RECORDINGS + '/start'; + /** + * @hidden + */ + static readonly API_RECORDINGS_STOP: string = OpenVidu.API_RECORDINGS + '/stop'; + + /** @@ -83,7 +89,8 @@ export class OpenVidu { activeSessions: Session[] = []; /** - * @param urlOpenViduServer Public accessible IP where your instance of OpenVidu Server is up an running + * @param urlOpenViduServer URL where your instance of OpenVidu Server is up an running. + * It must be the full URL (e.g. `https://12.34.56.78:1234/`) * @param secret Secret used on OpenVidu Server initialization */ constructor(private urlOpenViduServer: string, secret: string) { @@ -144,8 +151,8 @@ export class OpenVidu { hasAudio: !!(properties.hasAudio), hasVideo: !!(properties.hasVideo) }; - if (data.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED] - || data.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START]) { + if (data.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED] + || data.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START]) { data.resolution = !!properties.resolution ? properties.resolution : '1920x1080'; data.recordingLayout = !!properties.recordingLayout ? properties.recordingLayout : RecordingLayout.BEST_FIT; if (data.recordingLayout.toString() === RecordingLayout[RecordingLayout.CUSTOM]) { @@ -169,7 +176,7 @@ export class OpenVidu { } axios.post( - this.host + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_START, + this.host + OpenVidu.API_RECORDINGS_START, data, { headers: { @@ -223,7 +230,7 @@ export class OpenVidu { return new Promise((resolve, reject) => { axios.post( - this.host + OpenVidu.API_RECORDINGS + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, + this.host + OpenVidu.API_RECORDINGS_STOP + '/' + recordingId, undefined, { headers: { diff --git a/openvidu-node-client/src/Recording.ts b/openvidu-node-client/src/Recording.ts index 85635e3a..cc0989a6 100644 --- a/openvidu-node-client/src/Recording.ts +++ b/openvidu-node-client/src/Recording.ts @@ -83,7 +83,7 @@ export class Recording { hasVideo: !!json['hasVideo'] }; if (this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED] - || this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START]) { + || this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED_QUICK_START]) { this.properties.resolution = !!(json['resolution']) ? json['resolution'] : '1920x1080'; this.properties.recordingLayout = !!(json['recordingLayout']) ? json['recordingLayout'] : RecordingLayout.BEST_FIT; if (this.properties.recordingLayout.toString() === RecordingLayout[RecordingLayout.CUSTOM]) { @@ -103,7 +103,7 @@ export namespace Recording { /** * The recording is starting (cannot be stopped). Some recording may not go - * through this status and directly reach "started" status + * through this status and directly reach "started" status */ starting = 'starting', @@ -113,21 +113,20 @@ export namespace Recording { started = 'started', /** - * The recording has stopped and is being processed. At some point it will reach - * "ready" status - */ + * The recording has stopped and is being processed. At some point it will reach + * "ready" status + */ stopped = 'stopped', /** - * The recording has finished OK and is available for download through OpenVidu - * Server recordings endpoint: - * https://YOUR_OPENVIDUSERVER_IP/recordings/{RECORDING_ID}/{RECORDING_NAME}.{EXTENSION} + * The recording has finished being processed and is available for download through + * property [[Recording.url]] */ ready = 'ready', /** * The recording has failed. This status may be reached from "starting", - * "started" and "stopped" status + * "started" and "stopped" status */ failed = 'failed' } @@ -141,24 +140,24 @@ export namespace Recording { * Record all streams in a grid layout in a single archive */ COMPOSED = 'COMPOSED', - - /** - * Works the same way as COMPOSED mode, but the necessary recorder - * service module will start some time in advance and won't be terminated - * once a specific session recording has ended. This module will remain - * up and running as long as the session remains active. - * - * - **Pros vs COMPOSED**: the process of starting the recording will be noticeably - * faster. This can be very useful in use cases where a session needs to be - * recorded multiple times over time, when a better response time is usually - * desirable. - * - **Cons vs COMPOSED**: for every session initialized with COMPOSED_QUICK_START - * recording output mode, extra CPU power will be required in OpenVidu Server. - * The recording module will be continuously rendering all of the streams being - * published to the session even when the session is not being recorded. And that - * is for every session configured with COMPOSED_QUICK_START. - */ + /** + * Works the same way as COMPOSED mode, but the necessary recorder + * service module will start some time in advance and won't be terminated + * once a specific session recording has ended. This module will remain + * up and running as long as the session remains active. + * + * - **Pros vs COMPOSED**: the process of starting the recording will be noticeably + * faster. This can be very useful in use cases where a session needs to be + * recorded multiple times over time, when a better response time is usually + * desirable. + + * - **Cons vs COMPOSED**: for every session initialized with COMPOSED_QUICK_START + * recording output mode, extra CPU power will be required in OpenVidu Server. + * The recording module will be continuously rendering all of the streams being + * published to the session even when the session is not being recorded. And that + * is for every session configured with COMPOSED_QUICK_START. + */ COMPOSED_QUICK_START = 'COMPOSED_QUICK_START', /**