SDKs: fetch remote session on createSession 409

pull/707/head
pabloFuente 2022-03-11 13:44:27 +01:00
parent defba84160
commit 918ef299ae
5 changed files with 103 additions and 244 deletions

View File

@ -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()}
* <ul>
* <li><code>409</code>: you are trying to
* assign an already-in-use custom sessionId
* to the session. See
* {@link io.openvidu.java.client.SessionProperties#customSessionId()}</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#post-session">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no session exists
* for the passed <i>sessionId</i></li>
* <li><code>406</code>: the session has no
* connected participants</li>
* <li><code>422</code>: "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</li>
* <li><code>409</code>: the session is not
* configured for using
* {@link io.openvidu.java.client.MediaMode#ROUTED}
* or it is already being recorded</li>
* <li><code>501</code>: OpenVidu Server
* recording module is disabled
* (<i>OPENVIDU_RECORDING</i> property set
* to <i>false</i>)</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#post-recording-start">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no session exists
* for the passed <i>sessionId</i></li>
* <li><code>406</code>: the session has no
* connected participants</li>
* <li><code>422</code>: "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</li>
* <li><code>409</code>: the session is not
* configured for using
* {@link io.openvidu.java.client.MediaMode#ROUTED}
* or it is already being recorded</li>
* <li><code>501</code>: OpenVidu Server
* recording module is disabled
* (<i>OPENVIDU_RECORDING</i> property set
* to <i>false</i>)</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#post-recording-start">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no session exists
* for the passed <i>sessionId</i></li>
* <li><code>406</code>: the session has no
* connected participants</li>
* <li><code>422</code>: "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</li>
* <li><code>409</code>: the session is not
* configured for using
* {@link io.openvidu.java.client.MediaMode#ROUTED}
* or it is already being recorded</li>
* <li><code>501</code>: OpenVidu Server
* recording module is disabled
* (<i>OPENVIDU_RECORDING</i> property set
* to <i>false</i>)</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#post-recording-start">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no recording exists
* for the passed <i>recordingId</i></li>
* <li><code>406</code>: recording has
* <i>starting</i> status. Wait until
* <i>started</i> status before stopping the
* recording</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#post-recording-stop">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no recording exists
* for the passed <i>recordingId</i></li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#get-recording">REST
* API</a>)
*/
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()}
* <ul>
* <li><code>404</code>: no recording exists
* for the passed <i>recordingId</i></li>
* <li><code>409</code>: the recording has
* <i>started</i> status. Stop it before
* deletion</li>
* </ul>
* (see <a href=
* "/en/stable/reference-docs/REST-API/#delete-recording">REST
* API</a>)
*/
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</li>
* <li>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</li>
* <li>Calling
* {@link io.openvidu.java.client.Session#updateConnection(String, ConnectionProperties)}
* automatically updates the inner affected connection for that specific
* Session</li>
* <li>Calling {@link io.openvidu.java.client.OpenVidu#startRecording(String)}
* and {@link io.openvidu.java.client.OpenVidu#stopRecording(String)}

View File

@ -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/
* <a href="/en/stable/reference-docs/REST-API">REST API docs</a>
*/
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
* <a href="/en/stable/reference-docs/REST-API">REST API docs</a>
*/
public int getStatus() {
return this.status;

View File

@ -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);
}

View File

@ -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<Recording> {
return new Promise<Recording>((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<Recording> {
return new Promise<Recording>((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<Recording> {
return new Promise<Recording>((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<Error> {
return new Promise<Error>((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));
}
}
}

View File

@ -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) {
if (!!error.response && error.response.status === 409) {
// 'customSessionId' already existed
this.sessionId = this.properties.customSessionId;
resolve(this.sessionId);
this.fetch().then(() => 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));
} else {
// Something happened in setting up the request that triggered an Error
reject(new Error(error.message));
this.ov.handleError(error, reject);
}
});
});
@ -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
*/