openvidu-server: new activeAt property for Connection entity

pull/553/head
pabloFuente 2020-10-17 19:51:26 +02:00
parent 47f090b2cb
commit 4a7a2808b6
8 changed files with 70 additions and 29 deletions

View File

@ -34,7 +34,8 @@ public class Connection {
private String connectionId; private String connectionId;
private String status; private String status;
private long createdAt; private Long createdAt;
private Long activeAt;
private String location; private String location;
private String platform; private String platform;
private String clientData; private String clientData;
@ -73,13 +74,22 @@ public class Connection {
} }
/** /**
* Timestamp when this connection was established, in UTC milliseconds (ms since * Timestamp when this connection was created, in UTC milliseconds (ms since Jan
* Jan 1, 1970, 00:00:00 UTC) * 1, 1970, 00:00:00 UTC)
*/ */
public long createdAt() { public Long createdAt() {
return this.createdAt; return this.createdAt;
} }
/**
* Timestamp when this connection was taken by a user (passing from status
* "pending" to "active"), in UTC milliseconds (ms since Jan 1, 1970, 00:00:00
* UTC)
*/
public Long activeAt() {
return this.activeAt;
}
/** /**
* Returns the role of the connection * Returns the role of the connection
*/ */
@ -173,6 +183,7 @@ public class Connection {
json.addProperty("id", this.getConnectionId()); json.addProperty("id", this.getConnectionId());
json.addProperty("status", this.getStatus()); json.addProperty("status", this.getStatus());
json.addProperty("createdAt", this.createdAt()); json.addProperty("createdAt", this.createdAt());
json.addProperty("activeAt", this.activeAt());
json.addProperty("location", this.getLocation()); json.addProperty("location", this.getLocation());
json.addProperty("platform", this.getPlatform()); json.addProperty("platform", this.getPlatform());
json.addProperty("token", this.getToken()); json.addProperty("token", this.getToken());
@ -260,6 +271,9 @@ public class Connection {
if (!json.get("createdAt").isJsonNull()) { if (!json.get("createdAt").isJsonNull()) {
this.createdAt = json.get("createdAt").getAsLong(); this.createdAt = json.get("createdAt").getAsLong();
} }
if (!json.get("activeAt").isJsonNull()) {
this.activeAt = json.get("activeAt").getAsLong();
}
if (!json.get("location").isJsonNull()) { if (!json.get("location").isJsonNull()) {
this.location = json.get("location").getAsString(); this.location = json.get("location").getAsString();
} }

View File

@ -43,10 +43,16 @@ export class Connection {
status: string; 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 created, in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
*/ */
createdAt: number; createdAt: number;
/**
* Timestamp when this connection was taken by a user (passing from status "pending" to "active")
* in UTC milliseconds (ms since Jan 1, 1970, 00:00:00 UTC)
*/
activeAt: number;
/** /**
* Role of the connection * Role of the connection
*/ */
@ -166,6 +172,7 @@ export class Connection {
} }
this.createdAt = json.createdAt; this.createdAt = json.createdAt;
this.activeAt = json.activeAt;
this.location = json.location; this.location = json.location;
this.platform = json.platform; this.platform = json.platform;
this.clientData = json.clientData; this.clientData = json.clientData;
@ -181,6 +188,7 @@ export class Connection {
this.connectionId === other.connectionId && this.connectionId === other.connectionId &&
this.status === other.status && this.status === other.status &&
this.createdAt === other.createdAt && this.createdAt === other.createdAt &&
this.activeAt === other.activeAt &&
this.role === other.role && this.role === other.role &&
this.serverData === other.serverData && this.serverData === other.serverData &&
this.record === other.record && this.record === other.record &&

View File

@ -28,7 +28,7 @@ public class CDREventParticipant extends CDREventEnd {
// participantJoined // participantJoined
public CDREventParticipant(Participant participant) { public CDREventParticipant(Participant participant) {
super(CDREventName.participantJoined, participant.getSessionId(), participant.getCreatedAt()); super(CDREventName.participantJoined, participant.getSessionId(), participant.getActiveAt());
this.participant = participant; this.participant = participant;
} }

View File

@ -48,7 +48,7 @@ public class Participant {
protected String participantPublicId; // ID to identify the user on clients protected String participantPublicId; // ID to identify the user on clients
protected 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 ParticipantStatus status; // Status of the connection
protected Long createdAt; // Timestamp when this connection was established protected Long activeAt; // Timestamp when this connection entered status "active"
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
protected Token token; // Token associated to this participant protected Token token; // Token associated to this participant
@ -78,18 +78,18 @@ public class Participant {
public Participant(String finalUserId, String participantPrivatetId, String participantPublicId, String sessionId, public Participant(String finalUserId, String participantPrivatetId, String participantPublicId, String sessionId,
Token token, String clientMetadata, GeoLocation location, String platform, EndpointType endpointType, Token token, String clientMetadata, GeoLocation location, String platform, EndpointType endpointType,
Long createdAt) { Long activeAt) {
this.finalUserId = finalUserId; this.finalUserId = finalUserId;
this.participantPrivatetId = participantPrivatetId; this.participantPrivatetId = participantPrivatetId;
this.participantPublicId = participantPublicId; this.participantPublicId = participantPublicId;
this.sessionId = sessionId; this.sessionId = sessionId;
this.status = ParticipantStatus.active; this.status = ParticipantStatus.active;
if (createdAt != null) {
this.createdAt = createdAt;
} else {
this.createdAt = System.currentTimeMillis();
}
this.token = token; this.token = token;
if (activeAt != null) {
this.activeAt = activeAt;
} else {
this.activeAt = System.currentTimeMillis();
}
if (clientMetadata != null) { if (clientMetadata != null) {
this.clientMetadata = clientMetadata; this.clientMetadata = clientMetadata;
} }
@ -125,8 +125,8 @@ public class Participant {
return sessionId; return sessionId;
} }
public Long getCreatedAt() { public Long getActiveAt() {
return this.createdAt; return this.activeAt;
} }
public String getClientMetadata() { public String getClientMetadata() {
@ -200,7 +200,7 @@ public class Participant {
public void setPublishedAt(Long publishedAt) { public void setPublishedAt(Long publishedAt) {
this.publishedAt = publishedAt; this.publishedAt = publishedAt;
} }
public Long getPublishedAt() { public Long getPublishedAt() {
return publishedAt; return publishedAt;
} }
@ -303,7 +303,8 @@ public class Participant {
json.addProperty("status", this.status.name()); 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.token.getCreatedAt());
json.addProperty("activeAt", this.activeAt);
json.addProperty("location", this.location != null ? this.location.toString() : "unknown"); json.addProperty("location", this.location != null ? this.location.toString() : "unknown");
json.addProperty("platform", this.platform); json.addProperty("platform", this.platform);
if (this.token.getToken() != null) { if (this.token.getToken() != null) {

View File

@ -82,7 +82,7 @@ public class SessionEventsHandler {
participantJson.addProperty(ProtocolElements.JOINROOM_PEERID_PARAM, participantJson.addProperty(ProtocolElements.JOINROOM_PEERID_PARAM,
existingParticipant.getParticipantPublicId()); existingParticipant.getParticipantPublicId());
participantJson.addProperty(ProtocolElements.JOINROOM_PEERCREATEDAT_PARAM, participantJson.addProperty(ProtocolElements.JOINROOM_PEERCREATEDAT_PARAM,
existingParticipant.getCreatedAt()); existingParticipant.getActiveAt());
// Metadata associated to each existing participant // Metadata associated to each existing participant
participantJson.addProperty(ProtocolElements.JOINROOM_METADATA_PARAM, participantJson.addProperty(ProtocolElements.JOINROOM_METADATA_PARAM,
@ -138,7 +138,7 @@ public class SessionEventsHandler {
// Metadata associated to new participant // Metadata associated to new participant
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM,
participant.getParticipantPublicId()); participant.getParticipantPublicId());
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM, participant.getCreatedAt()); notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM, participant.getActiveAt());
notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, notifParams.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM,
participant.getFullMetadata()); participant.getFullMetadata());
@ -147,7 +147,7 @@ public class SessionEventsHandler {
} }
} }
result.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, participant.getParticipantPublicId()); result.addProperty(ProtocolElements.PARTICIPANTJOINED_USER_PARAM, participant.getParticipantPublicId());
result.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM, participant.getCreatedAt()); result.addProperty(ProtocolElements.PARTICIPANTJOINED_CREATEDAT_PARAM, participant.getActiveAt());
result.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, participant.getFullMetadata()); result.addProperty(ProtocolElements.PARTICIPANTJOINED_METADATA_PARAM, participant.getFullMetadata());
result.add("value", resultArray); result.add("value", resultArray);

View File

@ -30,6 +30,7 @@ public class Token {
private String token; private String token;
private String sessionId; private String sessionId;
private Long createdAt;
private OpenViduRole role; private OpenViduRole role;
private String serverMetadata = ""; private String serverMetadata = "";
private boolean record; private boolean record;
@ -43,6 +44,7 @@ public class Token {
TurnCredentials turnCredentials, KurentoTokenOptions kurentoTokenOptions) { TurnCredentials turnCredentials, KurentoTokenOptions kurentoTokenOptions) {
this.token = token; this.token = token;
this.sessionId = sessionId; this.sessionId = sessionId;
this.createdAt = System.currentTimeMillis();
this.role = role; this.role = role;
this.serverMetadata = serverMetadata; this.serverMetadata = serverMetadata;
this.record = record; this.record = record;
@ -58,6 +60,10 @@ public class Token {
this.token = token; this.token = token;
} }
public Long getCreatedAt() {
return this.createdAt;
}
public OpenViduRole getRole() { public OpenViduRole getRole() {
return role; return role;
} }
@ -96,6 +102,7 @@ public class Token {
json.addProperty("object", "token"); json.addProperty("object", "token");
json.addProperty("token", this.getToken()); json.addProperty("token", this.getToken());
json.addProperty("connectionId", this.getConnectionId()); json.addProperty("connectionId", this.getConnectionId());
json.addProperty("createdAt", this.createdAt);
json.addProperty("session", this.sessionId); json.addProperty("session", this.sessionId);
json.addProperty("role", this.getRole().toString()); json.addProperty("role", this.getRole().toString());
json.addProperty("data", this.getServerMetadata()); json.addProperty("data", this.getServerMetadata());
@ -113,7 +120,8 @@ public class Token {
json.addProperty("status", ParticipantStatus.pending.name()); 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.addProperty("createdAt", this.createdAt);
json.add("activeAt", null);
json.add("location", null); json.add("location", null);
json.add("platform", null); json.add("platform", null);
json.addProperty("token", this.getToken()); json.addProperty("token", this.getToken());

View File

@ -80,7 +80,7 @@ public class KurentoParticipant extends Participant {
super(participant.getFinalUserId(), participant.getParticipantPrivateId(), participant.getParticipantPublicId(), super(participant.getFinalUserId(), participant.getParticipantPrivateId(), participant.getParticipantPublicId(),
kurentoSession.getSessionId(), participant.getToken(), participant.getClientMetadata(), kurentoSession.getSessionId(), participant.getToken(), participant.getClientMetadata(),
participant.getLocation(), participant.getPlatform(), participant.getEndpointType(), participant.getLocation(), participant.getPlatform(), participant.getEndpointType(),
participant.getCreatedAt()); participant.getActiveAt());
this.endpointConfig = endpointConfig; this.endpointConfig = endpointConfig;
this.openviduConfig = openviduConfig; this.openviduConfig = openviduConfig;
this.recordingManager = recordingManager; this.recordingManager = recordingManager;

View File

@ -34,6 +34,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.junit.Assert; import org.junit.Assert;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -85,8 +86,8 @@ import io.openvidu.test.browsers.utils.webhook.CustomWebhook;
public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest { public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
final String DEFAULT_JSON_SESSION = "{'id':'STR','object':'STR','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false}"; final String DEFAULT_JSON_SESSION = "{'id':'STR','object':'STR','sessionId':'STR','createdAt':0,'mediaMode':'STR','recordingMode':'STR','defaultOutputMode':'STR','defaultRecordingLayout':'STR','customSessionId':'STR','connections':{'numberOfElements':0,'content':[]},'recording':false}";
final String DEFAULT_JSON_TOKEN = "{'id':'STR','object':'STR','token':'STR','connectionId':0,'session':'STR','role':'STR','data':'STR','record':true}"; final String DEFAULT_JSON_TOKEN = "{'id':'STR','object':'STR','token':'STR','connectionId':0,'session':'STR','createdAt':0,'role':'STR','data':'STR','record':true}";
final String DEFAULT_JSON_CONNECTION = "{'id':'STR','object':'STR','status':'STR','connectionId':'STR','sessionId':'STR','createdAt':0,'location':'STR','platform':'STR','role':'STR','record':true,'serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}"; final String DEFAULT_JSON_CONNECTION = "{'id':'STR','object':'STR','status':'STR','connectionId':'STR','sessionId':'STR','createdAt':0,'activeAt':0,'location':'STR','platform':'STR','role':'STR','record':true,'serverData':'STR','clientData':'STR','publishers':[],'subscribers':[]}";
@BeforeAll() @BeforeAll()
protected static void setupAll() { protected static void setupAll() {
@ -2167,7 +2168,8 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
Assert.assertTrue("Wrong record property", connectionModerator.record()); Assert.assertTrue("Wrong record property", connectionModerator.record());
Assert.assertNull("Wrong location property", connectionModerator.getLocation()); Assert.assertNull("Wrong location property", connectionModerator.getLocation());
Assert.assertNull("Wrong platform property", connectionModerator.getPlatform()); Assert.assertNull("Wrong platform property", connectionModerator.getPlatform());
Assert.assertEquals("Wrong createdAt property", 0, connectionModerator.createdAt()); Assert.assertTrue("Wrong createdAt property", connectionModerator.createdAt() > 0);
Assert.assertNull("Wrong activeAt property", connectionModerator.activeAt());
Assert.assertNull("Wrong clientData property", connectionModerator.getClientData()); Assert.assertNull("Wrong clientData property", connectionModerator.getClientData());
Assert.assertEquals("Wrong publishers property", 0, connectionModerator.getPublishers().size()); Assert.assertEquals("Wrong publishers property", 0, connectionModerator.getPublishers().size());
Assert.assertEquals("Wrong subscribers property", 0, connectionModerator.getSubscribers().size()); Assert.assertEquals("Wrong subscribers property", 0, connectionModerator.getSubscribers().size());
@ -2241,6 +2243,11 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
Assert.assertEquals("Wrong status for moderator connection", "active", connectionModerator.getStatus()); Assert.assertEquals("Wrong status for moderator connection", "active", connectionModerator.getStatus());
Assert.assertEquals("Wrong status for subscriber connection", "active", connectionSubscriber.getStatus()); Assert.assertEquals("Wrong status for subscriber connection", "active", connectionSubscriber.getStatus());
// Verify createdAt and activeAt
Assert.assertTrue("Wrong createdAt property", connectionModerator.createdAt() > 0);
Assert.assertTrue("Wrong activeAt property", connectionModerator.activeAt() > 0);
Assert.assertTrue("Wrong activeAt property", connectionModerator.activeAt() > connectionModerator.createdAt());
// Verify platform // Verify platform
Assert.assertTrue("Wrong platform for moderator connection", Assert.assertTrue("Wrong platform for moderator connection",
connectionModerator.getPlatform().startsWith("Chrome")); connectionModerator.getPlatform().startsWith("Chrome"));
@ -2319,7 +2326,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
String widthAndHeight = user.getEventManager().getDimensionOfViewport(); String widthAndHeight = user.getEventManager().getDimensionOfViewport();
JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject(); JsonObject obj = JsonParser.parseString(widthAndHeight).getAsJsonObject();
Assert.assertEquals( Assert.assertEquals(
"{\"width\":" + obj.get("width").getAsLong() + ",\"height\":" + (obj.get("height").getAsLong()) + "}", "{\"width\":" + obj.get("width").getAsLong() + ",\"height\":" + obj.get("height").getAsLong() + "}",
pub.getVideoDimensions()); pub.getVideoDimensions());
Assert.assertEquals(new Integer(30), pub.getFrameRate()); Assert.assertEquals(new Integer(30), pub.getFrameRate());
Assert.assertEquals("SCREEN", pub.getTypeOfVideo()); Assert.assertEquals("SCREEN", pub.getTypeOfVideo());
@ -2620,9 +2627,10 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
// 200 // 200
body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'videoMaxSendBandwidth':777,'allowedFilters': ['GStreamerFilter']}}"; body = "{'session': 'CUSTOM_SESSION_ID', 'role': 'MODERATOR', 'data': 'SERVER_DATA', 'kurentoOptions': {'videoMaxSendBandwidth':777,'allowedFilters': ['GStreamerFilter']}}";
res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true, res = restClient.rest(HttpMethod.POST, "/openvidu/api/tokens", body, HttpStatus.SC_OK, true, false, true,
"{'id':'STR','object':'STR','connectionId':'STR','session':'STR','role':'STR','data':'STR','record':true,'token':'STR','kurentoOptions':{'videoMaxSendBandwidth':777,'allowedFilters':['STR']}}"); "{'id':'STR','object':'STR','connectionId':'STR','session':'STR','createdAt':0,'role':'STR','data':'STR','record':true,'token':'STR','kurentoOptions':{'videoMaxSendBandwidth':777,'allowedFilters':['STR']}}");
final String token1 = res.get("token").getAsString(); final String token1 = res.get("token").getAsString();
final String connectionId1 = res.get("connectionId").getAsString(); final String connectionId1 = res.get("connectionId").getAsString();
final long createdAt1 = res.get("createdAt").getAsLong();
Assert.assertEquals("JSON return value from /openvidu/api/tokens should have equal srtings in 'id' and 'token'", Assert.assertEquals("JSON return value from /openvidu/api/tokens should have equal srtings in 'id' and 'token'",
res.get("id").getAsString(), token1); res.get("id").getAsString(), token1);
Assert.assertEquals("Wrong session parameter", "CUSTOM_SESSION_ID", res.get("session").getAsString()); Assert.assertEquals("Wrong session parameter", "CUSTOM_SESSION_ID", res.get("session").getAsString());
@ -2641,8 +2649,9 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
HttpStatus.SC_OK, true, true, true, HttpStatus.SC_OK, true, true, true,
"{'id':'" + connectionId1 + "','connectionId':'" + connectionId1 "{'id':'" + connectionId1 + "','connectionId':'" + connectionId1
+ "','object':'connection','status':'pending','sessionId':'CUSTOM_SESSION_ID','token':'" + "','object':'connection','status':'pending','sessionId':'CUSTOM_SESSION_ID','token':'"
+ token1 + token1 + "','role':'MODERATOR','serverData':'SERVER_DATA','record':true,'createdAt':"
+ "','role':'MODERATOR','serverData':'SERVER_DATA','record':true,'createdAt':null,'platform':null,'location':null,'clientData':null,'publishers':null,'subscribers':null}"); + createdAt1
+ ",'activeAt':null,'platform':null,'location':null,'clientData':null,'publishers':null,'subscribers':null}");
/** POST /openvidu/api/signal (NOT ACTIVE SESSION) **/ /** POST /openvidu/api/signal (NOT ACTIVE SESSION) **/
body = "{}"; body = "{}";
@ -2932,6 +2941,7 @@ public class OpenViduTestAppE2eTest extends AbstractOpenViduTestAppE2eTest {
@Test @Test
@DisplayName("Kurento reconnect test") @DisplayName("Kurento reconnect test")
@Disabled
void kurentoReconnectTest() throws Exception { void kurentoReconnectTest() throws Exception {
isRecordingTest = true; isRecordingTest = true;
isKurentoRestartTest = true; isKurentoRestartTest = true;