mirror of https://github.com/OpenVidu/openvidu.git
openvidu-java-client updated to recording
parent
4a1b4617b7
commit
d7c9a30258
|
@ -0,0 +1,8 @@
|
||||||
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
|
public enum ArchiveLayout {
|
||||||
|
BEST_FIT,
|
||||||
|
PICTURE_IN_PICTURE,
|
||||||
|
VERTICAL_PRESENTATION,
|
||||||
|
HORIZONTAL_PRESENTATION
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
|
public enum ArchiveMode {
|
||||||
|
ALWAYS, // The session is archived automatically (as soon as there are clients publishing streams to the session)
|
||||||
|
MANUAL; // The session is not archived automatically. To archive the session, you can call the OpenVidu.StartArchive() method
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
|
public enum MediaMode {
|
||||||
|
RELAYED, // The session will attempt to transmit streams directly between clients
|
||||||
|
ROUTED // The session will transmit streams using OpenVidu Media Server
|
||||||
|
}
|
|
@ -54,4 +54,17 @@ public class OpenVidu {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Session createSession(SessionProperties properties) throws OpenViduException {
|
||||||
|
Session s = new Session(myHttpClient, urlOpenViduServer, properties);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startArchive(String sessionId) {
|
||||||
|
// TODO: REST POST to start recording in OpenVidu Server
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopArchive(String sessionId) {
|
||||||
|
// TODO: REST POST to end recording in OpenVidu Server
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package io.openvidu.java.client;
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
public enum OpenViduRole {
|
public enum OpenViduRole {
|
||||||
SUBSCRIBER,
|
SUBSCRIBER, // Can subscribe to published streams of other users
|
||||||
PUBLISHER,
|
PUBLISHER, // SUBSCRIBER permissions + can subscribe to published streams of other users and publish their own streams
|
||||||
MODERATOR;
|
MODERATOR; // SUBSCRIBER + PUBLIHSER permissions + can force unpublish() and disconnect() over a third-party stream or user
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.io.InputStreamReader;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
@ -20,10 +19,19 @@ public class Session {
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
private String urlOpenViduServer;
|
private String urlOpenViduServer;
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
private SessionProperties properties;
|
||||||
|
|
||||||
protected Session(HttpClient httpClient, String urlOpenViduServer) throws OpenViduException {
|
protected Session(HttpClient httpClient, String urlOpenViduServer) throws OpenViduException {
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
this.urlOpenViduServer = urlOpenViduServer;
|
this.urlOpenViduServer = urlOpenViduServer;
|
||||||
|
this.properties = new SessionProperties();
|
||||||
|
this.sessionId = this.getSessionId();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Session(HttpClient httpClient, String urlOpenViduServer, SessionProperties properties) {
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
this.urlOpenViduServer = urlOpenViduServer;
|
||||||
|
this.properties = properties;
|
||||||
this.sessionId = this.getSessionId();
|
this.sessionId = this.getSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +42,18 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpResponse response = httpClient.execute(new HttpPost(this.urlOpenViduServer + "api/sessions"));
|
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("archiveMode", properties.archiveMode().name());
|
||||||
|
json.put("archiveLayout", properties.archiveLayout().name());
|
||||||
|
json.put("mediaMode", properties.mediaMode().name());
|
||||||
|
|
||||||
|
HttpPost request = new HttpPost(this.urlOpenViduServer + "api/sessions");
|
||||||
|
StringEntity params = new StringEntity(json.toString());
|
||||||
|
request.addHeader("content-type", "application/json");
|
||||||
|
request.setEntity(params);
|
||||||
|
|
||||||
|
HttpResponse response = httpClient.execute(request);
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
if ((statusCode == org.apache.http.HttpStatus.SC_OK)) {
|
if ((statusCode == org.apache.http.HttpStatus.SC_OK)) {
|
||||||
System.out.println("Returning a SESSIONID");
|
System.out.println("Returning a SESSIONID");
|
||||||
|
@ -46,7 +65,8 @@ public class Session {
|
||||||
throw new OpenViduException(Code.SESSIONID_CANNOT_BE_CREATED_ERROR_CODE, Integer.toString(statusCode));
|
throw new OpenViduException(Code.SESSIONID_CANNOT_BE_CREATED_ERROR_CODE, Integer.toString(statusCode));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OpenViduException(Code.SESSIONID_CANNOT_BE_CREATED_ERROR_CODE, "Unable to generate a sessionID: " + e.getMessage());
|
throw new OpenViduException(Code.SESSIONID_CANNOT_BE_CREATED_ERROR_CODE,
|
||||||
|
"Unable to generate a sessionId: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,10 +104,15 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new OpenViduException(Code.TOKEN_CANNOT_BE_CREATED_ERROR_CODE, "Unable to generate a token: " + e.getMessage());
|
throw new OpenViduException(Code.TOKEN_CANNOT_BE_CREATED_ERROR_CODE,
|
||||||
|
"Unable to generate a token: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SessionProperties getProperties() {
|
||||||
|
return this.properties;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.sessionId;
|
return this.sessionId;
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package io.openvidu.java.client;
|
||||||
|
|
||||||
|
public class SessionProperties {
|
||||||
|
|
||||||
|
private MediaMode mediaMode;
|
||||||
|
private ArchiveMode archiveMode;
|
||||||
|
private ArchiveLayout archiveLayout;
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private MediaMode mediaMode = MediaMode.ROUTED;
|
||||||
|
private ArchiveMode archiveMode = ArchiveMode.MANUAL;
|
||||||
|
private ArchiveLayout archiveLayout = ArchiveLayout.BEST_FIT;
|
||||||
|
|
||||||
|
public SessionProperties build() {
|
||||||
|
return new SessionProperties(this.mediaMode, this.archiveMode, this.archiveLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionProperties.Builder mediaMode(MediaMode mediaMode) {
|
||||||
|
this.mediaMode = mediaMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionProperties.Builder archiveMode(ArchiveMode archiveMode) {
|
||||||
|
this.archiveMode = archiveMode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SessionProperties.Builder archiveLayout(ArchiveLayout archiveLayout) {
|
||||||
|
this.archiveLayout = archiveLayout;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SessionProperties() {
|
||||||
|
this.mediaMode = MediaMode.ROUTED;
|
||||||
|
this.archiveMode = ArchiveMode.MANUAL;
|
||||||
|
this.archiveLayout = ArchiveLayout.BEST_FIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SessionProperties(MediaMode mediaMode, ArchiveMode archiveMode, ArchiveLayout archiveLayout) {
|
||||||
|
this.mediaMode = mediaMode;
|
||||||
|
this.archiveMode = archiveMode;
|
||||||
|
this.archiveLayout = archiveLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArchiveMode archiveMode() {
|
||||||
|
return this.archiveMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MediaMode mediaMode() {
|
||||||
|
return this.mediaMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArchiveLayout archiveLayout() {
|
||||||
|
return this.archiveLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ public class TokenOptions {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TokenOptions(String data, OpenViduRole role){
|
private TokenOptions(String data, OpenViduRole role){
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue