openvidu-java-client/openvidu-node-client RecordingProperties refactoring

pull/621/head
pabloFuente 2021-04-05 17:06:12 +02:00
parent 89e73262aa
commit b774d2cefc
11 changed files with 351 additions and 296 deletions

View File

@ -258,12 +258,10 @@ public class OpenVidu {
* Starts the recording of a {@link io.openvidu.java.client.Session} * Starts the recording of a {@link io.openvidu.java.client.Session}
* *
* @param sessionId The sessionId of the session you want to start recording * @param sessionId The sessionId of the session you want to start recording
* @param name The name you want to give to the video file. You can access * @param name The name you want to give to the video file.
* this same value in your clients on recording events * <strong>WARNING: this parameter follows an overwriting
* (recordingStarted, recordingStopped). <strong>WARNING: this * policy.</strong> If you name two recordings the same, the
* parameter follows an overwriting policy.</strong> If you * newest MP4 file will overwrite the oldest one
* name two recordings the same, the newest MP4 file will
* overwrite the oldest one
* *
* @return The started recording. If this method successfully returns the * @return The started recording. If this method successfully returns the
* Recording object it means that the recording can be stopped with * Recording object it means that the recording can be stopped with

View File

@ -153,9 +153,7 @@ public class Recording {
} }
/** /**
* Name of the recording. The video file will be named after this property. You * Name of the recording. The video file will be named after this property
* can access this same value in your clients on recording events
* (<code>recordingStarted</code>, <code>recordingStopped</code>)
*/ */
public String getName() { public String getName() {
return this.recordingProperties.name(); return this.recordingProperties.name();
@ -170,15 +168,22 @@ public class Recording {
} }
/** /**
* The layout used in this recording. Only defined if OutputMode is COMPOSED * The layout used in this recording. Only applicable if
* {@link io.openvidu.java.client.Recording.OutputMode} is
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} and
* {@link Recording#hasVideo()} is true
*/ */
public RecordingLayout getRecordingLayout() { public RecordingLayout getRecordingLayout() {
return this.recordingProperties.recordingLayout(); return this.recordingProperties.recordingLayout();
} }
/** /**
* The custom layout used in this recording. Only defined if if OutputMode is * The custom layout used in this recording. Only applicable if
* COMPOSED and * {@link io.openvidu.java.client.Recording.OutputMode} is
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START},
* {@link Recording#hasVideo()} is true and
* {@link io.openvidu.java.client.RecordingProperties.Builder#customLayout(String)} * {@link io.openvidu.java.client.RecordingProperties.Builder#customLayout(String)}
* has been called * has been called
*/ */
@ -227,14 +232,27 @@ public class Recording {
} }
/** /**
* Resolution of the video file. Only defined if OutputMode of the Recording is * Resolution of the video file. Only applicable if
* set to {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or * {@link io.openvidu.java.client.Recording.OutputMode} is
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} and
* {@link Recording#hasVideo()} is true
*/ */
public String getResolution() { public String getResolution() {
return this.recordingProperties.resolution(); return this.recordingProperties.resolution();
} }
/**
* Frame rate of the video file. Only applicable if
* {@link io.openvidu.java.client.Recording.OutputMode} is
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START} and
* {@link Recording#hasVideo()} is true
*/
public int getFrameRate() {
return this.recordingProperties.frameRate();
}
/** /**
* <code>true</code> if the recording has an audio track, <code>false</code> * <code>true</code> if the recording has an audio track, <code>false</code>
* otherwise (currently fixed to true) * otherwise (currently fixed to true)

View File

@ -19,9 +19,7 @@ package io.openvidu.java.client;
/** /**
* See * See
* {@link io.openvidu.java.client.SessionProperties.Builder#defaultRecordingLayout(RecordingLayout)} * {@link io.openvidu.java.client.RecordingProperties#recordingLayout(RecordingLayout)}
* and
* {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)}
*/ */
public enum RecordingLayout { public enum RecordingLayout {
@ -46,8 +44,8 @@ public enum RecordingLayout {
HORIZONTAL_PRESENTATION, HORIZONTAL_PRESENTATION,
/** /**
* Use your own custom recording layout. See * Use your own custom recording layout. See <a href=
* <a href="https://docs.openvidu.io/en/stable/advanced-features/recording#custom-recording-layouts" * "https://docs.openvidu.io/en/stable/advanced-features/recording#custom-recording-layouts"
* target="_blank">Custom recording layouts</a> to learn more * target="_blank">Custom recording layouts</a> to learn more
*/ */
CUSTOM CUSTOM

View File

@ -17,6 +17,10 @@
package io.openvidu.java.client; package io.openvidu.java.client;
import com.google.gson.JsonObject;
import io.openvidu.java.client.Recording.OutputMode;
/** /**
* See * See
* {@link io.openvidu.java.client.OpenVidu#startRecording(String, RecordingProperties)} * {@link io.openvidu.java.client.OpenVidu#startRecording(String, RecordingProperties)}
@ -28,6 +32,7 @@ public class RecordingProperties {
private RecordingLayout recordingLayout; private RecordingLayout recordingLayout;
private String customLayout; private String customLayout;
private String resolution; private String resolution;
private int frameRate;
private boolean hasAudio; private boolean hasAudio;
private boolean hasVideo; private boolean hasVideo;
private long shmSize; // For COMPOSED recording private long shmSize; // For COMPOSED recording
@ -39,27 +44,42 @@ public class RecordingProperties {
public static class Builder { public static class Builder {
private String name = ""; private String name = "";
private Recording.OutputMode outputMode; private Recording.OutputMode outputMode = Recording.OutputMode.COMPOSED;
private RecordingLayout recordingLayout; private RecordingLayout recordingLayout = RecordingLayout.BEST_FIT;
private String customLayout; private String customLayout = "";
private String resolution; private String resolution = "1280x720";
private int frameRate = 25;
private boolean hasAudio = true; private boolean hasAudio = true;
private boolean hasVideo = true; private boolean hasVideo = true;
private long shmSize = 536870912L; private long shmSize = 536870912L;
private String mediaNode; private String mediaNode;
public Builder() {
}
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.shmSize = props.shmSize();
this.mediaNode = props.mediaNode();
}
/** /**
* Builder for {@link io.openvidu.java.client.RecordingProperties} * Builder for {@link io.openvidu.java.client.RecordingProperties}
*/ */
public RecordingProperties build() { public RecordingProperties build() {
return new RecordingProperties(this.name, this.outputMode, this.recordingLayout, this.customLayout, return new RecordingProperties(this.name, this.outputMode, this.recordingLayout, this.customLayout,
this.resolution, this.hasAudio, this.hasVideo, this.shmSize, this.mediaNode); this.resolution, this.frameRate, this.hasAudio, this.hasVideo, this.shmSize, this.mediaNode);
} }
/** /**
* Call this method to set the name of the video file. You can access this same * Call this method to set the name of the video file
* value in your clients on recording events (<code>recordingStarted</code>,
* <code>recordingStopped</code>)
*/ */
public RecordingProperties.Builder name(String name) { public RecordingProperties.Builder name(String name) {
this.name = name; this.name = name;
@ -67,8 +87,11 @@ public class RecordingProperties {
} }
/** /**
* Call this method to set the mode of recording: COMPOSED for a single archive * Call this method to set the mode of recording:
* in a grid layout or INDIVIDUAL for one archive for each stream * {@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}
* for one archive for each stream.
*/ */
public RecordingProperties.Builder outputMode(Recording.OutputMode outputMode) { public RecordingProperties.Builder outputMode(Recording.OutputMode outputMode) {
this.outputMode = outputMode; this.outputMode = outputMode;
@ -77,11 +100,9 @@ public class RecordingProperties {
/** /**
* Call this method to set the layout to be used in the recording. Will only * Call this method to set the layout to be used in the recording. Will only
* have effect if * have effect for {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED}
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} * or {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* has been called with value * recordings with {@link RecordingProperties#hasVideo()} to true.
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
*/ */
public RecordingProperties.Builder recordingLayout(RecordingLayout layout) { public RecordingProperties.Builder recordingLayout(RecordingLayout layout) {
this.recordingLayout = layout; this.recordingLayout = layout;
@ -94,13 +115,6 @@ public class RecordingProperties {
* to {@link io.openvidu.java.client.RecordingLayout#CUSTOM} you can call this * 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 * method to set the relative path to the specific custom layout you want to
* use.<br> * use.<br>
* Will only have effect if
* {@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}.<br>
* See <a href= * See <a href=
* "https://docs.openvidu.io/en/stable/advanced-features/recording#custom-recording-layouts" * "https://docs.openvidu.io/en/stable/advanced-features/recording#custom-recording-layouts"
* target="_blank">Custom recording layouts</a> to learn more * target="_blank">Custom recording layouts</a> to learn more
@ -114,22 +128,35 @@ public class RecordingProperties {
* Call this method to specify the recording resolution. Must be a string with * Call this method to specify the recording resolution. Must be a string with
* format "WIDTHxHEIGHT", being both WIDTH and HEIGHT the number of pixels * format "WIDTHxHEIGHT", being both WIDTH and HEIGHT the number of pixels
* between 100 and 1999.<br> * between 100 and 1999.<br>
* Will only have effect if * Will only have effect for
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode) * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* Builder.outputMode()} has been called with value * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED * recordings with {@link RecordingProperties#hasVideo()} to true. Property
* OutputMode.COMPOSED} or * ignored for INDIVIDUAL recordings and audio-only recordings. For
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START * {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all
* OutputMode.COMPOSED_QUICK_START}. For * individual video files will have the native resolution of the published
* {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL * stream.
* OutputMode.INDIVIDUAL} all individual video files will have the native
* resolution of the published stream
*/ */
public RecordingProperties.Builder resolution(String resolution) { public RecordingProperties.Builder resolution(String resolution) {
this.resolution = resolution; this.resolution = resolution;
return this; return this;
} }
/**
* Call this method to specify the recording frame rate. Will only have effect
* for {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* recordings with {@link RecordingProperties#hasVideo()} to true. Property
* ignored for INDIVIDUAL recordings and audio-only recordings. For
* {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all
* individual video files will have the native frame rate of the published
* stream.
*/
public RecordingProperties.Builder frameRate(int frameRate) {
this.frameRate = frameRate;
return this;
}
/** /**
* Call this method to specify whether to record audio or not. Cannot be set to * Call this method to specify whether to record audio or not. Cannot be set to
* false at the same time as * false at the same time as
@ -151,9 +178,13 @@ public class RecordingProperties {
} }
/** /**
* If COMPOSED recording, call this method to specify the amount of shared * Call this method to specify the amount of shared memory reserved for the
* memory reserved for the recording process in bytes. Minimum 134217728 (128 * recording process in bytes. Minimum 134217728 (128MB).<br>
* MB). Property ignored if INDIVIDUAL recording * Will only have effect for
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* recordings with {@link RecordingProperties#hasVideo()} to true. Property
* ignored for INDIVIDUAL recordings and audio-only recordings
*/ */
public RecordingProperties.Builder shmSize(long shmSize) { public RecordingProperties.Builder shmSize(long shmSize) {
this.shmSize = shmSize; this.shmSize = shmSize;
@ -167,8 +198,10 @@ public class RecordingProperties {
* 3px; font-size: 13px; line-height:21px; font-family: Montserrat, * 3px; font-size: 13px; line-height:21px; font-family: Montserrat,
* sans-serif">PRO</a> Call this method to force the recording to be hosted in * sans-serif">PRO</a> Call this method to force the recording to be hosted in
* the Media Node with identifier <code>mediaNodeId</code>. This property only * the Media Node with identifier <code>mediaNodeId</code>. This property only
* applies to COMPOSED recordings and is ignored for INDIVIDUAL recordings, that * applies to COMPOSED or COMPOSED_QUICK_START recordings with
* are always hosted in the same Media Node hosting its Session * {@link RecordingProperties#hasVideo()} to true and is ignored for INDIVIDUAL
* recordings and audio-only recordings, that are always hosted in the same
* Media Node hosting its Session
*/ */
public RecordingProperties.Builder mediaNode(String mediaNodeId) { public RecordingProperties.Builder mediaNode(String mediaNodeId) {
this.mediaNode = mediaNodeId; this.mediaNode = mediaNodeId;
@ -178,13 +211,14 @@ public class RecordingProperties {
} }
protected RecordingProperties(String name, Recording.OutputMode outputMode, RecordingLayout layout, protected RecordingProperties(String name, Recording.OutputMode outputMode, RecordingLayout layout,
String customLayout, String resolution, boolean hasAudio, boolean hasVideo, long shmSize, String customLayout, String resolution, int frameRate, boolean hasAudio, boolean hasVideo, long shmSize,
String mediaNode) { String mediaNode) {
this.name = name; this.name = name;
this.outputMode = outputMode; this.outputMode = outputMode;
this.recordingLayout = layout; this.recordingLayout = layout;
this.customLayout = customLayout; this.customLayout = customLayout;
this.resolution = resolution; this.resolution = resolution;
this.frameRate = frameRate;
this.hasAudio = hasAudio; this.hasAudio = hasAudio;
this.hasVideo = hasVideo; this.hasVideo = hasVideo;
this.shmSize = shmSize; this.shmSize = shmSize;
@ -192,9 +226,7 @@ public class RecordingProperties {
} }
/** /**
* Defines the name you want to give to the video file. You can access this same * Defines the name you want to give to the video file
* value in your clients on recording events (<code>recordingStarted</code>,
* <code>recordingStopped</code>)
*/ */
public String name() { public String name() {
return this.name; return this.name;
@ -215,12 +247,11 @@ public class RecordingProperties {
/** /**
* Defines the layout to be used in the recording.<br> * Defines the layout to be used in the recording.<br>
* Will only have effect if * Will only have effect for
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode) * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* Builder.outputMode()} has been called with value * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* {@link Recording.OutputMode#COMPOSED OutputMode.COMPOSED} or * recordings with {@link RecordingProperties#hasVideo()} to true. Property
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START * ignored for INDIVIDUAL recordings and audio-only recordings<br>
* OutputMode.COMPOSED_QUICK_START}.<br>
* <br> * <br>
* *
* Default to {@link RecordingLayout#BEST_FIT RecordingLayout.BEST_FIT} * Default to {@link RecordingLayout#BEST_FIT RecordingLayout.BEST_FIT}
@ -243,22 +274,40 @@ public class RecordingProperties {
/** /**
* Defines the resolution of the recorded video.<br> * Defines the resolution of the recorded video.<br>
* Will only have effect if * Will only have effect for
* {@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} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}. * {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* For {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all * recordings with {@link RecordingProperties#hasVideo()} to true. Property
* ignored for INDIVIDUAL recordings and audio-only recordings. For
* {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all
* individual video files will have the native resolution of the published * individual video files will have the native resolution of the published
* stream.<br> * stream.<br>
* <br> * <br>
* *
* Default to "1920x1080" * Default to "1280x720"
*/ */
public String resolution() { public String resolution() {
return this.resolution; return this.resolution;
} }
/**
* Defines the frame rate of the recorded video.<br>
* Will only have effect for
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* recordings with {@link RecordingProperties#hasVideo()} to true. Property
* ignored for INDIVIDUAL recordings and audio-only recordings. For
* {@link io.openvidu.java.client.Recording.OutputMode#INDIVIDUAL} all
* individual video files will have the native frame rate of the published
* stream.<br>
* <br>
*
* Default to 25
*/
public int frameRate() {
return this.frameRate;
}
/** /**
* Defines whether to record audio or not. Cannot be set to false at the same * Defines whether to record audio or not. Cannot be set to false at the same
* time as {@link RecordingProperties#hasVideo()}.<br> * time as {@link RecordingProperties#hasVideo()}.<br>
@ -282,9 +331,13 @@ public class RecordingProperties {
} }
/** /**
* If COMPOSED recording, the amount of shared memory reserved for the recording * The amount of shared memory reserved for the recording process in bytes.
* process in bytes. Minimum 134217728 (128MB). Property ignored if INDIVIDUAL * Minimum 134217728 (128MB).<br>
* recording<br> * Will only have effect for
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
* recordings with {@link RecordingProperties#hasVideo()} to true. Property
* ignored for INDIVIDUAL recordings and audio-only recordings<br>
* <br> * <br>
* *
* Default to 536870912 (512 MB) * Default to 536870912 (512 MB)
@ -300,11 +353,71 @@ public class RecordingProperties {
* 3px; font-size: 13px; line-height:21px; font-family: Montserrat, * 3px; font-size: 13px; line-height:21px; font-family: Montserrat,
* sans-serif">PRO</a> The Media Node where to host the recording. The default * sans-serif">PRO</a> The Media Node where to host the recording. The default
* option if this property is not defined is the same Media Node hosting the * option if this property is not defined is the same Media Node hosting the
* Session to record. This property only applies to COMPOSED recordings and is * Session to record. This property only applies to COMPOSED or
* ignored for INDIVIDUAL recordings * COMPOSED_QUICK_START recordings with {@link RecordingProperties#hasVideo()}
* to true and is ignored for INDIVIDUAL recordings and audio-only recordings
*/ */
public String mediaNode() { public String mediaNode() {
return this.mediaNode; return this.mediaNode;
} }
/**
* @hidden
*/
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("name", name);
json.addProperty("outputMode", outputMode.name());
json.addProperty("hasAudio", hasAudio);
json.addProperty("hasVideo", hasVideo);
if (OutputMode.COMPOSED.equals(outputMode) || OutputMode.COMPOSED_QUICK_START.equals(outputMode)) {
json.addProperty("recordingLayout", recordingLayout.name());
if (RecordingLayout.CUSTOM.equals(recordingLayout)) {
json.addProperty("customLayout", customLayout);
}
json.addProperty("resolution", resolution);
json.addProperty("frameRate", frameRate);
json.addProperty("shmSize", shmSize);
}
if (this.mediaNode != null) {
json.addProperty("mediaNode", mediaNode);
}
return json;
}
public static RecordingProperties fromJson(JsonObject json) {
Builder builder = new RecordingProperties.Builder();
if (json.has("name")) {
builder.name(json.get("name").getAsString());
}
if (json.has("outputMode")) {
builder.outputMode(OutputMode.valueOf(json.get("outputMode").getAsString()));
}
if (json.has("recordingLayout")) {
builder.recordingLayout(RecordingLayout.valueOf(json.get("recordingLayout").getAsString()));
}
if (json.has("customLayout")) {
builder.customLayout(json.get("customLayout").getAsString());
}
if (json.has("resolution")) {
builder.resolution(json.get("resolution").getAsString());
}
if (json.has("frameRate")) {
builder.frameRate(json.get("frameRate").getAsInt());
}
if (json.has("hasAudio")) {
builder.hasAudio(json.get("hasAudio").getAsBoolean());
}
if (json.has("hasVideo")) {
builder.hasVideo(json.get("hasVideo").getAsBoolean());
}
if (json.has("shmSize")) {
builder.shmSize(json.get("shmSize").getAsLong());
}
if (json.has("mediaNode")) {
builder.mediaNode(json.get("mediaNode").getAsString());
}
return builder.build();
}
} }

View File

@ -684,22 +684,17 @@ public class Session {
this.sessionId = responseJson.get("id").getAsString(); this.sessionId = responseJson.get("id").getAsString();
this.createdAt = responseJson.get("createdAt").getAsLong(); this.createdAt = responseJson.get("createdAt").getAsLong();
// forcedVideoCodec and allowTranscoding values are configured in OpenVidu Server // forcedVideoCodec and allowTranscoding values are configured in OpenVidu
// via configuration or session // Server via configuration or session
VideoCodec forcedVideoCodec = VideoCodec.valueOf(responseJson.get("forcedVideoCodec").getAsString()); VideoCodec forcedVideoCodec = VideoCodec.valueOf(responseJson.get("forcedVideoCodec").getAsString());
Boolean allowTranscoding = responseJson.get("allowTranscoding").getAsBoolean(); Boolean allowTranscoding = responseJson.get("allowTranscoding").getAsBoolean();
SessionProperties responseProperties = new SessionProperties.Builder() SessionProperties responseProperties = new SessionProperties.Builder()
.customSessionId(properties.customSessionId()) .customSessionId(properties.customSessionId()).mediaMode(properties.mediaMode())
.mediaMode(properties.mediaMode())
.recordingMode(properties.recordingMode()) .recordingMode(properties.recordingMode())
.defaultOutputMode(properties.defaultOutputMode()) .defaultRecordingProperties(properties.defaultRecordingProperties())
.defaultRecordingLayout(properties.defaultRecordingLayout()) .mediaNode(properties.mediaNode()).forcedVideoCodec(forcedVideoCodec)
.defaultCustomLayout(properties.defaultCustomLayout()) .allowTranscoding(allowTranscoding).build();
.mediaNode(properties.mediaNode())
.forcedVideoCodec(forcedVideoCodec)
.allowTranscoding(allowTranscoding)
.build();
this.properties = responseProperties; this.properties = responseProperties;
log.info("Session '{}' created", this.sessionId); log.info("Session '{}' created", this.sessionId);
@ -734,13 +729,10 @@ public class Session {
this.recording = json.get("recording").getAsBoolean(); this.recording = json.get("recording").getAsBoolean();
SessionProperties.Builder builder = new SessionProperties.Builder() SessionProperties.Builder builder = new SessionProperties.Builder()
.mediaMode(MediaMode.valueOf(json.get("mediaMode").getAsString())) .mediaMode(MediaMode.valueOf(json.get("mediaMode").getAsString()))
.recordingMode(RecordingMode.valueOf(json.get("recordingMode").getAsString())) .recordingMode(RecordingMode.valueOf(json.get("recordingMode").getAsString()));
.defaultOutputMode(Recording.OutputMode.valueOf(json.get("defaultOutputMode").getAsString())); if (json.has("defaultRecordingProperties")) {
if (json.has("defaultRecordingLayout")) { builder.defaultRecordingProperties(
builder.defaultRecordingLayout(RecordingLayout.valueOf(json.get("defaultRecordingLayout").getAsString())); RecordingProperties.fromJson(json.get("defaultRecordingProperties").getAsJsonObject()));
}
if (json.has("defaultCustomLayout")) {
builder.defaultCustomLayout(json.get("defaultCustomLayout").getAsString());
} }
if (json.has("customSessionId")) { if (json.has("customSessionId")) {
builder.customSessionId(json.get("customSessionId").getAsString()); builder.customSessionId(json.get("customSessionId").getAsString());
@ -791,10 +783,10 @@ public class Session {
json.addProperty("recording", this.recording); json.addProperty("recording", this.recording);
json.addProperty("mediaMode", this.properties.mediaMode().name()); json.addProperty("mediaMode", this.properties.mediaMode().name());
json.addProperty("recordingMode", this.properties.recordingMode().name()); json.addProperty("recordingMode", this.properties.recordingMode().name());
json.addProperty("defaultOutputMode", this.properties.defaultOutputMode().name()); if (this.properties.defaultRecordingProperties() != null) {
json.addProperty("defaultRecordingLayout", this.properties.defaultRecordingLayout().name()); json.add("defaultRecordingProperties", this.properties.defaultRecordingProperties().toJson());
json.addProperty("defaultCustomLayout", this.properties.defaultCustomLayout()); }
if(this.properties.forcedVideoCodec() != null) { if (this.properties.forcedVideoCodec() != null) {
json.addProperty("forcedVideoCodec", this.properties.forcedVideoCodec().name()); json.addProperty("forcedVideoCodec", this.properties.forcedVideoCodec().name());
} }
if (this.properties.isTranscodingAllowed() != null) { if (this.properties.isTranscodingAllowed() != null) {

View File

@ -19,8 +19,6 @@ package io.openvidu.java.client;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.openvidu.java.client.Recording.OutputMode;
/** /**
* See {@link io.openvidu.java.client.OpenVidu#createSession(SessionProperties)} * See {@link io.openvidu.java.client.OpenVidu#createSession(SessionProperties)}
*/ */
@ -28,9 +26,7 @@ public class SessionProperties {
private MediaMode mediaMode; private MediaMode mediaMode;
private RecordingMode recordingMode; private RecordingMode recordingMode;
private OutputMode defaultOutputMode; private RecordingProperties defaultRecordingProperties;
private RecordingLayout defaultRecordingLayout;
private String defaultCustomLayout;
private String customSessionId; private String customSessionId;
private String mediaNode; private String mediaNode;
private VideoCodec forcedVideoCodec; private VideoCodec forcedVideoCodec;
@ -43,30 +39,26 @@ public class SessionProperties {
private MediaMode mediaMode = MediaMode.ROUTED; private MediaMode mediaMode = MediaMode.ROUTED;
private RecordingMode recordingMode = RecordingMode.MANUAL; private RecordingMode recordingMode = RecordingMode.MANUAL;
private OutputMode defaultOutputMode = OutputMode.COMPOSED; private RecordingProperties defaultRecordingProperties = new RecordingProperties.Builder().build();
private RecordingLayout defaultRecordingLayout = RecordingLayout.BEST_FIT;
private String defaultCustomLayout = "";
private String customSessionId = ""; private String customSessionId = "";
private String mediaNode; private String mediaNode;
private VideoCodec forcedVideoCodec; private VideoCodec forcedVideoCodec = VideoCodec.VP8;
private Boolean allowTranscoding; private Boolean allowTranscoding = false;
/** /**
* Returns the {@link io.openvidu.java.client.SessionProperties} object properly * Returns the {@link io.openvidu.java.client.SessionProperties} object properly
* configured * configured
*/ */
public SessionProperties build() { public SessionProperties build() {
return new SessionProperties(this.mediaMode, this.recordingMode, this.defaultOutputMode, return new SessionProperties(this.mediaMode, this.recordingMode, this.defaultRecordingProperties,
this.defaultRecordingLayout, this.defaultCustomLayout, this.customSessionId, this.mediaNode, this.customSessionId, this.mediaNode, this.forcedVideoCodec, this.allowTranscoding);
this.forcedVideoCodec, this.allowTranscoding);
} }
/** /**
* Call this method to set how the media streams will be sent and received by * Call this method to set how the media streams will be sent and received by
* your clients: routed through OpenVidu Media Node * your clients: routed through OpenVidu Media Node
* (<code>MediaMode.ROUTED</code>) or attempting direct p2p connections * (<code>MediaMode.ROUTED</code>) or attempting direct p2p connections
* (<code>MediaMode.RELAYED</code>, <i>not available yet</i>) * (<code>MediaMode.RELAYED</code>, <i>not available yet</i>)<br>
*
* Default value is <code>MediaMode.ROUTED</code> * Default value is <code>MediaMode.ROUTED</code>
*/ */
public SessionProperties.Builder mediaMode(MediaMode mediaMode) { public SessionProperties.Builder mediaMode(MediaMode mediaMode) {
@ -85,53 +77,14 @@ public class SessionProperties {
} }
/** /**
* Call this method to set the the default value used to initialize property * Call this method to set the default recording properties of this session. You
* {@link io.openvidu.java.client.RecordingProperties#outputMode()} of every * can easily override this value later when starting a
* recording of this session. You can easily override this value later when * {@link io.openvidu.java.client.Recording} by providing new
* starting a {@link io.openvidu.java.client.Recording} by calling * {@link RecordingProperties}<br>
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)} * Default values defined in {@link RecordingProperties} class.
* with any other value.<br>
* Default value is {@link Recording.OutputMode#COMPOSED}
*/ */
public SessionProperties.Builder defaultOutputMode(OutputMode outputMode) { public SessionProperties.Builder defaultRecordingProperties(RecordingProperties defaultRecordingProperties) {
this.defaultOutputMode = outputMode; this.defaultRecordingProperties = defaultRecordingProperties;
return this;
}
/**
* Call this method to set the the default value used to initialize property
* {@link io.openvidu.java.client.RecordingProperties#recordingLayout()} of
* every recording of this session. You can easily override this value later
* when starting a {@link io.openvidu.java.client.Recording} by calling
* {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)}
* with any other value.<br>
* Default value is {@link RecordingLayout#BEST_FIT}<br>
* <br>
* Recording layouts are only applicable to recordings with OutputMode
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
*/
public SessionProperties.Builder defaultRecordingLayout(RecordingLayout layout) {
this.defaultRecordingLayout = layout;
return this;
}
/**
* Call this method to set the default value used to initialize property
* {@link io.openvidu.java.client.RecordingProperties#customLayout()} of every
* recording of this session. You can easily override this value later when
* starting a {@link io.openvidu.java.client.Recording} by calling
* {@link io.openvidu.java.client.RecordingProperties.Builder#customLayout(String)}
* with any other value.<br>
* <br>
*
* Custom layouts are only applicable to recordings with OutputMode
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} (or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START})
* and RecordingLayout {@link io.openvidu.java.client.RecordingLayout#CUSTOM}
*/
public SessionProperties.Builder defaultCustomLayout(String path) {
this.defaultCustomLayout = path;
return this; return this;
} }
@ -161,12 +114,13 @@ public class SessionProperties {
} }
/** /**
* Call this method to define which video codec do you want to be forcibly used for this session. * Call this method to define which video codec do you want to be forcibly used
* This allows browsers/clients to use the same codec avoiding transcoding in the media server. * for this session. This allows browsers/clients to use the same codec avoiding
* If the browser/client is not compatible with the specified codec and {@link #allowTranscoding(Boolean)} * transcoding in the media server. If the browser/client is not compatible with
* is <code>false</code> and exception will occur. * the specified codec and {@link #allowTranscoding(Boolean)} is
* * <code>false</code> and exception will occur. If forcedVideoCodec is set to
* If forcedVideoCodec is set to NONE, no codec will be forced. * NONE, no codec will be forced.<br>
* Default value is {@link VideoCodec#VP8}
*/ */
public SessionProperties.Builder forcedVideoCodec(VideoCodec forcedVideoCodec) { public SessionProperties.Builder forcedVideoCodec(VideoCodec forcedVideoCodec) {
this.forcedVideoCodec = forcedVideoCodec; this.forcedVideoCodec = forcedVideoCodec;
@ -174,8 +128,10 @@ public class SessionProperties {
} }
/** /**
* Call this method to define if you want to allow transcoding in the media server or not * Call this method to define if you want to allow transcoding in the media
* when {@link #forcedVideoCodec(VideoCodec)} is not compatible with the browser/client. * server or not when {@link #forcedVideoCodec(VideoCodec)} is not compatible
* with the browser/client.<br>
* Default value is false
*/ */
public SessionProperties.Builder allowTranscoding(Boolean allowTranscoding) { public SessionProperties.Builder allowTranscoding(Boolean allowTranscoding) {
this.allowTranscoding = allowTranscoding; this.allowTranscoding = allowTranscoding;
@ -187,21 +143,17 @@ public class SessionProperties {
protected SessionProperties() { protected SessionProperties() {
this.mediaMode = MediaMode.ROUTED; this.mediaMode = MediaMode.ROUTED;
this.recordingMode = RecordingMode.MANUAL; this.recordingMode = RecordingMode.MANUAL;
this.defaultOutputMode = OutputMode.COMPOSED; this.defaultRecordingProperties = new RecordingProperties.Builder().build();
this.defaultRecordingLayout = RecordingLayout.BEST_FIT;
this.defaultCustomLayout = "";
this.customSessionId = ""; this.customSessionId = "";
this.mediaNode = ""; this.mediaNode = "";
} }
private SessionProperties(MediaMode mediaMode, RecordingMode recordingMode, OutputMode outputMode, private SessionProperties(MediaMode mediaMode, RecordingMode recordingMode,
RecordingLayout layout, String defaultCustomLayout, String customSessionId, String mediaNode, RecordingProperties defaultRecordingProperties, String customSessionId, String mediaNode,
VideoCodec forcedVideoCodec, Boolean allowTranscoding) { VideoCodec forcedVideoCodec, Boolean allowTranscoding) {
this.mediaMode = mediaMode; this.mediaMode = mediaMode;
this.recordingMode = recordingMode; this.recordingMode = recordingMode;
this.defaultOutputMode = outputMode; this.defaultRecordingProperties = defaultRecordingProperties;
this.defaultRecordingLayout = layout;
this.defaultCustomLayout = defaultCustomLayout;
this.customSessionId = customSessionId; this.customSessionId = customSessionId;
this.mediaNode = mediaNode; this.mediaNode = mediaNode;
this.forcedVideoCodec = forcedVideoCodec; this.forcedVideoCodec = forcedVideoCodec;
@ -227,46 +179,13 @@ public class SessionProperties {
} }
/** /**
* Defines the default value used to initialize property * Defines the default recording properties of this session. You can easily
* {@link io.openvidu.java.client.RecordingProperties#outputMode()} of every * override this value later when starting a
* recording of this session. You can easily override this value later when * {@link io.openvidu.java.client.Recording} by providing new
* starting a {@link io.openvidu.java.client.Recording} by calling * {@link RecordingProperties}
* {@link io.openvidu.java.client.RecordingProperties.Builder#outputMode(Recording.OutputMode)}
* with any other value
*/ */
public OutputMode defaultOutputMode() { public RecordingProperties defaultRecordingProperties() {
return this.defaultOutputMode; return this.defaultRecordingProperties;
}
/**
* Defines the default value used to initialize property
* {@link io.openvidu.java.client.RecordingProperties#recordingLayout()} of
* every recording of this session. You can easily override this value later
* when starting a {@link io.openvidu.java.client.Recording} by calling
* {@link io.openvidu.java.client.RecordingProperties.Builder#recordingLayout(RecordingLayout)}
* with any other value.<br>
* Recording layouts are only applicable to recordings with OutputMode
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START}
*/
public RecordingLayout defaultRecordingLayout() {
return this.defaultRecordingLayout;
}
/**
* Defines the default value used to initialize property
* {@link io.openvidu.java.client.RecordingProperties#customLayout()} of every
* recording of this session. You can easily override this value later when
* starting a {@link io.openvidu.java.client.Recording} by calling
* {@link io.openvidu.java.client.RecordingProperties.Builder#customLayout(String)}
* with any other value.<br>
* Custom layouts are only applicable to recordings with OutputMode
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED} (or
* {@link io.openvidu.java.client.Recording.OutputMode#COMPOSED_QUICK_START})
* and RecordingLayout {@link io.openvidu.java.client.RecordingLayout#CUSTOM}
*/
public String defaultCustomLayout() {
return this.defaultCustomLayout;
} }
/** /**
@ -301,8 +220,8 @@ public class SessionProperties {
} }
/** /**
* Defines if transcoding is allowed or not when {@link #forcedVideoCodec} * Defines if transcoding is allowed or not when {@link #forcedVideoCodec} is
* is not a compatible codec with the browser/client. * not a compatible codec with the browser/client.
*/ */
public Boolean isTranscodingAllowed() { public Boolean isTranscodingAllowed() {
return this.allowTranscoding; return this.allowTranscoding;
@ -312,10 +231,8 @@ public class SessionProperties {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();
json.addProperty("mediaMode", mediaMode().name()); json.addProperty("mediaMode", mediaMode().name());
json.addProperty("recordingMode", recordingMode().name()); json.addProperty("recordingMode", recordingMode().name());
json.addProperty("defaultOutputMode", defaultOutputMode().name());
json.addProperty("defaultRecordingLayout", defaultRecordingLayout().name());
json.addProperty("defaultCustomLayout", defaultCustomLayout());
json.addProperty("customSessionId", customSessionId()); json.addProperty("customSessionId", customSessionId());
json.add("defaultRecordingProperties", defaultRecordingProperties.toJson());
if (mediaNode() != null) { if (mediaNode() != null) {
JsonObject mediaNodeJson = new JsonObject(); JsonObject mediaNodeJson = new JsonObject();
mediaNodeJson.addProperty("id", mediaNode()); mediaNodeJson.addProperty("id", mediaNode());

View File

@ -84,7 +84,7 @@ export class Recording {
}; };
if (this.properties.outputMode.toString() === Recording.OutputMode[Recording.OutputMode.COMPOSED] 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.resolution = !!(json['resolution']) ? json['resolution'] : '1280x720';
this.properties.recordingLayout = !!(json['recordingLayout']) ? json['recordingLayout'] : RecordingLayout.BEST_FIT; this.properties.recordingLayout = !!(json['recordingLayout']) ? json['recordingLayout'] : RecordingLayout.BEST_FIT;
if (this.properties.recordingLayout.toString() === RecordingLayout[RecordingLayout.CUSTOM]) { if (this.properties.recordingLayout.toString() === RecordingLayout[RecordingLayout.CUSTOM]) {
this.properties.customLayout = json['customLayout']; this.properties.customLayout = json['customLayout'];

View File

@ -16,7 +16,7 @@
*/ */
/** /**
* See [[SessionProperties.defaultRecordingLayout]] and [[RecordingProperties.recordingLayout]] * See [[RecordingProperties.recordingLayout]]
*/ */
export enum RecordingLayout { export enum RecordingLayout {

View File

@ -32,45 +32,67 @@ export interface RecordingProperties {
/** /**
* The mode of recording: COMPOSED for a single archive in a grid layout or INDIVIDUAL for one archive for each stream * The mode of recording: COMPOSED for a single archive in a grid layout or INDIVIDUAL for one archive for each stream
*
* Default to [[Recording.OutputMode.COMPOSED]]
*/ */
outputMode?: Recording.OutputMode; outputMode?: Recording.OutputMode;
/** /**
* The layout to be used in the recording.<br> * The layout to be used in the recording.<br>
* Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` or `COMPOSED_QUICK_START` * Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` or `COMPOSED_QUICK_START`
*
* Default to [[RecordingLayout.BEST_FIT]]
*/ */
recordingLayout?: RecordingLayout; recordingLayout?: RecordingLayout;
/** /**
* The relative path to the specific custom layout you want to use.<br> * The relative path to the specific custom layout you want to use.<br>
* Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` (or `COMPOSED_QUICK_START`) and [[RecordingProperties.recordingLayout]] is `CUSTOM`<br> * Will only have effect if [[RecordingProperties.outputMode]] is `COMPOSED` (or `COMPOSED_QUICK_START`) and [[RecordingProperties.recordingLayout]] is `CUSTOM`<br>
* See [Custom recording layouts](/en/stable/advanced-features/recording#custom-recording-layouts) to learn more * See [Custom recording layouts](/en/stable/advanced-features/recording#custom-recording-layouts) to learn more.
*/ */
customLayout?: string; customLayout?: string;
/** /**
* Recording video file resolution. Must be a string with format "WIDTHxHEIGHT", * Recording video file resolution. Must be a string with format "WIDTHxHEIGHT",
* being both WIDTH and HEIGHT the number of pixels between 100 and 1999.<br> * being both WIDTH and HEIGHT the number of pixels between 100 and 1999.<br>
* Will only have effect if [[RecordingProperties.outputMode]] * Will only have effect if [[RecordingProperties.outputMode]] is set to [[Recording.OutputMode.COMPOSED]] or [[Recording.OutputMode.COMPOSED_QUICK_START]]
* is set to [[Recording.OutputMode.COMPOSED]] or [[Recording.OutputMode.COMPOSED_QUICK_START]]. * and [[RecordingProperties.hasVideo]] is set to true. For [[Recording.OutputMode.INDIVIDUAL]] all individual video files will have the native resolution of the published stream.
* For [[Recording.OutputMode.INDIVIDUAL]] all *
* individual video files will have the native resolution of the published stream * Default to "1280x720"
*/ */
resolution?: string; resolution?: string;
/**
* Recording video file frame rate.<br>
* Will only have effect if [[RecordingProperties.outputMode]]
* is set to [[Recording.OutputMode.COMPOSED]] or [[Recording.OutputMode.COMPOSED_QUICK_START]] and [[RecordingProperties.hasVideo]] is set to true.
* For [[Recording.OutputMode.INDIVIDUAL]] all individual video files will have the native frame rate of the published stream.
*
* Default to 25
*/
frameRate?: number;
/** /**
* Whether or not to record audio. Cannot be set to false at the same time as [[RecordingProperties.hasVideo]] * Whether or not to record audio. Cannot be set to false at the same time as [[RecordingProperties.hasVideo]]
*
* Default to true
*/ */
hasAudio?: boolean; hasAudio?: boolean;
/** /**
* Whether or not to record video. Cannot be set to false at the same time as [[RecordingProperties.hasAudio]] * Whether or not to record video. Cannot be set to false at the same time as [[RecordingProperties.hasAudio]]
*
* Default to true
*/ */
hasVideo?: boolean; hasVideo?: boolean;
/** /**
* If COMPOSED recording, the amount of shared memory reserved for the recording process in bytes. * The amount of shared memory reserved for the recording process in bytes.
* Minimum 134217728 (128MB). Property ignored if INDIVIDUAL recording. Default to 536870912 (512 MB) * Will only have effect if [[RecordingProperties.outputMode]] is set to [[Recording.OutputMode.COMPOSED]] or [[Recording.OutputMode.COMPOSED_QUICK_START]]
* and [[RecordingProperties.hasVideo]] is set to true. Property ignored for INDIVIDUAL recordings and audio-only recordings.
* Minimum 134217728 (128MB).
*
* Default to 536870912 (512 MB)
*/ */
shmSize?: number; shmSize?: number;

View File

@ -16,6 +16,7 @@
*/ */
import axios, { AxiosError } from 'axios'; import axios, { AxiosError } from 'axios';
import { VideoCodec } from './VideoCodec';
import { Connection } from './Connection'; import { Connection } from './Connection';
import { ConnectionProperties } from './ConnectionProperties'; import { ConnectionProperties } from './ConnectionProperties';
import { MediaMode } from './MediaMode'; import { MediaMode } from './MediaMode';
@ -90,12 +91,7 @@ export class Session {
// Empty parameter // Empty parameter
this.properties = {}; this.properties = {};
} }
this.properties.mediaMode = !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED; this.initDefaultSessionProperties();
this.properties.recordingMode = !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL;
this.properties.defaultOutputMode = !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED;
this.properties.defaultRecordingLayout = !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT;
this.properties.forcedVideoCodec = !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : undefined;
this.properties.allowTranscoding = this.properties.allowTranscoding != null ? this.properties.allowTranscoding : undefined;
} }
/** /**
@ -189,8 +185,8 @@ export class Session {
* *
* @returns A Promise that is resolved if the session has been closed successfully and rejected with an Error object if not * @returns A Promise that is resolved if the session has been closed successfully and rejected with an Error object if not
*/ */
public close(): Promise<any> { public close(): Promise<void> {
return new Promise<any>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
axios.delete( axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId, this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId,
{ {
@ -272,8 +268,8 @@ export class Session {
* *
* @returns A Promise that is resolved if the Connection was successfully removed from the Session and rejected with an Error object if not * @returns A Promise that is resolved if the Connection was successfully removed from the Session and rejected with an Error object if not
*/ */
public forceDisconnect(connection: string | Connection): Promise<any> { public forceDisconnect(connection: string | Connection): Promise<void> {
return new Promise<any>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId; const connectionId: string = typeof connection === 'string' ? connection : (<Connection>connection).connectionId;
axios.delete( axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId, this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/connection/' + connectionId,
@ -344,8 +340,8 @@ export class Session {
* *
* @returns A Promise that is resolved if the stream was successfully unpublished and rejected with an Error object if not * @returns A Promise that is resolved if the stream was successfully unpublished and rejected with an Error object if not
*/ */
public forceUnpublish(publisher: string | Publisher): Promise<any> { public forceUnpublish(publisher: string | Publisher): Promise<void> {
return new Promise<any>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId; const streamId: string = typeof publisher === 'string' ? publisher : (<Publisher>publisher).streamId;
axios.delete( axios.delete(
this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId, this.ov.host + OpenVidu.API_SESSIONS + '/' + this.sessionId + '/stream/' + streamId,
@ -466,20 +462,11 @@ export class Session {
resolve(this.sessionId); resolve(this.sessionId);
} }
const mediaMode = !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED; this.initDefaultSessionProperties();
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 mediaNode = !!this.properties.mediaNode ? this.properties.mediaNode : undefined;
const forcedVideoCodec = !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : undefined;
const allowTranscoding = this.properties.allowTranscoding != null ? this.properties.allowTranscoding : undefined;
const data = JSON.stringify({ const data = JSON.stringify(
mediaMode, recordingMode, defaultOutputMode, defaultRecordingLayout, defaultCustomLayout, this.properties
customSessionId, mediaNode, forcedVideoCodec, allowTranscoding );
});
axios.post( axios.post(
this.ov.host + OpenVidu.API_SESSIONS, this.ov.host + OpenVidu.API_SESSIONS,
@ -496,13 +483,11 @@ export class Session {
// SUCCESS response from openvidu-server. Resolve token // SUCCESS response from openvidu-server. Resolve token
this.sessionId = res.data.id; this.sessionId = res.data.id;
this.createdAt = res.data.createdAt; this.createdAt = res.data.createdAt;
this.properties.mediaMode = mediaMode; this.properties.mediaMode = res.data.mediaMode;
this.properties.recordingMode = recordingMode; this.properties.recordingMode = res.data.recordingMode;
this.properties.defaultOutputMode = defaultOutputMode; this.properties.defaultRecordingProperties = res.data.defaultRecordingProperties;
this.properties.defaultRecordingLayout = defaultRecordingLayout; this.properties.customSessionId = res.data.customSessionId;
this.properties.defaultCustomLayout = defaultCustomLayout; this.properties.mediaNode = res.data.mediaNode;
this.properties.customSessionId = customSessionId;
this.properties.mediaNode = mediaNode;
this.properties.forcedVideoCodec = res.data.forcedVideoCodec; this.properties.forcedVideoCodec = res.data.forcedVideoCodec;
this.properties.allowTranscoding = res.data.allowTranscoding; this.properties.allowTranscoding = res.data.allowTranscoding;
resolve(this.sessionId); resolve(this.sessionId);
@ -546,21 +531,17 @@ export class Session {
customSessionId: json.customSessionId, customSessionId: json.customSessionId,
mediaMode: json.mediaMode, mediaMode: json.mediaMode,
recordingMode: json.recordingMode, recordingMode: json.recordingMode,
defaultOutputMode: json.defaultOutputMode, defaultRecordingProperties: json.defaultRecordingProperties,
defaultRecordingLayout: json.defaultRecordingLayout,
defaultCustomLayout: json.defaultCustomLayout,
forcedVideoCodec: json.forcedVideoCodec, forcedVideoCodec: json.forcedVideoCodec,
allowTranscoding: json.allowTranscoding allowTranscoding: json.allowTranscoding
}; };
if (json.defaultRecordingLayout == null) { this.initDefaultSessionProperties();
delete this.properties.defaultRecordingLayout; if (json.defaultRecordingProperties == null) {
delete this.properties.defaultRecordingProperties;
} }
if (json.customSessionId == null) { if (json.customSessionId == null) {
delete this.properties.customSessionId; delete this.properties.customSessionId;
} }
if (json.defaultCustomLayout == null) {
delete this.properties.defaultCustomLayout;
}
if (json.mediaNode == null) { if (json.mediaNode == null) {
delete this.properties.mediaNode; delete this.properties.mediaNode;
} }
@ -668,4 +649,28 @@ export class Session {
} }
} }
/**
* @hidden
*/
private initDefaultSessionProperties() {
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,
mediaNode: this.properties.defaultRecordingProperties?.mediaNode
};
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;
this.properties.allowTranscoding = this.properties.allowTranscoding != null ? this.properties.allowTranscoding : false;
}
} }

View File

@ -16,9 +16,9 @@
*/ */
import { MediaMode } from './MediaMode'; import { MediaMode } from './MediaMode';
import { Recording } from './Recording'; import { RecordingProperties } from './RecordingProperties';
import { RecordingLayout } from './RecordingLayout';
import { RecordingMode } from './RecordingMode'; import { RecordingMode } from './RecordingMode';
import { VideoCodec } from './VideoCodec';
/** /**
* See [[OpenVidu.createSession]] * See [[OpenVidu.createSession]]
@ -28,35 +28,25 @@ export interface SessionProperties {
/** /**
* How the media streams will be sent and received by your clients: routed through OpenVidu Media Node * How the media streams will be sent and received by your clients: routed through OpenVidu Media Node
* (`MediaMode.ROUTED`) or attempting direct p2p connections (`MediaMode.RELAYED`, _not available yet_) * (`MediaMode.ROUTED`) or attempting direct p2p connections (`MediaMode.RELAYED`, _not available yet_)
*
* Default to [[MediaMode.ROUTED]]
*/ */
mediaMode?: MediaMode; mediaMode?: MediaMode;
/** /**
* Whether the Session will be automatically recorded (`RecordingMode.ALWAYS`) or not (`RecordingMode.MANUAL`) * Whether the Session will be automatically recorded (`RecordingMode.ALWAYS`) or not (`RecordingMode.MANUAL`)
*
* Default to [[RecordingMode.MANUAL]]
*/ */
recordingMode?: RecordingMode; recordingMode?: RecordingMode;
/** /**
* Default value used to initialize property [[RecordingProperties.outputMode]] of every recording of this session. * Default recording properties of this session. You can easily override this value later when starting a
* * [[Recording]] by providing new [[RecordingProperties]]
* You can easily override this value later by setting [[RecordingProperties.outputMode]] to any other value *
* Default values defined in [[RecordingProperties]] class
*/ */
defaultOutputMode?: Recording.OutputMode; defaultRecordingProperties?: RecordingProperties;
/**
* Default value used to initialize property [[RecordingProperties.recordingLayout]] of every recording of this session.
*
* You can easily override this value later by setting [[RecordingProperties.recordingLayout]] to any other value
*/
defaultRecordingLayout?: RecordingLayout;
/**
* Default value used to initialize property [[RecordingProperties.customLayout]] of every recording of this session.
* This property can only be defined if [[SessionProperties.defaultRecordingLayout]] is set to [[RecordingLayout.CUSTOM]].
*
* You can easily override this value later by setting [[RecordingProperties.customLayout]] to any other value
*/
defaultCustomLayout?: string;
/** /**
* Fix the sessionId that will be assigned to the session with this parameter. You can take advantage of this property * Fix the sessionId that will be assigned to the session with this parameter. You can take advantage of this property
@ -79,16 +69,18 @@ export interface SessionProperties {
/** /**
* It defines which video codec do you want to be forcibly used for this session. * It defines which video codec do you want to be forcibly used for this session.
* This allows browsers/clients to use the same codec avoiding transcoding in the media server. * This allows browsers/clients to use the same codec avoiding transcoding in the media server.
* If the browser/client is not compatible with the specified codec and [[allowTranscoding]] * If the browser/client is not compatible with the specified codec and [[allowTranscoding]] is <code>false</code>
* is <code>false</code> and exception will occur. * and exception will occur. If forcedVideoCodec is set to [[VideoCodec.NONE]], no codec will be forced.
* *
* If forcedVideoCodec is set to NONE, no codec will be forced. * Default to [[VideoCodec.VP8]]
*/ */
forcedVideoCodec?: string; forcedVideoCodec?: VideoCodec;
/** /**
* It defines if you want to allow transcoding in the media server or not * It defines if you want to allow transcoding in the media server or not
* when [[forcedVideoCodec]] is not compatible with the browser/client. * when [[forcedVideoCodec]] is not compatible with the browser/client.
*
* Default to false
*/ */
allowTranscoding?: boolean; allowTranscoding?: boolean;