mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: new "status" property in Connection entities
parent
6f33bf5def
commit
1c72a1ce4e
|
@ -31,6 +31,7 @@ import com.google.gson.JsonObject;
|
||||||
public class Connection {
|
public class Connection {
|
||||||
|
|
||||||
private String connectionId;
|
private String connectionId;
|
||||||
|
private String status;
|
||||||
private long createdAt;
|
private long createdAt;
|
||||||
private String location;
|
private String location;
|
||||||
private String platform;
|
private String platform;
|
||||||
|
@ -77,6 +78,7 @@ public class Connection {
|
||||||
|
|
||||||
// These properties won't ever be null
|
// These properties won't ever be null
|
||||||
this.connectionId = json.get("connectionId").getAsString();
|
this.connectionId = json.get("connectionId").getAsString();
|
||||||
|
this.status = json.get("status").getAsString();
|
||||||
String token = json.has("token") ? json.get("token").getAsString() : null;
|
String token = json.has("token") ? json.get("token").getAsString() : null;
|
||||||
OpenViduRole role = OpenViduRole.valueOf(json.get("role").getAsString());
|
OpenViduRole role = OpenViduRole.valueOf(json.get("role").getAsString());
|
||||||
String data = json.get("serverData").getAsString();
|
String data = json.get("serverData").getAsString();
|
||||||
|
@ -96,6 +98,21 @@ public class Connection {
|
||||||
return connectionId;
|
return connectionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the status of the connection. Can be:
|
||||||
|
* <ul>
|
||||||
|
* <li><code>pending</code>: if the Connection is waiting for any user to use
|
||||||
|
* its internal token to connect to the session, calling method <a href=
|
||||||
|
* "https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/session.html#connect"
|
||||||
|
* target ="_blank">Session.connect</a> in OpenVidu Browser.</li>
|
||||||
|
* <li><code>active</code>: if the internal token of the Connection has already
|
||||||
|
* been used by some user to connect to the session, and it cannot be used
|
||||||
|
* again.</li>
|
||||||
|
*/
|
||||||
|
public String getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timestamp when this connection was established, in UTC milliseconds (ms since
|
* Timestamp when this connection was established, in UTC milliseconds (ms since
|
||||||
* Jan 1, 1970, 00:00:00 UTC)
|
* Jan 1, 1970, 00:00:00 UTC)
|
||||||
|
@ -195,6 +212,7 @@ public class Connection {
|
||||||
protected JsonObject toJson() {
|
protected JsonObject toJson() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("id", this.getConnectionId());
|
json.addProperty("id", this.getConnectionId());
|
||||||
|
json.addProperty("status", this.getStatus());
|
||||||
json.addProperty("createdAt", this.createdAt());
|
json.addProperty("createdAt", this.createdAt());
|
||||||
json.addProperty("location", this.getLocation());
|
json.addProperty("location", this.getLocation());
|
||||||
json.addProperty("platform", this.getPlatform());
|
json.addProperty("platform", this.getPlatform());
|
||||||
|
|
|
@ -30,6 +30,18 @@ export class Connection {
|
||||||
*/
|
*/
|
||||||
connectionId: string;
|
connectionId: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the status of the connection. Can be:
|
||||||
|
* - `pending`: if the Connection is waiting for any user to use
|
||||||
|
* its internal token to connect to the session, calling method
|
||||||
|
* [Session.connect](https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/session.html#connect)
|
||||||
|
* in OpenVidu Browser.
|
||||||
|
* - `active`: if the internal token of the Connection has already
|
||||||
|
* been used by some user to connect to the session, and it cannot be used
|
||||||
|
* again.
|
||||||
|
*/
|
||||||
|
status: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timestamp when this connection was established, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
|
* Timestamp when this connection was established, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
|
||||||
*/
|
*/
|
||||||
|
@ -106,6 +118,7 @@ export class Connection {
|
||||||
|
|
||||||
// These properties won't ever be null
|
// These properties won't ever be null
|
||||||
this.connectionId = json.connectionId;
|
this.connectionId = json.connectionId;
|
||||||
|
this.status = json.status;
|
||||||
this.token = json.token;
|
this.token = json.token;
|
||||||
this.role = json.role;
|
this.role = json.role;
|
||||||
this.serverData = json.serverData;
|
this.serverData = json.serverData;
|
||||||
|
@ -118,6 +131,7 @@ export class Connection {
|
||||||
equalTo(other: Connection): boolean {
|
equalTo(other: Connection): boolean {
|
||||||
let equals: boolean = (
|
let equals: boolean = (
|
||||||
this.connectionId === other.connectionId &&
|
this.connectionId === other.connectionId &&
|
||||||
|
this.status === other.status &&
|
||||||
this.createdAt === other.createdAt &&
|
this.createdAt === other.createdAt &&
|
||||||
this.role === other.role &&
|
this.role === other.role &&
|
||||||
this.serverData === other.serverData &&
|
this.serverData === other.serverData &&
|
||||||
|
|
|
@ -27,10 +27,27 @@ import io.openvidu.server.utils.GeoLocation;
|
||||||
|
|
||||||
public class Participant {
|
public class Participant {
|
||||||
|
|
||||||
|
enum ParticipantStatus {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The participant has not called Session.publish in the client side yet. The
|
||||||
|
* internal token is available.
|
||||||
|
*/
|
||||||
|
pending,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The participant has called Session.publish in the client side and a WebSocket
|
||||||
|
* connection is established. The internal token has been consumed and cannot be
|
||||||
|
* used again.
|
||||||
|
*/
|
||||||
|
active
|
||||||
|
}
|
||||||
|
|
||||||
protected String finalUserId; // ID to match this connection with a final user (HttpSession id)
|
protected String finalUserId; // ID to match this connection with a final user (HttpSession id)
|
||||||
protected String participantPrivatetId; // ID to identify the user on server (org.kurento.jsonrpc.Session.id)
|
protected String participantPrivatetId; // ID to identify the user on server (org.kurento.jsonrpc.Session.id)
|
||||||
protected String participantPublicId; // ID to identify the user on clients
|
protected String participantPublicId; // ID to identify the user on clients
|
||||||
private String sessionId; // ID of the session to which the participant belongs
|
protected String sessionId; // ID of the session to which the participant belongs
|
||||||
|
protected ParticipantStatus status; // Status of the connection
|
||||||
protected Long createdAt; // Timestamp when this connection was established
|
protected Long createdAt; // Timestamp when this connection was established
|
||||||
protected String clientMetadata = ""; // Metadata provided on client side
|
protected String clientMetadata = ""; // Metadata provided on client side
|
||||||
protected String serverMetadata = ""; // Metadata provided on server side
|
protected String serverMetadata = ""; // Metadata provided on server side
|
||||||
|
@ -65,6 +82,7 @@ public class Participant {
|
||||||
this.participantPrivatetId = participantPrivatetId;
|
this.participantPrivatetId = participantPrivatetId;
|
||||||
this.participantPublicId = participantPublicId;
|
this.participantPublicId = participantPublicId;
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
|
this.status = ParticipantStatus.active;
|
||||||
if (createdAt != null) {
|
if (createdAt != null) {
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
} else {
|
} else {
|
||||||
|
@ -273,6 +291,7 @@ public class Participant {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("id", this.participantPublicId);
|
json.addProperty("id", this.participantPublicId);
|
||||||
json.addProperty("object", "connection");
|
json.addProperty("object", "connection");
|
||||||
|
json.addProperty("status", this.status.name());
|
||||||
json.addProperty("connectionId", this.participantPublicId); // TODO: deprecated. Better use only "id"
|
json.addProperty("connectionId", this.participantPublicId); // TODO: deprecated. Better use only "id"
|
||||||
json.addProperty("sessionId", this.sessionId);
|
json.addProperty("sessionId", this.sessionId);
|
||||||
json.addProperty("createdAt", this.createdAt);
|
json.addProperty("createdAt", this.createdAt);
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.openvidu.java.client.OpenViduRole;
|
import io.openvidu.java.client.OpenViduRole;
|
||||||
|
import io.openvidu.server.core.Participant.ParticipantStatus;
|
||||||
import io.openvidu.server.coturn.TurnCredentials;
|
import io.openvidu.server.coturn.TurnCredentials;
|
||||||
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
||||||
|
|
||||||
|
@ -109,6 +110,7 @@ public class Token {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
json.addProperty("id", this.getConnectionId());
|
json.addProperty("id", this.getConnectionId());
|
||||||
json.addProperty("object", "connection");
|
json.addProperty("object", "connection");
|
||||||
|
json.addProperty("status", ParticipantStatus.pending.name());
|
||||||
json.addProperty("connectionId", this.getConnectionId()); // DEPRECATED: better use id
|
json.addProperty("connectionId", this.getConnectionId()); // DEPRECATED: better use id
|
||||||
json.addProperty("sessionId", this.sessionId);
|
json.addProperty("sessionId", this.sessionId);
|
||||||
json.add("createdAt", null);
|
json.add("createdAt", null);
|
||||||
|
|
|
@ -210,14 +210,14 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
|
||||||
// Updating only role should let record value untouched
|
// Updating only role should let record value untouched
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'role':'MODERATOR'}", HttpStatus.SC_OK, true, true, true,
|
"{'role':'MODERATOR'}", HttpStatus.SC_OK, true, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'pending','connectionId':'"
|
||||||
+ "','role':'MODERATOR','record':false,'token':'" + token
|
+ tokenConnectionId + "','role':'MODERATOR','record':false,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':null,'subscribers':null,'createdAt':null,'platform':null,'location':null,'clientData':null}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':null,'subscribers':null,'createdAt':null,'platform':null,'location':null,'clientData':null}");
|
||||||
// Updating only record should let role value untouched
|
// Updating only record should let role value untouched
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'record':true}", HttpStatus.SC_OK, true, true, true,
|
"{'record':true}", HttpStatus.SC_OK, true, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'pending','connectionId':'"
|
||||||
+ "','role':'MODERATOR','record':true,'token':'" + token
|
+ tokenConnectionId + "','role':'MODERATOR','record':true,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':null,'subscribers':null,'createdAt':null,'platform':null,'location':null,'clientData':null}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':null,'subscribers':null,'createdAt':null,'platform':null,'location':null,'clientData':null}");
|
||||||
|
|
||||||
// Test with openvidu-java-client
|
// Test with openvidu-java-client
|
||||||
|
@ -278,24 +278,24 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
|
||||||
// Updating only role should let record value untouched
|
// Updating only role should let record value untouched
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'role':'MODERATOR'}", HttpStatus.SC_OK, false, true, true,
|
"{'role':'MODERATOR'}", HttpStatus.SC_OK, false, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'active','connectionId':'"
|
||||||
+ "','role':'MODERATOR','record':false,'token':'" + token
|
+ tokenConnectionId + "','role':'MODERATOR','record':false,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
||||||
// Updating only record should let role value untouched
|
// Updating only record should let role value untouched
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'record':true}", HttpStatus.SC_OK, false, true, true,
|
"{'record':true}", HttpStatus.SC_OK, false, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'active','connectionId':'"
|
||||||
+ "','role':'MODERATOR','record':true,'token':'" + token
|
+ tokenConnectionId + "','role':'MODERATOR','record':true,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'role':'SUBSCRIBER','record':true,'data':'OTHER DATA'}", HttpStatus.SC_OK, false, true, true,
|
"{'role':'SUBSCRIBER','record':true,'data':'OTHER DATA'}", HttpStatus.SC_OK, false, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'active','connectionId':'"
|
||||||
+ "','role':'SUBSCRIBER','record':true,'token':'" + token
|
+ tokenConnectionId + "','role':'SUBSCRIBER','record':true,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
||||||
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
restClient.rest(HttpMethod.PATCH, "/openvidu/api/sessions/CUSTOM_SESSION_ID/connection/" + tokenConnectionId,
|
||||||
"{'role':'PUBLISHER'}", HttpStatus.SC_OK, false, true, true,
|
"{'role':'PUBLISHER'}", HttpStatus.SC_OK, false, true, true,
|
||||||
"{'id':'" + tokenConnectionId + "','object':'connection','connectionId':'" + tokenConnectionId
|
"{'id':'" + tokenConnectionId + "','object':'connection','status':'active','connectionId':'"
|
||||||
+ "','role':'PUBLISHER','record':true,'token':'" + token
|
+ tokenConnectionId + "','role':'PUBLISHER','record':true,'token':'" + token
|
||||||
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
+ "','sessionId':'CUSTOM_SESSION_ID','serverData':'','publishers':[],'subscribers':[]}");
|
||||||
|
|
||||||
// Test with openvidu-node-client
|
// Test with openvidu-node-client
|
||||||
|
@ -332,6 +332,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
|
||||||
Assert.assertEquals("Wrong connectionId in Connection object", tokenConnectionId, connection.getConnectionId());
|
Assert.assertEquals("Wrong connectionId in Connection object", tokenConnectionId, connection.getConnectionId());
|
||||||
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.PUBLISHER, connection.getRole());
|
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.PUBLISHER, connection.getRole());
|
||||||
Assert.assertTrue("Wrong record in Connection object", connection.record());
|
Assert.assertTrue("Wrong record in Connection object", connection.record());
|
||||||
|
Assert.assertEquals("Wrong status in Connection object", "active", connection.getStatus());
|
||||||
connection = session.updateConnection(tokenConnectionId,
|
connection = session.updateConnection(tokenConnectionId,
|
||||||
new ConnectionOptions.Builder().role(OpenViduRole.SUBSCRIBER).build());
|
new ConnectionOptions.Builder().role(OpenViduRole.SUBSCRIBER).build());
|
||||||
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.SUBSCRIBER, connection.getRole());
|
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.SUBSCRIBER, connection.getRole());
|
||||||
|
@ -342,6 +343,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
|
||||||
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.MODERATOR, connection.getRole());
|
Assert.assertEquals("Wrong role in Connection object", OpenViduRole.MODERATOR, connection.getRole());
|
||||||
Assert.assertFalse("Wrong record in Connection object", connection.record());
|
Assert.assertFalse("Wrong record in Connection object", connection.record());
|
||||||
Assert.assertTrue("Wrong data in Connection object", connection.getServerData().isEmpty());
|
Assert.assertTrue("Wrong data in Connection object", connection.getServerData().isEmpty());
|
||||||
|
Assert.assertEquals("Wrong status in Connection object", "active", connection.getStatus());
|
||||||
|
|
||||||
user.getEventManager().resetEventThread();
|
user.getEventManager().resetEventThread();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue