@Test
public void testWebRtcSwitch() throws InterruptedException {
// Media pipeline
MediaPipeline mp = pipelineFactory.create();
WebRtcEndpoint webRtcEndpoint1 = mp.newWebRtcEndpoint().build();
WebRtcEndpoint webRtcEndpoint2 = mp.newWebRtcEndpoint().build();
WebRtcEndpoint webRtcEndpoint3 = mp.newWebRtcEndpoint().build();
webRtcEndpoint1.connect(webRtcEndpoint1);
webRtcEndpoint2.connect(webRtcEndpoint2);
webRtcEndpoint3.connect(webRtcEndpoint3);
BrowserClient.Builder builderWebrtc = new BrowserClient.Builder()
.browser(Browser.CHROME).client(Client.WEBRTC);
try (BrowserClient browser1 = builderWebrtc.build();
BrowserClient browser2 = builderWebrtc.build();
BrowserClient browser3 = builderWebrtc.build()) {
// Start WebRTC in loopback in each browser
browser1.subscribeEvents("playing");
browser1.connectToWebRtcEndpoint(webRtcEndpoint1,
WebRtcChannel.AUDIO_AND_VIDEO);
// Delay time (to avoid the same timing in videos)
Thread.sleep(1000);
// Browser 2
browser2.subscribeEvents("playing");
browser2.connectToWebRtcEndpoint(webRtcEndpoint2,
WebRtcChannel.AUDIO_AND_VIDEO);
// Delay time (to avoid the same timing in videos)
Thread.sleep(1000);
// Browser 3
browser3.subscribeEvents("playing");
browser3.connectToWebRtcEndpoint(webRtcEndpoint3,
WebRtcChannel.AUDIO_AND_VIDEO);
// Wait until event playing in the remote streams
Assert.assertTrue("Timeout waiting playing event",
browser1.waitForEvent("playing"));
Assert.assertTrue("Timeout waiting playing event",
browser2.waitForEvent("playing"));
Assert.assertTrue("Timeout waiting playing event",
browser3.waitForEvent("playing"));
// Guard time to see each browser in loopback
Thread.sleep(4000);
assertColor(browser1, browser2, browser3);
// Switching (round #1)
webRtcEndpoint1.connect(webRtcEndpoint2);
webRtcEndpoint2.connect(webRtcEndpoint3);
webRtcEndpoint3.connect(webRtcEndpoint1);
assertColor(browser1, browser2, browser3);
// Guard time to see switching #1
Thread.sleep(4000);
// Switching (round #2)
webRtcEndpoint1.connect(webRtcEndpoint3);
webRtcEndpoint2.connect(webRtcEndpoint1);
webRtcEndpoint3.connect(webRtcEndpoint2);
assertColor(browser1, browser2, browser3);
// Guard time to see switching #2
Thread.sleep(4000);
}