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 c5a326b1..295545e7 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
@@ -142,14 +142,12 @@ public class OpenVidu {
* @return The created session
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 409
: you are trying to
- * assign an already-in-use custom sessionId
- * to the session. See
- * {@link io.openvidu.java.client.SessionProperties#customSessionId()}
- *
+ * (see REST
+ * API)
*/
public Session createSession(SessionProperties properties)
throws OpenViduJavaClientException, OpenViduHttpException {
@@ -167,28 +165,12 @@ public class OpenVidu {
* @return The new created session
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no session exists
- * for the passed sessionId
- * 406
: the session has no
- * connected participants
- * 422
: "resolution"
- * parameter exceeds acceptable values (for
- * both width and height, min 100px and max
- * 1999px) or trying to start a recording
- * with both "hasAudio" and "hasVideo" to
- * false
- * 409
: the session is not
- * configured for using
- * {@link io.openvidu.java.client.MediaMode#ROUTED}
- * or it is already being recorded
- * 501
: OpenVidu Server
- * recording module is disabled
- * (OPENVIDU_RECORDING property set
- * to false)
- *
+ * (see REST
+ * API)
*/
public Recording startRecording(String sessionId, RecordingProperties properties)
throws OpenViduJavaClientException, OpenViduHttpException {
@@ -246,28 +228,12 @@ public class OpenVidu {
* guarantees
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no session exists
- * for the passed sessionId
- * 406
: the session has no
- * connected participants
- * 422
: "resolution"
- * parameter exceeds acceptable values (for
- * both width and height, min 100px and max
- * 1999px) or trying to start a recording
- * with both "hasAudio" and "hasVideo" to
- * false
- * 409
: the session is not
- * configured for using
- * {@link io.openvidu.java.client.MediaMode#ROUTED}
- * or it is already being recorded
- * 501
: OpenVidu Server
- * recording module is disabled
- * (OPENVIDU_RECORDING property set
- * to false)
- *
+ * (see REST
+ * API)
*/
public Recording startRecording(String sessionId, String name)
throws OpenViduJavaClientException, OpenViduHttpException {
@@ -287,28 +253,12 @@ public class OpenVidu {
* guarantees
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no session exists
- * for the passed sessionId
- * 406
: the session has no
- * connected participants
- * 422
: "resolution"
- * parameter exceeds acceptable values (for
- * both width and height, min 100px and max
- * 1999px) or trying to start a recording
- * with both "hasAudio" and "hasVideo" to
- * false
- * 409
: the session is not
- * configured for using
- * {@link io.openvidu.java.client.MediaMode#ROUTED}
- * or it is already being recorded
- * 501
: OpenVidu Server
- * recording module is disabled
- * (OPENVIDU_RECORDING property set
- * to false)
- *
+ * (see REST
+ * API)
*/
public Recording startRecording(String sessionId) throws OpenViduJavaClientException, OpenViduHttpException {
return this.startRecording(sessionId, "");
@@ -322,16 +272,12 @@ public class OpenVidu {
* @return The stopped recording
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no recording exists
- * for the passed recordingId
- * 406
: recording has
- * starting status. Wait until
- * started status before stopping the
- * recording
- *
+ * (see REST
+ * API)
*/
public Recording stopRecording(String recordingId) throws OpenViduJavaClientException, OpenViduHttpException {
HttpPost request = new HttpPost(this.hostname + API_RECORDINGS_STOP + "/" + recordingId);
@@ -369,12 +315,12 @@ public class OpenVidu {
* @param recordingId The id property of the recording you want to retrieve
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no recording exists
- * for the passed recordingId
- *
+ * (see REST
+ * API)
*/
public Recording getRecording(String recordingId) throws OpenViduJavaClientException, OpenViduHttpException {
HttpGet request = new HttpGet(this.hostname + API_RECORDINGS + "/" + recordingId);
@@ -443,15 +389,12 @@ public class OpenVidu {
* @param recordingId The id property of the recording you want to delete
*
* @throws OpenViduJavaClientException
- * @throws OpenViduHttpException Value returned from
+ * @throws OpenViduHttpException The status code carries a specific
+ * meaning
* {@link io.openvidu.java.client.OpenViduHttpException#getStatus()}
- *
- * 404
: no recording exists
- * for the passed recordingId
- * 409
: the recording has
- * started status. Stop it before
- * deletion
- *
+ * (see REST
+ * API)
*/
public void deleteRecording(String recordingId) throws OpenViduJavaClientException, OpenViduHttpException {
HttpDelete request = new HttpDelete(this.hostname + API_RECORDINGS + "/" + recordingId);
@@ -491,7 +434,11 @@ public class OpenVidu {
* automatically updates the inner affected connections for that specific
* Session
* Calling {@link io.openvidu.java.client.Session#forceUnpublish(Publisher)}
- * also automatically updates the inner affected connections for that specific
+ * automatically updates the inner affected connections for that specific
+ * Session
+ * Calling
+ * {@link io.openvidu.java.client.Session#updateConnection(String, ConnectionProperties)}
+ * automatically updates the inner affected connection for that specific
* Session
* Calling {@link io.openvidu.java.client.OpenVidu#startRecording(String)}
* and {@link io.openvidu.java.client.OpenVidu#stopRecording(String)}
diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenViduHttpException.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenViduHttpException.java
index 2aef5b87..85027aa9 100644
--- a/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenViduHttpException.java
+++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/OpenViduHttpException.java
@@ -19,7 +19,7 @@ package io.openvidu.java.client;
/**
* Defines error responses from OpenVidu Server. See error codes at
- * https://docs.openvidu.io/en/stable/reference-docs/REST-API/
+ * REST API docs
*/
public class OpenViduHttpException extends OpenViduException {
@@ -32,7 +32,8 @@ public class OpenViduHttpException extends OpenViduException {
}
/**
- * @return The unexpected status of the HTTP request
+ * @return The unexpected status of the HTTP request. See error codes meaning at
+ * REST API docs
*/
public int getStatus() {
return this.status;
diff --git a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java
index 1fa46ad6..388fce61 100644
--- a/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java
+++ b/openvidu-java-client/src/main/java/io/openvidu/java/client/Session.java
@@ -480,7 +480,7 @@ public class Session {
*
* The affected client will trigger one
- * ConnectionPropertyChangedEvent for each modified property.
+ * ConnectionPropertyChangedEvent for each modified property.
*
* @param connectionId The Connection to modify
* @param connectionProperties A ConnectionProperties object with the new values
@@ -678,6 +678,10 @@ public class Session {
this.properties = responseProperties;
log.info("Session '{}' created", this.sessionId);
+ } else if (statusCode == org.apache.http.HttpStatus.SC_CONFLICT) {
+ // 'customSessionId' already existed
+ this.sessionId = properties.customSessionId();
+ this.fetch();
} else {
throw new OpenViduHttpException(statusCode);
}
diff --git a/openvidu-node-client/src/OpenVidu.ts b/openvidu-node-client/src/OpenVidu.ts
index b29aaad5..09131f52 100644
--- a/openvidu-node-client/src/OpenVidu.ts
+++ b/openvidu-node-client/src/OpenVidu.ts
@@ -15,13 +15,12 @@
*
*/
-import axios from 'axios';
+import axios, { AxiosError } from 'axios';
import { Connection } from './Connection';
import { Recording } from './Recording';
import { RecordingProperties } from './RecordingProperties';
import { Session } from './Session';
import { SessionProperties } from './SessionProperties';
-import { RecordingLayout } from './RecordingLayout';
/**
* @hidden
@@ -79,8 +78,8 @@ export class OpenVidu {
* - Calling [[Session.close]] automatically removes the Session from the list of active Sessions
* - Calling [[Session.forceDisconnect]] automatically updates the inner affected connections for that specific Session
* - Calling [[Session.forceUnpublish]] also automatically updates the inner affected connections for that specific Session
- * - Calling [[OpenVidu.startRecording]] and [[OpenVidu.stopRecording]] automatically updates the recording status of the
- * Session ([[Session.recording]])
+ * - Calling [[Session.updateConnection]] automatically updates the inner affected connection for that specific Session
+ * - Calling [[OpenVidu.startRecording]] and [[OpenVidu.stopRecording]] automatically updates the recording status of the Session ([[Session.recording]])
*
* To get the array of active sessions with their current actual value, you must call [[OpenVidu.fetch]] before consulting
* property [[activeSessions]]
@@ -129,13 +128,8 @@ export class OpenVidu {
* @param properties Custom RecordingProperties to apply to this Recording. This will override the global default values set to the Session with [[SessionProperties.defaultRecordingProperties]]
*
* @returns A Promise that is resolved to the [[Recording]] if it successfully started (the recording can be stopped with guarantees) and rejected with an Error
- * object if not. This Error object has as `message` property with the following values:
- * - `404`: no session exists for the passed `sessionId`
- * - `406`: the session has no connected participants
- * - `422`: when passing [[RecordingProperties]], `resolution` parameter exceeds acceptable values (for both width and height, min 100px and max 1999px) or trying
- * to start a recording with both `hasAudio` and `hasVideo` to false
- * - `409`: the session is not configured for using [[MediaMode.ROUTED]] or it is already being recorded
- * - `501`: OpenVidu Server recording module is disabled (`OPENVIDU_RECORDING` property set to `false`)
+ * object if not. This Error object has as `message` property with a status code with a specific meaning
+ * (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-start)).
*/
public startRecording(sessionId: string, param2?: string | RecordingProperties): Promise {
return new Promise((resolve, reject) => {
@@ -199,18 +193,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(error.request);
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(error.message);
- }
+ this.handleError(error, reject);
});
});
}
@@ -220,9 +203,9 @@ export class OpenVidu {
*
* @param recordingId The `id` property of the [[Recording]] you want to stop
*
- * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not. This Error object has as `message` property with the following values:
- * - `404`: no recording exists for the passed `recordingId`
- * - `406`: recording has `starting` status. Wait until `started` status before stopping the recording
+ * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not.
+ * This Error object has as `message` property with a status code with a specific meaning
+ * (see [REST API](/en/stable/reference-docs/REST-API/#post-recording-stop)).
*/
public stopRecording(recordingId: string): Promise {
return new Promise((resolve, reject) => {
@@ -253,17 +236,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received `error.request` is an instance of XMLHttpRequest
- // in the browser and an instance of http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -273,8 +246,9 @@ export class OpenVidu {
*
* @param recordingId The `id` property of the [[Recording]] you want to retrieve
*
- * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not. This Error object has as `message` property with the following values:
- * - `404`: no recording exists for the passed `recordingId`
+ * @returns A Promise that is resolved to the [[Recording]] if it successfully stopped and rejected with an Error object if not.
+ * This Error object has as `message` property with a status code with a specific meaning
+ * (see [REST API](/en/stable/reference-docs/REST-API/#get-recording)).
*/
public getRecording(recordingId: string): Promise {
return new Promise((resolve, reject) => {
@@ -297,18 +271,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -345,18 +308,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -366,9 +318,9 @@ export class OpenVidu {
*
* @param recordingId
*
- * @returns A Promise that is resolved if the Recording was successfully deleted and rejected with an Error object if not. This Error object has as `message` property with the following values:
- * - `404`: no recording exists for the passed `recordingId`
- * - `409`: the recording has `started` status. Stop it before deletion
+ * @returns A Promise that is resolved if the Recording was successfully deleted and rejected with an Error object if not.
+ * This Error object has as `message` property with a status code with a specific meaning
+ * (see [REST API](/en/stable/reference-docs/REST-API/#delete-recording)).
*/
public deleteRecording(recordingId: string): Promise {
return new Promise((resolve, reject) => {
@@ -391,18 +343,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -472,18 +413,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(error);
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -640,18 +570,7 @@ export class OpenVidu {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
+ this.handleError(error, reject);
});
});
}
@@ -671,4 +590,22 @@ export class OpenVidu {
this.host = url.protocol + '//' + url.host;
}
+ /**
+ * @hidden
+ */
+ handleError(error: AxiosError, reject: (reason?: any) => void) {
+ if (error.response) {
+ // The request was made and the server responded with a status code (not 2xx)
+ reject(new Error(error.response.status.toString()));
+ } else if (error.request) {
+ // The request was made but no response was received
+ // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
+ // http.ClientRequest in node.js
+ reject(new Error(error.request));
+ } else {
+ // Something happened in setting up the request that triggered an Error
+ reject(new Error(error.message));
+ }
+ }
+
}
diff --git a/openvidu-node-client/src/Session.ts b/openvidu-node-client/src/Session.ts
index 8a2484d5..9895008b 100644
--- a/openvidu-node-client/src/Session.ts
+++ b/openvidu-node-client/src/Session.ts
@@ -16,7 +16,6 @@
*/
import axios, { AxiosError } from 'axios';
-import { VideoCodec } from './VideoCodec';
import { Connection } from './Connection';
import { ConnectionProperties } from './ConnectionProperties';
import { MediaMode } from './MediaMode';
@@ -128,7 +127,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -178,7 +177,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -210,7 +209,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -250,7 +249,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -324,7 +323,7 @@ export class Session {
}
})
.catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -382,7 +381,7 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -443,7 +442,7 @@ export class Session {
resolve(existingConnection);
}
}).catch(error => {
- this.handleError(error, reject);
+ this.ov.handleError(error, reject);
});
});
}
@@ -501,23 +500,12 @@ export class Session {
reject(new Error(res.status.toString()));
}
}).catch(error => {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- if (error.response.status === 409) {
- // 'customSessionId' already existed
- this.sessionId = this.properties.customSessionId;
- resolve(this.sessionId);
- } else {
- reject(new Error(error.response.status.toString()));
- }
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
+ if (!!error.response && error.response.status === 409) {
+ // 'customSessionId' already existed
+ this.sessionId = this.properties.customSessionId;
+ this.fetch().then(() => resolve(this.sessionId));
} else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
+ this.ov.handleError(error, reject);
}
});
});
@@ -589,10 +577,10 @@ export class Session {
this.connections.forEach(connection => {
if (connection.connectionProperties.customIceServers != null &&
connection.connectionProperties.customIceServers.length > 0) {
- // Order alphabetically Ice servers using url just to keep the same list order.
- const simpleIceComparator = (a: IceServerProperties, b: IceServerProperties) => (a.url > b.url) ? 1 : -1
- connection.connectionProperties.customIceServers.sort(simpleIceComparator);
- }
+ // Order alphabetically Ice servers using url just to keep the same list order.
+ const simpleIceComparator = (a: IceServerProperties, b: IceServerProperties) => (a.url > b.url) ? 1 : -1
+ connection.connectionProperties.customIceServers.sort(simpleIceComparator);
+ }
});
// Populate activeConnections array
this.updateActiveConnectionsArray();
@@ -645,24 +633,6 @@ export class Session {
});
}
- /**
- * @hidden
- */
- private handleError(error: AxiosError, reject: (reason?: any) => void) {
- if (error.response) {
- // The request was made and the server responded with a status code (not 2xx)
- reject(new Error(error.response.status.toString()));
- } else if (error.request) {
- // The request was made but no response was received
- // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
- // http.ClientRequest in node.js
- reject(new Error(error.request));
- } else {
- // Something happened in setting up the request that triggered an Error
- reject(new Error(error.message));
- }
- }
-
/**
* @hidden
*/