Change POST /api/sessions to return all session information, fixed default parameters in session object on clients and fixed recorder

pull/600/head
cruizba 2020-09-10 11:07:43 +02:00
parent 253ba9e80f
commit 32f63f50a3
6 changed files with 49 additions and 27 deletions

View File

@ -142,7 +142,7 @@ export class Connection {
}; };
// TODO: CLEAN 2.15.0 LEGACY CODE // TODO: CLEAN 2.15.0 LEGACY CODE
// THIS LINE: // THIS LINE:
const stream = this.session.openvidu.openviduServerVersion.startsWith('2.16') ? new Stream(this.session, streamOptions) : new StreamLEGACY(this.session, streamOptions); const stream = (this.session.openvidu.recorder || this.session.openvidu.openviduServerVersion.startsWith('2.16')) ? new Stream(this.session, streamOptions) : new StreamLEGACY(this.session, streamOptions);
// SHOULD GET BACK TO: // SHOULD GET BACK TO:
// const stream = new Stream(this.session, streamOptions); // const stream = new Stream(this.session, streamOptions);

View File

@ -54,14 +54,14 @@ public class Session {
protected Session(OpenVidu openVidu) throws OpenViduJavaClientException, OpenViduHttpException { protected Session(OpenVidu openVidu) throws OpenViduJavaClientException, OpenViduHttpException {
this.openVidu = openVidu; this.openVidu = openVidu;
this.properties = new SessionProperties.Builder().build(); this.properties = new SessionProperties.Builder().build();
this.getSessionIdHttp(); this.getSessionHttp();
} }
protected Session(OpenVidu openVidu, SessionProperties properties) protected Session(OpenVidu openVidu, SessionProperties properties)
throws OpenViduJavaClientException, OpenViduHttpException { throws OpenViduJavaClientException, OpenViduHttpException {
this.openVidu = openVidu; this.openVidu = openVidu;
this.properties = properties; this.properties = properties;
this.getSessionIdHttp(); this.getSessionHttp();
} }
protected Session(OpenVidu openVidu, JsonObject json) { protected Session(OpenVidu openVidu, JsonObject json) {
@ -444,7 +444,7 @@ public class Session {
return (this.sessionId != null && !this.sessionId.isEmpty()); return (this.sessionId != null && !this.sessionId.isEmpty());
} }
private void getSessionIdHttp() throws OpenViduJavaClientException, OpenViduHttpException { private void getSessionHttp() throws OpenViduJavaClientException, OpenViduHttpException {
if (this.hasSessionId()) { if (this.hasSessionId()) {
return; return;
} }
@ -458,6 +458,9 @@ public class Session {
json.addProperty("defaultRecordingLayout", properties.defaultRecordingLayout().name()); json.addProperty("defaultRecordingLayout", properties.defaultRecordingLayout().name());
json.addProperty("defaultCustomLayout", properties.defaultCustomLayout()); json.addProperty("defaultCustomLayout", properties.defaultCustomLayout());
json.addProperty("customSessionId", properties.customSessionId()); json.addProperty("customSessionId", properties.customSessionId());
// forcedVideoCodec codec and allowTranscoding could be null because
// both default values are loaded by openvidu server
if (properties.forcedVideoCodec() != null) { if (properties.forcedVideoCodec() != null) {
json.addProperty("forcedVideoCodec", properties.forcedVideoCodec().name()); json.addProperty("forcedVideoCodec", properties.forcedVideoCodec().name());
} }
@ -487,6 +490,20 @@ public class Session {
JsonObject responseJson = httpResponseToJson(response); JsonObject responseJson = httpResponseToJson(response);
this.sessionId = responseJson.get("id").getAsString(); this.sessionId = responseJson.get("id").getAsString();
this.createdAt = responseJson.get("createdAt").getAsLong(); this.createdAt = responseJson.get("createdAt").getAsLong();
VideoCodec forcedVideoCodec = VideoCodec.valueOf(responseJson.get("forcedVideoCodec").getAsString());
Boolean allowTranscoding = responseJson.get("allowTranscoding").getAsBoolean();
SessionProperties responseProperties = new SessionProperties.Builder()
.mediaMode(properties.mediaMode())
.recordingMode(properties.recordingMode())
.defaultOutputMode(properties.defaultOutputMode())
.defaultRecordingLayout(properties.defaultRecordingLayout())
.defaultCustomLayout(properties.defaultCustomLayout())
.forcedVideoCodec(forcedVideoCodec)
.allowTranscoding(allowTranscoding)
.build();
this.properties = responseProperties;
log.info("Session '{}' created", this.sessionId); log.info("Session '{}' created", this.sessionId);
} else if (statusCode == org.apache.http.HttpStatus.SC_CONFLICT) { } else if (statusCode == org.apache.http.HttpStatus.SC_CONFLICT) {
// 'customSessionId' already existed // 'customSessionId' already existed

View File

@ -99,8 +99,8 @@ export class OpenVidu {
public createSession(properties?: SessionProperties): Promise<Session> { public createSession(properties?: SessionProperties): Promise<Session> {
return new Promise<Session>((resolve, reject) => { return new Promise<Session>((resolve, reject) => {
const session = new Session(this, properties); const session = new Session(this, properties);
session.getSessionIdHttp() session.getSessionHttp()
.then(sessionId => { .then(response => {
this.activeSessions.push(session); this.activeSessions.push(session);
resolve(session); resolve(session);
}) })

View File

@ -391,23 +391,25 @@ export class Session {
/** /**
* @hidden * @hidden
*/ */
public getSessionIdHttp(): Promise<string> { public getSessionHttp(): Promise<string> {
return new Promise<string>((resolve, reject) => { return new Promise<string>((resolve, reject) => {
if (!!this.sessionId) { if (!!this.sessionId) {
resolve(this.sessionId); resolve(this.sessionId);
} }
const data = JSON.stringify({ const mediaMode = !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED;
mediaMode: !!this.properties.mediaMode ? this.properties.mediaMode : MediaMode.ROUTED, const recordingMode = !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL;
recordingMode: !!this.properties.recordingMode ? this.properties.recordingMode : RecordingMode.MANUAL, const defaultOutputMode = !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED;
defaultOutputMode: !!this.properties.defaultOutputMode ? this.properties.defaultOutputMode : Recording.OutputMode.COMPOSED, const defaultRecordingLayout = !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT;
defaultRecordingLayout: !!this.properties.defaultRecordingLayout ? this.properties.defaultRecordingLayout : RecordingLayout.BEST_FIT, const defaultCustomLayout = !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : '';
defaultCustomLayout: !!this.properties.defaultCustomLayout ? this.properties.defaultCustomLayout : '', const customSessionId = !!this.properties.customSessionId ? this.properties.customSessionId : '';
customSessionId: !!this.properties.customSessionId ? this.properties.customSessionId : '', const forcedVideoCodec = !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : null;
forcedVideoCodec: !!this.properties.forcedVideoCodec ? this.properties.forcedVideoCodec : null, const allowTranscoding = !!this.properties.allowTranscoding ? this.properties.allowTranscoding : null;
allowTranscoding: !!this.properties.allowTranscoding ? this.properties.allowTranscoding : null
const data = JSON.stringify({ mediaMode, recordingMode,
defaultOutputMode, defaultRecordingLayout, defaultCustomLayout,
customSessionId, forcedVideoCodec, allowTranscoding
}); });
axios.post( axios.post(
@ -425,6 +427,13 @@ 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.recordingMode = recordingMode;
this.properties.defaultOutputMode = defaultOutputMode;
this.properties.defaultRecordingLayout = defaultRecordingLayout;
this.properties.customSessionId = customSessionId;
this.properties.forcedVideoCodec = res.data.forcedVideoCodec;
this.properties.allowTranscoding = res.data.allowTranscoding;
resolve(this.sessionId); resolve(this.sessionId);
} else { } else {
// ERROR response from openvidu-server. Resolve HTTP status // ERROR response from openvidu-server. Resolve HTTP status

View File

@ -190,10 +190,9 @@ public class SessionRestController {
Session sessionNotActive = sessionManager.storeSessionNotActive(sessionId, sessionProperties); Session sessionNotActive = sessionManager.storeSessionNotActive(sessionId, sessionProperties);
log.info("New session {} initialized {}", sessionId, this.sessionManager.getSessionsWithNotActive().stream() log.info("New session {} initialized {}", sessionId, this.sessionManager.getSessionsWithNotActive().stream()
.map(Session::getSessionId).collect(Collectors.toList()).toString()); .map(Session::getSessionId).collect(Collectors.toList()).toString());
JsonObject responseJson = new JsonObject(); JsonObject responseJson = sessionNotActive.toJson();
responseJson.remove("sessionId");
responseJson.addProperty("id", sessionNotActive.getSessionId()); responseJson.addProperty("id", sessionNotActive.getSessionId());
responseJson.addProperty("createdAt", sessionNotActive.getStartTime());
return new ResponseEntity<>(responseJson.toString(), getResponseHeaders(), HttpStatus.OK); return new ResponseEntity<>(responseJson.toString(), getResponseHeaders(), HttpStatus.OK);
} }

View File

@ -2162,13 +2162,10 @@ public class OpenViduTestAppE2eTest {
SessionProperties properties = new SessionProperties.Builder().customSessionId(customSessionId) SessionProperties properties = new SessionProperties.Builder().customSessionId(customSessionId)
.mediaMode(MediaMode.ROUTED).recordingMode(RecordingMode.ALWAYS) .mediaMode(MediaMode.ROUTED).recordingMode(RecordingMode.ALWAYS)
.defaultOutputMode(OutputMode.INDIVIDUAL) .defaultOutputMode(OutputMode.INDIVIDUAL).build();
.forcedVideoCodec(VideoCodec.VP8)
.allowTranscoding(false)
.build();
Session session = OV.createSession(properties); Session session = OV.createSession(properties);
Assert.assertFalse("Session.fetch() should return true after OpenVidu.createSession() because some default properties are created in the server", session.fetch()); Assert.assertFalse("Session.fetch() should return false after OpenVidu.createSession()", session.fetch());
Assert.assertFalse("OpenVidu.fetch() should return false after OpenVidu.createSession()", OV.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false after OpenVidu.createSession()", OV.fetch());
sessions = OV.getActiveSessions(); sessions = OV.getActiveSessions();
Assert.assertEquals("Expected 1 active session but found " + sessions.size(), 1, sessions.size()); Assert.assertEquals("Expected 1 active session but found " + sessions.size(), 1, sessions.size());
@ -2357,7 +2354,7 @@ public class OpenViduTestAppE2eTest {
Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus()); Assert.assertEquals("Wrong HTTP status on OpenVidu.startRecording()", 404, e.getStatus());
} }
Session sessionAux = OV.createSession(); Session sessionAux = OV.createSession();
Assert.assertTrue("OpenVidu.fetch() should return true", OV.fetch()); Assert.assertFalse("OpenVidu.fetch() should return false", OV.fetch());
try { try {
OV.startRecording(sessionAux.getSessionId()); OV.startRecording(sessionAux.getSessionId());
} catch (OpenViduHttpException e) { } catch (OpenViduHttpException e) {
@ -2452,7 +2449,7 @@ public class OpenViduTestAppE2eTest {
OV.deleteRecording(recording2.getId()); OV.deleteRecording(recording2.getId());
recording2 = OV.startRecording(session.getSessionId(), recordingProperties); recording2 = OV.startRecording(session.getSessionId(), recordingProperties);
user.getEventManager().waitUntilEventReaches("recordingStarted", 2); // user.getEventManager().waitUntilEventReaches("recordingStarted", 2);
Assert.assertEquals("Wrong recording name", customRecordingName, recording2.getName()); Assert.assertEquals("Wrong recording name", customRecordingName, recording2.getName());
Assert.assertEquals("Wrong recording id", session.getSessionId() + "-1", recording2.getId()); Assert.assertEquals("Wrong recording id", session.getSessionId() + "-1", recording2.getId());