From e38c7e4a6cebf26ab5037e98e818a90283b73d17 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Fri, 9 Apr 2021 17:32:33 +0200 Subject: [PATCH] openvidu-java-client/openvidu-node-client: new RecordingProperties defaults --- .../io/openvidu/java/client/OpenVidu.java | 20 +- .../io/openvidu/java/client/Recording.java | 34 +- .../java/client/RecordingProperties.java | 295 ++++++++++-------- openvidu-node-client/src/Recording.ts | 36 ++- .../src/RecordingProperties.ts | 42 +-- openvidu-node-client/src/Session.ts | 22 +- 6 files changed, 244 insertions(+), 205 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 5b065b4a..b5cc0cfe 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 @@ -196,26 +196,8 @@ public class OpenVidu { HttpPost request = new HttpPost(this.hostname + API_RECORDINGS_START); - JsonObject json = new JsonObject(); + JsonObject json = properties.toJson(); json.addProperty("session", sessionId); - json.addProperty("name", properties.name()); - json.addProperty("outputMode", properties.outputMode() != null ? properties.outputMode().name() : null); - json.addProperty("hasAudio", properties.hasAudio()); - json.addProperty("hasVideo", properties.hasVideo()); - json.addProperty("shmSize", properties.shmSize()); - json.addProperty("mediaNode", properties.mediaNode()); - - if ((properties.outputMode() == null || Recording.OutputMode.COMPOSED.equals(properties.outputMode()) - || (Recording.OutputMode.COMPOSED_QUICK_START.equals(properties.outputMode()))) - && properties.hasVideo()) { - json.addProperty("resolution", properties.resolution()); - json.addProperty("frameRate", properties.frameRate()); - json.addProperty("recordingLayout", - (properties.recordingLayout() != null) ? properties.recordingLayout().name() : ""); - if (RecordingLayout.CUSTOM.equals(properties.recordingLayout())) { - json.addProperty("customLayout", (properties.customLayout() != null) ? properties.customLayout() : ""); - } - } StringEntity params = null; try { 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 2a22e3c9..4bf75994 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 @@ -159,6 +159,22 @@ public class Recording { return this.recordingProperties.name(); } + /** + * true if the recording has an audio track, false + * otherwise (currently fixed to true) + */ + public boolean hasAudio() { + return this.recordingProperties.hasAudio(); + } + + /** + * true if the recording has a video track, false + * otherwise (currently fixed to true) + */ + public boolean hasVideo() { + return this.recordingProperties.hasVideo(); + } + /** * Mode of recording: COMPOSED for a single archive in a grid layout or * INDIVIDUAL for one archive for each stream @@ -249,24 +265,8 @@ public class Recording { * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} and * {@link Recording#hasVideo()} is true */ - public int getFrameRate() { + public Integer getFrameRate() { return this.recordingProperties.frameRate(); } - /** - * true if the recording has an audio track, false - * otherwise (currently fixed to true) - */ - public boolean hasAudio() { - return this.recordingProperties.hasAudio(); - } - - /** - * true if the recording has a video track, false - * otherwise (currently fixed to true) - */ - public boolean hasVideo() { - return this.recordingProperties.hasVideo(); - } - } 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 72e4beab..4beb83ae 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 @@ -27,15 +27,29 @@ import io.openvidu.java.client.Recording.OutputMode; */ public class RecordingProperties { - private String name; - private Recording.OutputMode outputMode; + public static class DefaultValues { + public static final Boolean hasAudio = true; + public static final Boolean hasVideo = true; + public static final Recording.OutputMode outputMode = Recording.OutputMode.COMPOSED; + public static final RecordingLayout recordingLayout = RecordingLayout.BEST_FIT; + public static final String resolution = "1280x720"; + public static final Integer frameRate = 25; + public static final Long shmSize = 536870912L; + } + + // For all + private String name = ""; + private Boolean hasAudio = true; + private Boolean hasVideo = true; + private Recording.OutputMode outputMode = Recording.OutputMode.COMPOSED; + // For COMPOSED/COMPOSED_QUICK_START + hasVideo private RecordingLayout recordingLayout; - private String customLayout; private String resolution; - private int frameRate; - private boolean hasAudio; - private boolean hasVideo; - private long shmSize; // For COMPOSED recording + private Integer frameRate; + private Long shmSize; + // For COMPOSED/COMPOSED_QUICK_START + hasVideo + RecordingLayout.CUSTOM + private String customLayout; + // For OpenVidu Pro private String mediaNode; /** @@ -44,14 +58,14 @@ public class RecordingProperties { public static class Builder { private String name = ""; + private Boolean hasAudio = true; + private Boolean hasVideo = true; private Recording.OutputMode outputMode = Recording.OutputMode.COMPOSED; - private RecordingLayout recordingLayout = RecordingLayout.BEST_FIT; - private String customLayout = ""; - private String resolution = "1280x720"; - private int frameRate = 25; - private boolean hasAudio = true; - private boolean hasVideo = true; - private long shmSize = 536870912L; + private RecordingLayout recordingLayout; + private String resolution; + private Integer frameRate; + private Long shmSize; + private String customLayout; private String mediaNode; public Builder() { @@ -59,14 +73,14 @@ public class RecordingProperties { public Builder(RecordingProperties props) { this.name = props.name(); - this.outputMode = props.outputMode(); - this.recordingLayout = props.recordingLayout(); - this.customLayout = props.customLayout(); - this.resolution = props.resolution(); - this.frameRate = props.frameRate(); this.hasAudio = props.hasAudio(); this.hasVideo = props.hasVideo(); + this.outputMode = props.outputMode(); + this.recordingLayout = props.recordingLayout(); + this.resolution = props.resolution(); + this.frameRate = props.frameRate(); this.shmSize = props.shmSize(); + this.customLayout = props.customLayout(); this.mediaNode = props.mediaNode(); } @@ -74,8 +88,9 @@ public class RecordingProperties { * Builder for {@link io.openvidu.java.client.RecordingProperties} */ public RecordingProperties build() { - return new RecordingProperties(this.name, this.outputMode, this.recordingLayout, this.customLayout, - this.resolution, this.frameRate, this.hasAudio, this.hasVideo, this.shmSize, this.mediaNode); + return new RecordingProperties(this.name, this.hasAudio, this.hasVideo, this.outputMode, + this.recordingLayout, this.resolution, this.frameRate, this.shmSize, this.customLayout, + this.mediaNode); } /** @@ -86,6 +101,26 @@ public class RecordingProperties { return this; } + /** + * Call this method to specify whether to record audio or not. Cannot be set to + * false at the same time as + * {@link RecordingProperties.Builder#hasVideo(boolean)} + */ + public RecordingProperties.Builder hasAudio(boolean hasAudio) { + this.hasAudio = hasAudio; + return this; + } + + /** + * Call this method to specify whether to record video or not. Cannot be set to + * false at the same time as + * {@link RecordingProperties.Builder#hasAudio(boolean)} + */ + public RecordingProperties.Builder hasVideo(boolean hasVideo) { + this.hasVideo = hasVideo; + return this; + } + /** * Call this method to set the mode of recording: * {@link Recording.OutputMode#COMPOSED} or @@ -109,21 +144,6 @@ public class RecordingProperties { return this; } - /** - * If setting - * {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)} - * to {@link io.openvidu.java.client.RecordingLayout#CUSTOM} you can call this - * method to set the relative path to the specific custom layout you want to - * use.
- * See Custom recording layouts to learn more - */ - public RecordingProperties.Builder customLayout(String path) { - this.customLayout = path; - return this; - } - /** * Call this method to specify the recording resolution. Must be a string with * format "WIDTHxHEIGHT", being both WIDTH and HEIGHT the number of pixels @@ -157,26 +177,6 @@ public class RecordingProperties { return this; } - /** - * Call this method to specify whether to record audio or not. Cannot be set to - * false at the same time as - * {@link RecordingProperties.Builder#hasVideo(boolean)} - */ - public RecordingProperties.Builder hasAudio(boolean hasAudio) { - this.hasAudio = hasAudio; - return this; - } - - /** - * Call this method to specify whether to record video or not. Cannot be set to - * false at the same time as - * {@link RecordingProperties.Builder#hasAudio(boolean)} - */ - public RecordingProperties.Builder hasVideo(boolean hasVideo) { - this.hasVideo = hasVideo; - return this; - } - /** * Call this method to specify the amount of shared memory reserved for the * recording process in bytes. Minimum 134217728 (128MB).
@@ -191,6 +191,21 @@ public class RecordingProperties { return this; } + /** + * If setting + * {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)} + * to {@link io.openvidu.java.client.RecordingLayout#CUSTOM} you can call this + * method to set the relative path to the specific custom layout you want to + * use.
+ * See Custom recording layouts to learn more + */ + public RecordingProperties.Builder customLayout(String path) { + this.customLayout = path; + return this; + } + /** * + *
+ * + * Default to true + */ + public Boolean hasAudio() { + return this.hasAudio; + } + + /** + * Defines whether to record video or not. Cannot be set to false at the same + * time as {@link RecordingProperties#hasAudio()}.
+ *
+ * + * Default to true + */ + public Boolean hasVideo() { + return this.hasVideo; + } + /** * Defines the mode of recording: {@link Recording.OutputMode#COMPOSED} or * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} for @@ -260,18 +302,6 @@ public class RecordingProperties { return this.recordingLayout; } - /** - * 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() { - return this.customLayout; - } - /** * Defines the resolution of the recorded video.
* Will only have effect for @@ -304,32 +334,10 @@ public class RecordingProperties { * * Default to 25 */ - public int frameRate() { + public Integer frameRate() { return this.frameRate; } - /** - * Defines whether to record audio or not. Cannot be set to false at the same - * time as {@link RecordingProperties#hasVideo()}.
- *
- * - * Default to true - */ - public boolean hasAudio() { - return this.hasAudio; - } - - /** - * Defines whether to record video or not. Cannot be set to false at the same - * time as {@link RecordingProperties#hasAudio()}.
- *
- * - * Default to true - */ - public boolean hasVideo() { - return this.hasVideo; - } - /** * The amount of shared memory reserved for the recording process in bytes. * Minimum 134217728 (128MB).
@@ -342,10 +350,22 @@ public class RecordingProperties { * * Default to 536870912 (512 MB) */ - public long shmSize() { + public Long shmSize() { return this.shmSize; } + /** + * 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() { + return this.customLayout; + } + /** * - * Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` (or `COMPOSED_QUICK_START`) and [[RecordingProperties.recordingLayout]] is `CUSTOM`
- * See [Custom recording layouts](/en/stable/advanced-features/recording#custom-recording-layouts) to learn more. - */ - customLayout?: string; - /** * Recording video file resolution. Must be a string with format "WIDTHxHEIGHT", * being both WIDTH and HEIGHT the number of pixels between 100 and 1999.
@@ -72,20 +79,6 @@ export interface RecordingProperties { */ frameRate?: number; - /** - * Whether or not to record audio. Cannot be set to false at the same time as [[RecordingProperties.hasVideo]] - * - * Default to true - */ - hasAudio?: boolean; - - /** - * Whether or not to record video. Cannot be set to false at the same time as [[RecordingProperties.hasAudio]] - * - * Default to true - */ - hasVideo?: boolean; - /** * The amount of shared memory reserved for the recording process in bytes. * Will only have effect if [[RecordingProperties.outputMode]] is set to [[Recording.OutputMode.COMPOSED]] or [[Recording.OutputMode.COMPOSED_QUICK_START]] @@ -96,6 +89,13 @@ export interface RecordingProperties { */ shmSize?: number; + /** + * The relative path to the specific custom layout you want to use.
+ * Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` (or `COMPOSED_QUICK_START`) and [[RecordingProperties.recordingLayout]] is `CUSTOM`
+ * See [Custom recording layouts](/en/stable/advanced-features/recording#custom-recording-layouts) to learn more. + */ + customLayout?: string; + /** * **This feature is part of OpenVidu Pro tier**
PRO * diff --git a/openvidu-node-client/src/Session.ts b/openvidu-node-client/src/Session.ts index c809bdcf..471af175 100644 --- a/openvidu-node-client/src/Session.ts +++ b/openvidu-node-client/src/Session.ts @@ -656,17 +656,21 @@ export class Session { this.properties.mediaMode = !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED; this.properties.recordingMode = !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL; this.properties.defaultRecordingProperties = { - name: !!this.properties.defaultRecordingProperties?.name ? this.properties.defaultRecordingProperties?.name : '', - outputMode: !!this.properties.defaultRecordingProperties?.outputMode ? this.properties.defaultRecordingProperties?.outputMode : Recording.OutputMode.COMPOSED, - recordingLayout: !!this.properties.defaultRecordingProperties?.recordingLayout ? this.properties.defaultRecordingProperties?.recordingLayout : RecordingLayout.BEST_FIT, - customLayout: !!this.properties.defaultRecordingProperties?.customLayout ? this.properties.defaultRecordingProperties?.customLayout : '', - resolution: !!this.properties.defaultRecordingProperties?.resolution ? this.properties.defaultRecordingProperties?.resolution : '1280x720', - frameRate: !!this.properties.defaultRecordingProperties?.frameRate ? this.properties.defaultRecordingProperties?.frameRate : 25, - hasAudio: !!this.properties.defaultRecordingProperties?.hasAudio ? this.properties.defaultRecordingProperties?.hasAudio : true, - hasVideo: !!this.properties.defaultRecordingProperties?.hasVideo ? this.properties.defaultRecordingProperties?.hasVideo : true, - shmSize: !!this.properties.defaultRecordingProperties?.shmSize ? this.properties.defaultRecordingProperties?.shmSize : 536870912, + name: !!this.properties.defaultRecordingProperties?.name ? this.properties.defaultRecordingProperties.name : '', + hasAudio: !!this.properties.defaultRecordingProperties?.hasAudio ? this.properties.defaultRecordingProperties.hasAudio : true, + hasVideo: !!this.properties.defaultRecordingProperties?.hasVideo ? this.properties.defaultRecordingProperties.hasVideo : true, + outputMode: !!this.properties.defaultRecordingProperties?.outputMode ? this.properties.defaultRecordingProperties.outputMode : Recording.OutputMode.COMPOSED, mediaNode: this.properties.defaultRecordingProperties?.mediaNode }; + if ((this.properties.defaultRecordingProperties.outputMode === Recording.OutputMode.COMPOSED || this.properties.defaultRecordingProperties.outputMode == Recording.OutputMode.COMPOSED_QUICK_START) && this.properties.defaultRecordingProperties.hasVideo) { + this.properties.defaultRecordingProperties.recordingLayout = !!this.properties.defaultRecordingProperties.recordingLayout ? this.properties.defaultRecordingProperties.recordingLayout : RecordingLayout.BEST_FIT; + this.properties.defaultRecordingProperties.resolution = !!this.properties.defaultRecordingProperties.resolution ? this.properties.defaultRecordingProperties.resolution : '1280x720'; + this.properties.defaultRecordingProperties.frameRate = !!this.properties.defaultRecordingProperties.frameRate ? this.properties.defaultRecordingProperties.frameRate : 25; + this.properties.defaultRecordingProperties.shmSize = !!this.properties.defaultRecordingProperties.shmSize ? this.properties.defaultRecordingProperties.shmSize : 536870912; + if (this.properties.defaultRecordingProperties.recordingLayout === RecordingLayout.CUSTOM) { + this.properties.defaultRecordingProperties.customLayout = !!this.properties.defaultRecordingProperties.customLayout ? this.properties.defaultRecordingProperties.customLayout : ''; + } + } this.properties.customSessionId = !!this.properties.customSessionId ? this.properties.customSessionId : ''; this.properties.mediaNode = !!this.properties.mediaNode ? this.properties.mediaNode : undefined; this.properties.forcedVideoCodec = !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : VideoCodec.VP8;