tests-e2e: Fixed endReason test

v2compatibility
Carlos Santos 2024-12-11 12:32:47 +01:00
parent 821484b42c
commit a21dd2ebb4
2 changed files with 206 additions and 177 deletions

View File

@ -229,7 +229,6 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
* events triggered. * events triggered.
*/ */
@Test @Test
@Disabled
@DisplayName("End reason") @DisplayName("End reason")
void endReasonTest() throws Exception { void endReasonTest() throws Exception {
@ -267,28 +266,31 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
try { try {
Map<String, Object> newConfig = Map.of("OPENVIDU_PRO_NETWORK_QUALITY", false, // Map<String, Object> newConfig = Map.of("OPENVIDU_PRO_NETWORK_QUALITY", false,
"OPENVIDU_PRO_SPEECH_TO_TEXT", "disabled", "OPENVIDU_WEBHOOK", true, // "OPENVIDU_PRO_SPEECH_TO_TEXT", "disabled", "OPENVIDU_WEBHOOK", true,
"OPENVIDU_WEBHOOK_ENDPOINT", "http://127.0.0.1:7777/webhook", // "OPENVIDU_WEBHOOK_ENDPOINT", "http://127.0.0.1:7777/webhook",
"OPENVIDU_RECORDING_AUTOSTOP_TIMEOUT", 0); // "OPENVIDU_RECORDING_AUTOSTOP_TIMEOUT", 0);
restartOpenViduServer(newConfig); // restartOpenViduServer(newConfig);
OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome"); OpenViduTestappUser user = setupBrowserAndConnectToOpenViduTestapp("chrome");
// unsubscribe: webrtcConnectionDestroyed // unsubscribe: webrtcConnectionDestroyed
this.connectTwoUsers(user, restClient, false, false, null); this.connectTwoUsers(user, restClient, false, false, null);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .sub-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .sub-btn")).click();
Assertions.assertEquals("unsubscribe",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); // webrtcConnectionDestroyed event is not triggered when unsubscribing in v2Compatibility (only OUTBOUND)
// Assertions.assertEquals("unsubscribe",
// CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// unpublish: webrtcConnectionDestroyed // unpublish: webrtcConnectionDestroyed
this.connectTwoUsers(user, restClient, false, false, null); this.connectTwoUsers(user, restClient, false, false, null);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .pub-btn")).click();
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
// webrtcConnectionDestroyed event is not triggered when unsubscribing in v2Compatibility (only OUTBOUND)
Assertions.assertEquals("unpublish", Assertions.assertEquals("unpublish",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// disconnect: webrtcConnectionDestroyed, participantLeft (and subsequent // disconnect: webrtcConnectionDestroyed, participantLeft (and subsequent
@ -297,39 +299,43 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
// First user out // First user out
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click();
for (int i = 0; i < 3; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("disconnect", // for (int i = 0; i < 3; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
Assertions.assertEquals("disconnect", Assertions.assertEquals("disconnect",
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
// Second user out // Second user out
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .leave-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .leave-btn")).click();
Assertions.assertEquals("disconnect", Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
Assertions.assertEquals("disconnect", Assertions.assertEquals("disconnect",
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("lastParticipantLeft", Assertions.assertEquals("recordingStoppedByServer", // reason is always "recordingStoppedByServer" in v2Compatibility
CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString());
} }
Assertions.assertEquals("lastParticipantLeft", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // Assertions.assertEquals("lastParticipantLeft",
Assertions.assertEquals("lastParticipantLeft", // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("sessionClosedByServer", // reason is always "sessionClosedByServer" in v2Compatibility
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// forceUnpublishByUser: webrtcConnectionDestroyed // forceUnpublishByUser: webrtcConnectionDestroyed
this.connectTwoUsers(user, restClient, true, false, null); this.connectTwoUsers(user, restClient, true, false, null);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-unpub-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-unpub-btn")).click();
for (int i = 0; i < 2; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("forceUnpublishByUser", // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// forceUnpublishByServer: webrtcConnectionDestroyed // forceUnpublishByServer: webrtcConnectionDestroyed
this.connectTwoUsers(user, restClient, false, false, null); this.connectTwoUsers(user, restClient, false, false, null);
Thread.sleep(5000);
String streamId = restClient String streamId = restClient
.rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK) .rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK)
.get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream() .get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream()
@ -338,20 +344,23 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
.get("streamId").getAsString(); .get("streamId").getAsString();
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/stream/" + streamId, restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/stream/" + streamId,
HttpURLConnection.HTTP_NO_CONTENT); HttpURLConnection.HTTP_NO_CONTENT);
for (int i = 0; i < 2; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("forceUnpublishByServer", // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// forceDisconnectByUser: webrtcConnectionDestroyed, participantLeft // forceDisconnectByUser: webrtcConnectionDestroyed, participantLeft
this.connectTwoUsers(user, restClient, true, false, null); this.connectTwoUsers(user, restClient, true, false, null);
Thread.sleep(5000);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-disconnect-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .force-disconnect-btn")).click();
for (int i = 0; i < 3; i++) { // for (int i = 0; i < 3; i++) {
Assertions.assertEquals("forceDisconnectByUser", // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
} CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 5).get("reason").getAsString());
Assertions.assertEquals("forceDisconnectByUser", // }
Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
@ -359,6 +368,7 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
// subsequent lastParticipantLeft triggered events for sessionDestroyed, // subsequent lastParticipantLeft triggered events for sessionDestroyed,
// recordingStatusChanged, broadcastStopped) // recordingStatusChanged, broadcastStopped)
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
Thread.sleep(2000);
String[] connectionIds = restClient String[] connectionIds = restClient
.rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK) .rest(HttpMethod.GET, "/openvidu/api/sessions/TestSession", HttpURLConnection.HTTP_OK)
.get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream() .get("connections").getAsJsonObject().get("content").getAsJsonArray().asList().stream()
@ -366,48 +376,54 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
// First user out // First user out
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/connection/" + connectionIds[0], restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/connection/" + connectionIds[0],
HttpURLConnection.HTTP_NO_CONTENT); HttpURLConnection.HTTP_NO_CONTENT);
for (int i = 0; i < 3; i++) {
Assertions.assertEquals("forceDisconnectByServer", // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
// for (int i = 0; i < 3; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
Assertions.assertEquals("forceDisconnectByServer", Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
// Second user out // Second user out
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/connection/" + connectionIds[1], restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession/connection/" + connectionIds[1],
HttpURLConnection.HTTP_NO_CONTENT); HttpURLConnection.HTTP_NO_CONTENT);
Assertions.assertEquals("forceDisconnectByServer", Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
Assertions.assertEquals("forceDisconnectByServer", Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("lastParticipantLeft", Assertions.assertEquals("recordingStoppedByServer", // reason is always "recordingStoppedByServer" in v2Compatibility
CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString());
} }
Assertions.assertEquals("lastParticipantLeft", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // Assertions.assertEquals("lastParticipantLeft",
Assertions.assertEquals("lastParticipantLeft", // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("sessionClosedByServer", // reason is always "sessionClosedByServer" in v2Compatibility
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// sessionClosedByServer: webrtcConnectionDestroyed, participantLeft, // sessionClosedByServer: webrtcConnectionDestroyed, participantLeft,
// sessionDestroyed, recordingStatusChanged, broadcastStopped // sessionDestroyed, recordingStatusChanged, broadcastStopped
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
Thread.sleep(2000);
restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession", restClient.rest(HttpMethod.DELETE, "/openvidu/api/sessions/TestSession",
HttpURLConnection.HTTP_NO_CONTENT); HttpURLConnection.HTTP_NO_CONTENT);
for (int i = 0; i < 4; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("sessionClosedByServer", for (int i = 0; i < 2; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("sessionClosedByServer", Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("sessionClosedByServer", Assertions.assertEquals("recordingStoppedByServer", // reason is always "recordingStoppedByServer" in v2Compatibility
CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString());
} }
Assertions.assertEquals("sessionClosedByServer", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // Assertions.assertEquals("sessionClosedByServer",
// CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("sessionClosedByServer", Assertions.assertEquals("sessionClosedByServer",
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
@ -418,158 +434,163 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
// First user out // First user out
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .network-drop-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .network-drop-btn")).click();
for (int i = 0; i < 3; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("networkDisconnect", // for (int i = 0; i < 3; i++) {
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString()); Assertions.assertEquals("unpublish",
} CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 30).get("reason").getAsString());
Assertions.assertEquals("networkDisconnect", // }
Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
// Second user out // Second user out
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .network-drop-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .network-drop-btn")).click();
Assertions.assertEquals("networkDisconnect", Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 30).get("reason").getAsString());
Assertions.assertEquals("networkDisconnect", Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("lastParticipantLeft", Assertions.assertEquals("recordingStoppedByServer", // reason is always "recordingStoppedByServer" in v2Compatibility
CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString());
} }
Assertions.assertEquals("lastParticipantLeft", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // Assertions.assertEquals("lastParticipantLeft",
Assertions.assertEquals("lastParticipantLeft", // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("sessionClosedByServer", // reason is always "sessionClosedByServer" in v2Compatibility
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// mediaServerDisconnect: webrtcConnectionDestroyed, participantLeft, // mediaServerDisconnect: webrtcConnectionDestroyed, participantLeft,
// sessionDestroyed, recordingStatusChanged, broadcastStopped // sessionDestroyed, recordingStatusChanged, broadcastStopped
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); // this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
String mediaNodeId = restClient // String mediaNodeId = restClient
.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content") // .rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content")
.getAsJsonArray().get(0).getAsJsonObject().get("id").getAsString(); // .getAsJsonArray().get(0).getAsJsonObject().get("id").getAsString();
restClient.rest(HttpMethod.DELETE, // restClient.rest(HttpMethod.DELETE,
"/openvidu/api/media-nodes/" + mediaNodeId + "?wait=false&deletion-strategy=now", // "/openvidu/api/media-nodes/" + mediaNodeId + "?wait=false&deletion-strategy=now",
HttpURLConnection.HTTP_OK); // HttpURLConnection.HTTP_OK);
CustomWebhook.waitForEvent("mediaNodeStatusChanged", 3); // CustomWebhook.waitForEvent("mediaNodeStatusChanged", 3);
for (int i = 0; i < 4; i++) { // for (int i = 0; i < 4; i++) {
Assertions.assertEquals("mediaServerDisconnect", // Assertions.assertEquals("mediaServerDisconnect",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString()); // CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("mediaServerDisconnect", // Assertions.assertEquals("mediaServerDisconnect",
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("mediaServerDisconnect", // Assertions.assertEquals("mediaServerDisconnect",
CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString()); // CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString());
} // }
Assertions.assertEquals("mediaServerDisconnect", // Assertions.assertEquals("mediaServerDisconnect",
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("mediaServerDisconnect", // Assertions.assertEquals("mediaServerDisconnect",
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.waitForEvent("mediaNodeStatusChanged", 5); // CustomWebhook.waitForEvent("mediaNodeStatusChanged", 5);
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); // CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK); // restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK);
// mediaServerReconnect: webrtcConnectionDestroyed, recordingStatusChanged // mediaServerReconnect: webrtcConnectionDestroyed, recordingStatusChanged
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); // this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
String containerId = restClient // String containerId = restClient
.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content") // .rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK).get("content")
.getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString(); // .getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString();
MediaNodeDockerUtils.stopMediaServerInsideMediaNodeAndRecover(containerId, 400); // MediaNodeDockerUtils.stopMediaServerInsideMediaNodeAndRecover(containerId, 400);
for (int i = 0; i < 4; i++) { // for (int i = 0; i < 4; i++) {
Assertions.assertEquals("mediaServerReconnect", // Assertions.assertEquals("mediaServerReconnect",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 6).get("reason").getAsString()); // CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 6).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("mediaServerReconnect", // Assertions.assertEquals("mediaServerReconnect",
CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("recordingStatusChanged", 2).get("reason").getAsString());
} // }
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); // CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// nodeCrashed: webrtcConnectionDestroyed, participantLeft, sessionDestroyed, // nodeCrashed: webrtcConnectionDestroyed, participantLeft, sessionDestroyed,
// recordingStatusChanged, broadcastStopped // recordingStatusChanged, broadcastStopped
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); // this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
containerId = restClient.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK) // containerId = restClient.rest(HttpMethod.GET, "/openvidu/api/media-nodes", HttpURLConnection.HTTP_OK)
.get("content").getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString(); // .get("content").getAsJsonArray().get(0).getAsJsonObject().get("environmentId").getAsString();
MediaNodeDockerUtils.crashMediaNode(containerId); // MediaNodeDockerUtils.crashMediaNode(containerId);
JsonObject nodeCrashedEvent = CustomWebhook.waitForEvent("nodeCrashed", 10); // JsonObject nodeCrashedEvent = CustomWebhook.waitForEvent("nodeCrashed", 10);
Assertions.assertEquals(1, nodeCrashedEvent.get("recordingIds").getAsJsonArray().size()); // Assertions.assertEquals(1, nodeCrashedEvent.get("recordingIds").getAsJsonArray().size());
JsonArray affectedBroadcasts = nodeCrashedEvent.get("broadcasts").getAsJsonArray(); // JsonArray affectedBroadcasts = nodeCrashedEvent.get("broadcasts").getAsJsonArray();
Assertions.assertEquals(1, affectedBroadcasts.size()); // Assertions.assertEquals(1, affectedBroadcasts.size());
Assertions.assertTrue(affectedBroadcasts.get(0).equals(JsonParser.parseString("TestSession"))); // Assertions.assertTrue(affectedBroadcasts.get(0).equals(JsonParser.parseString("TestSession")));
CustomWebhook.waitForEvent("mediaNodeStatusChanged", 2); // CustomWebhook.waitForEvent("mediaNodeStatusChanged", 2);
for (int i = 0; i < 4; i++) { // for (int i = 0; i < 4; i++) {
Assertions.assertEquals("nodeCrashed", // Assertions.assertEquals("nodeCrashed",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("nodeCrashed", // Assertions.assertEquals("nodeCrashed",
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
} // }
// Only status "stopped" for recording. Not "ready" if node crash // // Only status "stopped" for recording. Not "ready" if node crash
Assertions.assertEquals("nodeCrashed", // Assertions.assertEquals("nodeCrashed",
CustomWebhook.waitForEvent("recordingStatusChanged", 10).get("reason").getAsString()); // CustomWebhook.waitForEvent("recordingStatusChanged", 10).get("reason").getAsString());
Assertions.assertEquals("nodeCrashed", // Assertions.assertEquals("nodeCrashed",
CustomWebhook.waitForEvent("broadcastStopped", 10).get("reason").getAsString()); // CustomWebhook.waitForEvent("broadcastStopped", 10).get("reason").getAsString());
Assertions.assertEquals("nodeCrashed", // Assertions.assertEquals("nodeCrashed",
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.waitForEvent("mediaNodeStatusChanged", 2); // CustomWebhook.waitForEvent("mediaNodeStatusChanged", 2);
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); // CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK); // restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK);
// openviduServerStopped: webrtcConnectionDestroyed, participantLeft, // openviduServerStopped: webrtcConnectionDestroyed, participantLeft,
// sessionDestroyed, recordingStatusChanged, broadcastStopped // sessionDestroyed, recordingStatusChanged, broadcastStopped
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); // this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK); // restartOpenViduServer(new HashMap<>(), true, HttpURLConnection.HTTP_OK);
for (int i = 0; i < 4; i++) { // for (int i = 0; i < 4; i++) {
Assertions.assertEquals("openviduServerStopped", // Assertions.assertEquals("openviduServerStopped",
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString()); // CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 20).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("openviduServerStopped", // Assertions.assertEquals("openviduServerStopped",
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
} // }
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
Assertions.assertEquals("openviduServerStopped", // Assertions.assertEquals("openviduServerStopped",
CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString()); // CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString());
} // }
Assertions.assertEquals("openviduServerStopped", // Assertions.assertEquals("openviduServerStopped",
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("openviduServerStopped", // Assertions.assertEquals("openviduServerStopped",
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); // CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
for (int i = 0; i < 2; i++) { // for (int i = 0; i < 2; i++) {
CustomWebhook.waitForEvent("mediaNodeStatusChanged", 15); // CustomWebhook.waitForEvent("mediaNodeStatusChanged", 15);
} // }
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); // CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// automaticStop: sessionDestroyed, recordingStatusChanged // automaticStop: sessionDestroyed, recordingStatusChanged
newConfig = Map.of("OPENVIDU_RECORDING_AUTOSTOP_TIMEOUT", 1); // newConfig = Map.of("OPENVIDU_RECORDING_AUTOSTOP_TIMEOUT", 1);
restartOpenViduServer(newConfig); // restartOpenViduServer(newConfig);
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-0 .leave-btn")).click();
user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .leave-btn")).click(); user.getDriver().findElement(By.cssSelector("#openvidu-instance-1 .leave-btn")).click();
for (int i = 0; i < 4; i++) { // webrtcConnectionDestroyed event is only triggered when participant left in v2Compatibility
Assertions.assertEquals("disconnect", for (int i = 0; i < 2; i++) {
Assertions.assertEquals("unpublish", // reason is always "unpublish" in v2Compatibility
CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("webrtcConnectionDestroyed", 2).get("reason").getAsString());
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("disconnect", Assertions.assertEquals("disconnect", // reason is always "disconnect" in v2Compatibility
CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("participantLeft", 2).get("reason").getAsString());
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
Assertions.assertEquals("automaticStop", Assertions.assertEquals("recordingStoppedByServer", // reason is always "recordingStoppedByServer" in v2Compatibility
CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString()); CustomWebhook.waitForEvent("recordingStatusChanged", 4).get("reason").getAsString());
} }
Assertions.assertEquals("lastParticipantLeft", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString()); // Assertions.assertEquals("lastParticipantLeft",
Assertions.assertEquals("automaticStop", // CustomWebhook.waitForEvent("broadcastStopped", 2).get("reason").getAsString());
Assertions.assertEquals("sessionClosedByServer", // reason is always "sessionClosedByServer" in v2Compatibility
CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString()); CustomWebhook.waitForEvent("sessionDestroyed", 2).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
// recordingStoppedByServer: recordingStatusChanged // recordingStoppedByServer: recordingStatusChanged
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
Thread.sleep(2000);
String recordingId = restClient String recordingId = restClient
.rest(HttpMethod.GET, "/openvidu/api/recordings", HttpURLConnection.HTTP_OK).get("items") .rest(HttpMethod.GET, "/openvidu/api/recordings", HttpURLConnection.HTTP_OK).get("items")
.getAsJsonArray().asList().stream() .getAsJsonArray().asList().stream()
@ -588,8 +609,9 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP); this.connectTwoUsers(user, restClient, false, true, BROADCAST_IP);
restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/stop", "{'session':'TestSession'}", restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/stop", "{'session':'TestSession'}",
HttpURLConnection.HTTP_OK); HttpURLConnection.HTTP_OK);
Assertions.assertEquals("broadcastStoppedByServer", // broadcastStopped does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
CustomWebhook.waitForEvent("broadcastStopped", 5).get("reason").getAsString()); // Assertions.assertEquals("broadcastStoppedByServer",
// CustomWebhook.waitForEvent("broadcastStopped", 5).get("reason").getAsString());
CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty())); CustomWebhook.events.values().forEach(collection -> Assertions.assertTrue(collection.isEmpty()));
} finally { } finally {
@ -3035,7 +3057,8 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
body = "{'session':'TestSession','broadcastUrl':'schemefail://" + BROADCAST_IP + "/live'}"; body = "{'session':'TestSession','broadcastUrl':'schemefail://" + BROADCAST_IP + "/live'}";
errorResponse = restClient.commonRestString(HttpMethod.POST, "/openvidu/api/broadcast/start", body, errorResponse = restClient.commonRestString(HttpMethod.POST, "/openvidu/api/broadcast/start", body,
HttpURLConnection.HTTP_BAD_REQUEST); HttpURLConnection.HTTP_BAD_REQUEST);
// Assertions.assertTrue(errorResponse.contains("schemefail://" + BROADCAST_IP + "/live: Protocol not found"), // Assertions.assertTrue(errorResponse.contains("schemefail://" + BROADCAST_IP +
// "/live: Protocol not found"),
// "Broadcast error message does not contain expected message"); // "Broadcast error message does not contain expected message");
// 404 // 404
body = "{'session':'NOT_EXISTS','broadcastUrl':'rtmp://" + BROADCAST_IP + "/live'}"; body = "{'session':'NOT_EXISTS','broadcastUrl':'rtmp://" + BROADCAST_IP + "/live'}";
@ -3054,18 +3077,22 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
+ "/live','hasAudio':false,'hasVideo':false}"; + "/live','hasAudio':false,'hasVideo':false}";
restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/start", body, 422); restClient.rest(HttpMethod.POST, "/openvidu/api/broadcast/start", body, 422);
// 500 (Connection refused) // 500 (Connection refused)
// body = "{'session':'TestSession','broadcastUrl':'rtmps://" + BROADCAST_IP + "/live'}"; // body = "{'session':'TestSession','broadcastUrl':'rtmps://" + BROADCAST_IP +
// errorResponse = restClient.commonRestString(HttpMethod.POST, "/openvidu/api/broadcast/start", body, // "/live'}";
// errorResponse = restClient.commonRestString(HttpMethod.POST,
// "/openvidu/api/broadcast/start", body,
// HttpURLConnection.HTTP_INTERNAL_ERROR); // HttpURLConnection.HTTP_INTERNAL_ERROR);
// Assertions.assertTrue( // Assertions.assertTrue(
// errorResponse.contains("Cannot open connection") // errorResponse.contains("Cannot open connection")
// && errorResponse.contains("rtmps://" + BROADCAST_IP + "/live: Connection refused"), // && errorResponse.contains("rtmps://" + BROADCAST_IP + "/live: Connection
// refused"),
// "Broadcast error message does not contain expected message"); // "Broadcast error message does not contain expected message");
// 500 (Input/output error) // 500 (Input/output error)
body = "{'session':'TestSession','broadcastUrl':'rtmp://not.exists'}"; body = "{'session':'TestSession','broadcastUrl':'rtmp://not.exists'}";
errorResponse = restClient.commonRestString(HttpMethod.POST, "/openvidu/api/broadcast/start", body, errorResponse = restClient.commonRestString(HttpMethod.POST, "/openvidu/api/broadcast/start", body,
HttpURLConnection.HTTP_INTERNAL_ERROR); HttpURLConnection.HTTP_INTERNAL_ERROR);
// Assertions.assertTrue(errorResponse.contains("rtmp://not.exists: Input/output error"), // Assertions.assertTrue(errorResponse.contains("rtmp://not.exists: Input/output
// error"),
// "Broadcast error message does not contain expected message"); // "Broadcast error message does not contain expected message");
// Concurrent broadcast // Concurrent broadcast
@ -3577,7 +3604,8 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
CustomWebhook.waitForEvent("participantJoined", 1); CustomWebhook.waitForEvent("participantJoined", 1);
} }
for (int i = 0; i < 4; i++) { // Only OUTBOUND events will be fired in V2Compatibility
for (int i = 0; i < 2; i++) {
CustomWebhook.waitForEvent("webrtcConnectionCreated", 1); CustomWebhook.waitForEvent("webrtcConnectionCreated", 1);
} }
if (startRecording) { if (startRecording) {
@ -3592,7 +3620,8 @@ public class OpenViduProTestAppE2eTest extends AbstractOpenViduTestappE2eTest {
"{'session':'TestSession','broadcastUrl':'rtmp://" + broadcastIp + "/live'}", "{'session':'TestSession','broadcastUrl':'rtmp://" + broadcastIp + "/live'}",
HttpURLConnection.HTTP_OK); HttpURLConnection.HTTP_OK);
user.getEventManager().waitUntilEventReaches("broadcastStarted", 2); user.getEventManager().waitUntilEventReaches("broadcastStarted", 2);
CustomWebhook.waitForEvent("broadcastStarted", 3); // broadcastStarted does not exist in the official OpenVidu docs and v2Compatibility does not trigger it
// CustomWebhook.waitForEvent("broadcastStarted", 3);
} }
} }

View File

@ -287,9 +287,9 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy {
this.subscribers = []; this.subscribers = [];
} }
private simulateNetworkDrop(): void { private async simulateNetworkDrop(): Promise<void> {
const jsonRpClient = (this.OV as any).jsonRpcClient; const jsonRpClient = this.OV.session.localParticipant.engine;
jsonRpClient.close(); await jsonRpClient.close();
} }
updateEventList(eventName: string, eventContent: string, event: Event) { updateEventList(eventName: string, eventContent: string, event: Event) {