diff --git a/openvidu-test-e2e/README.md b/openvidu-test-e2e/README.md deleted file mode 100644 index 5cffa53e..00000000 --- a/openvidu-test-e2e/README.md +++ /dev/null @@ -1,12 +0,0 @@ -[![License badge](https://img.shields.io/badge/license-Apache2-orange.svg)](http://www.apache.org/licenses/LICENSE-2.0) -[![Documentation badge](https://readthedocs.org/projects/fiware-orion/badge/?version=latest)](http://openvidu.io/docs/home/) -[![Support badge](https://img.shields.io/badge/support-sof-yellowgreen.svg)](https://groups.google.com/forum/#!forum/openvidu) - -[![][OpenViduLogo]](http://openvidu.io) - -openvidu-test-e2e -=== - -end2end tests for OpenVidu. Implemented with [Cucumber](https://cucumber.io/) framework, ready to work with [openvidu-insecure-js](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-insecure-js), [openvidu-insecure-angular](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-insecure-angular), [openvidu-js-java](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-js-java), [openvidu-js-node](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-js-node), [openvidu-mvc-java](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-mvc-java), [openvidu-mvc-node](https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-mvc-node). - -[OpenViduLogo]: https://secure.gravatar.com/avatar/5daba1d43042f2e4e85849733c8e5702?s=120 diff --git a/openvidu-test-e2e/pom.xml b/openvidu-test-e2e/pom.xml index 662dc8d3..42e1ed81 100644 --- a/openvidu-test-e2e/pom.xml +++ b/openvidu-test-e2e/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - + io.openvidu openvidu-parent @@ -9,47 +9,142 @@ openvidu-test-e2e + 1.1.1 jar OpenVidu Test e2e - e2e tests for OpenVidu Tutorials - http://maven.apache.org + End2End tests for OpenVidu TestApp + http://openvidu.io + + + + Apache 2.0 + http://www.apache.org/licenses/LICENSE-2.0 + repo + + + + + OpenVidu + http://openvidu.io + + + + https://github.com/OpenVidu/openvidu.git + scm:git:https://github.com/OpenVidu/openvidu.git + scm:git:https://github.com/OpenVidu/openvidu.git + develop + + + + + openvidu.io + -openvidu.io Community + openvidu.io + http://openvidu.io + + - UTF-8 - example.openvidu.testapp.cucumbertest.TestRunner + 1.8 - 1.8 - 1.8 + ${java.version} + ${java.version} + + + UTF-8 + UTF-8 + + + 5.0.0 + 1.0.0 + 1.1.2 + 1.7.25 + + + 2.19.1 + 0.7.9 - junit - junit + org.junit.jupiter + junit-jupiter-api + ${junit.jupiter.version} + test + + + io.github.bonigarcia + selenium-jupiter + ${selenium-jupiter.version} + test + + + + + org.seleniumhq.selenium + selenium-java + 3.4.0 test org.seleniumhq.selenium - selenium-java - - - info.cukes - cucumber-java - 1.2.5 - - - - info.cukes - cucumber-core - 1.2.5 + selenium-chrome-driver + 3.4.0 test - - info.cukes - cucumber-junit - 1.2.5 + org.seleniumhq.selenium + selenium-firefox-driver + 3.4.0 + test + + + org.seleniumhq.selenium + selenium-api + 3.4.0 + test + + + org.seleniumhq.selenium + selenium-remote-driver + 3.4.0 + test + + + com.google.guava + guava + 21.0 + test + + + + + org.slf4j + slf4j-api + test + + + + org.junit.platform + junit-platform-runner + 1.0.1 + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + + + com.googlecode.json-simple + json-simple + + + xml-apis + xml-apis + 1.4.01 + diff --git a/openvidu-test-e2e/src/main/features/test.feature b/openvidu-test-e2e/src/main/features/test.feature deleted file mode 100644 index 1c2ece0f..00000000 --- a/openvidu-test-e2e/src/main/features/test.feature +++ /dev/null @@ -1,27 +0,0 @@ -Feature: Connecting To Session - IN ORDER TO complete a bidirectional communication - AS a regular user - I WANT TO check the WebRTC connections between two peers - - Scenario Outline: Users connect to the same session - Given Chrome users and Firefox users go to "http://localhost:5000" page with seconds - And users fill "participantId" input - And users fill "sessionId" input with session name - When users click on "commit" button - Then users should see title in element with id "session-header" - And "1" video element/s should be shown in element with id "main-video" - And "1" video element/s in "main-video" should be playing media - And users should see other users nicknames - And all video elements should be shown in element with id "video-container" - And all video elements in "video-container" should be playing media - And leave session - And see "Join a video session" text in "h1" element - And div "video-container" should have videos - And close all browsers - - Examples: - | chromeUsers | firefoxUsers | session | secondsOfWait | - | ['User1'] | ['User2'] | Session1 | 7 | - | ['User1', 'User3'] | ['User2'] | Session2 | 7 | - | ['User1'] | ['User2', 'User3'] | Session3 | 7 | - | ['User1', 'User3'] | ['User2', 'User4'] | Session4 | 10 | \ No newline at end of file diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java new file mode 100644 index 00000000..216e0569 --- /dev/null +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduEventManager.java @@ -0,0 +1,156 @@ +package io.openvidu.test.e2e; + +import java.util.Map; +import java.util.Queue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class OpenViduEventManager { + + private static class RunnableCallback implements Runnable { + + private final Consumer callback; + private JSONObject eventResult; + + public RunnableCallback(Consumer callback) { + this.callback = callback; + } + + public void setEventResult(JSONObject json) { + this.eventResult = json; + } + + @Override + public void run() { + callback.accept(this.eventResult); + } + } + + private Thread pollingThread; + private ExecutorService execService = Executors.newCachedThreadPool(); + private final int LATCH_TIMEOUT = 10000; + private WebDriver driver; + private WebDriverWait waiter; + private Queue eventQueue; + private Map eventCallbacks; + private Map eventNumbers; + private Map eventCountdowns; + private AtomicBoolean isInterrupted = new AtomicBoolean(false); + + public OpenViduEventManager(WebDriver driver, WebDriverWait waiter) { + this.driver = driver; + this.waiter = waiter; + this.eventQueue = new ConcurrentLinkedQueue(); + this.eventCallbacks = new ConcurrentHashMap<>(); + this.eventNumbers = new ConcurrentHashMap<>(); + this.eventCountdowns = new ConcurrentHashMap<>(); + } + + public void startPolling() { + + this.pollingThread = new Thread(() -> { + while (!this.isInterrupted.get()) { + this.getEventsFromBrowser(); + this.emitEvents(); + } + }); + this.pollingThread.start(); + } + + public void stopPolling() { + this.eventCallbacks.clear(); + this.eventCountdowns.clear(); + this.eventNumbers.clear(); + this.isInterrupted.set(true); + this.pollingThread.interrupt(); + } + + public void on(String eventName, Consumer callback) { + this.eventCallbacks.put(eventName, new RunnableCallback(callback)); + } + + public void waitUntilNumberOfEvent(String eventName, int eventNumber) { + CountDownLatch eventSignal = new CountDownLatch(eventNumber); + this.setCountDown(eventName, eventSignal); + try { + if (!eventSignal.await(LATCH_TIMEOUT, TimeUnit.MILLISECONDS)) { + throw(new TimeoutException()); + } + } catch (InterruptedException | TimeoutException e) { + e.printStackTrace(); + } + } + + private AtomicInteger getNumEvents(String eventName) { + return this.eventNumbers.computeIfAbsent(eventName, k -> new AtomicInteger(0)); + } + + private void setCountDown(String eventName, CountDownLatch cd) { + this.eventCountdowns.put(eventName, cd); + for(int i=0; i< getNumEvents(eventName).get(); i++){ + cd.countDown(); + } + } + + private void emitEvents() { + while (!this.eventQueue.isEmpty()) { + JSONObject event = this.eventQueue.poll(); + + System.out.println(event.get("event") + ": " + event); + + RunnableCallback callback = this.eventCallbacks.get(event.get("event")); + if (callback != null) { + callback.setEventResult(event); + execService.submit(callback); + } + } + } + + private void getEventsFromBrowser() { + String rawEvents = this.getAndClearEventsInBrowser(); + + if (rawEvents == null || rawEvents.length() == 0) { + return; + } + + String[] events = rawEvents.replaceFirst("^
", "").split("
"); + JSONParser parser = new JSONParser(); + for (String e : events) { + try { + JSONObject event = (JSONObject) parser.parse(e); + String eventName = (String) event.get("event"); + + this.eventQueue.add(event); + getNumEvents(eventName).incrementAndGet(); + + if (this.eventCountdowns.get(eventName) != null) { + this.eventCountdowns.get(eventName).countDown(); + } + } catch (ParseException exc) { + exc.printStackTrace(); + } + } + } + + private String getAndClearEventsInBrowser() { + String events = (String) ((JavascriptExecutor) driver) + .executeScript("var e = window.myEvents; window.myEvents = ''; return e;"); + return events; + } + +} diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java new file mode 100644 index 00000000..8e056057 --- /dev/null +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/OpenViduTestAppE2eTest.java @@ -0,0 +1,162 @@ +package io.openvidu.test.e2e; +/* + * (C) Copyright 2017-2019 OpenVideo (http://openvidu.io/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import static java.lang.invoke.MethodHandles.lookup; +import static org.slf4j.LoggerFactory.getLogger; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.runner.RunWith; +import org.junit.platform.runner.JUnitPlatform; +import org.openqa.selenium.By; +import org.slf4j.Logger; + +import io.github.bonigarcia.SeleniumExtension; +import io.openvidu.test.e2e.browser.ChromeUser; +import io.openvidu.test.e2e.browser.FirefoxUser; + + +/** + * E2E test for openvidu-testapp. + * + * @author Pablo Fuente (pablo.fuente@urjc.es) + * @since 1.1.1 + */ +@Tag("e2e") +@DisplayName("E2E tests for OpenVidu TestApp") +@ExtendWith(SeleniumExtension.class) +@RunWith(JUnitPlatform.class) +public class OpenViduTestAppE2eTest { + + final Logger log = getLogger(lookup().lookupClass()); + + final String DEFAULT_SESSION_NAME = "TestSession"; + + String testAppUrl = "http://localhost:4200/"; // default value (local) + + @BeforeEach + void setup() { + + } + + @Test + @DisplayName("One2One [Video + Audio] session") + void oneToOneVideoAudioSession() throws InterruptedException { + + FirefoxUser user = new FirefoxUser("TestUser", 10); + user.getEventManager().startPolling(); + + log.debug("Navigate to openvidu-testapp and click on 1:1 scenario"); + + user.getDriver().get(testAppUrl); + user.getDriver().findElement(By.id("auto-join-checkbox")).click(); + user.getDriver().findElement(By.id("one2one-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("videoPlaying", 4); + + user.getDriver().findElement(By.id("remove-user-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("streamDestroyed", 1); + user.getEventManager().waitUntilNumberOfEvent("sessionDisconnected", 1); + + user.getDriver().findElement(By.id("remove-user-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("sessionDisconnected", 2); + + user.dispose(); + } + + @Test + @DisplayName("One2Many [Video + Audio] session") + void oneToManyVideoAudioSession() throws InterruptedException { + + ChromeUser user = new ChromeUser("TestUser", 10); + user.getEventManager().startPolling(); + + log.debug("Navigate to openvidu-testapp and click on 1:N scenario"); + + user.getDriver().get(testAppUrl); + user.getDriver().findElement(By.id("auto-join-checkbox")).click(); + user.getDriver().findElement(By.id("one2many-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("videoPlaying", 4); + + user.getDriver().findElements(By.className(("leave-btn"))).get(0).click(); + + user.getEventManager().waitUntilNumberOfEvent("streamDestroyed", 3); + + user.dispose(); + } + + @Test + @DisplayName("Unique user remote subscription [Video + Audio]") + void oneRemoteSubscription() throws InterruptedException { + + ChromeUser user = new ChromeUser("TestUser", 10); + user.getEventManager().startPolling(); + + log.debug("Navigate to openvidu-testapp and join one user with remote subscription"); + + user.getDriver().get(testAppUrl); + user.getDriver().findElement(By.id("add-user-btn")).click(); + user.getDriver().findElement(By.className("subscribe-remote-check")).click(); + user.getDriver().findElement(By.id("join-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("connectionCreated", 1); + user.getEventManager().waitUntilNumberOfEvent("accessAllowed", 1); + user.getEventManager().waitUntilNumberOfEvent("videoElementCreated", 1); + user.getEventManager().waitUntilNumberOfEvent("remoteVideoPlaying", 1); + + user.getDriver().findElement(By.className(("leave-btn"))).click(); + + user.getEventManager().waitUntilNumberOfEvent("sessionDisconnected", 1); + + user.dispose(); + } + + @Test + @DisplayName("Unique user remote subscription [ScreenShare + Audio]") + void oneRemoteSubscriptionScreen() throws InterruptedException { + + ChromeUser user = new ChromeUser("TestUser", 10); + user.getEventManager().startPolling(); + + log.debug("Navigate to openvidu-testapp and join one user with remote subscription"); + + user.getDriver().get(testAppUrl); + user.getDriver().findElement(By.id("add-user-btn")).click(); + user.getDriver().findElement(By.className("screen-radio")).click(); + user.getDriver().findElement(By.className("subscribe-remote-check")).click(); + user.getDriver().findElement(By.id("join-btn")).click(); + + user.getEventManager().waitUntilNumberOfEvent("connectionCreated", 1); + user.getEventManager().waitUntilNumberOfEvent("accessAllowed", 1); + user.getEventManager().waitUntilNumberOfEvent("videoElementCreated", 1); + user.getEventManager().waitUntilNumberOfEvent("remoteVideoPlaying", 1); + + user.getDriver().findElement(By.className(("leave-btn"))).click(); + + user.getEventManager().waitUntilNumberOfEvent("sessionDisconnected", 1); + + user.dispose(); + } + +} diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/BrowserUser.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/BrowserUser.java new file mode 100644 index 00000000..8c7a63eb --- /dev/null +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/BrowserUser.java @@ -0,0 +1,54 @@ +package io.openvidu.test.e2e.browser; + +import java.util.concurrent.TimeUnit; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.openvidu.test.e2e.OpenViduEventManager; + +public class BrowserUser { + + protected WebDriver driver; + protected WebDriverWait waiter; + protected String clientData; + protected int timeOfWait; + protected OpenViduEventManager eventManager; + + public BrowserUser(String clientData, int timeOfWait) { + this.clientData = clientData; + this.timeOfWait = timeOfWait; + } + + public WebDriver getDriver() { + return this.driver; + } + + public WebDriverWait getWaiter() { + return this.waiter; + } + + public OpenViduEventManager getEventManager() { + return this.eventManager; + } + + public String getClientData() { + return this.clientData; + } + + protected void newWaiter(int timeOfWait) { + this.waiter = new WebDriverWait(this.driver, timeOfWait); + } + + protected void configureDriver() { + this.waiter = new WebDriverWait(this.driver, this.timeOfWait); + this.driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + this.eventManager = new OpenViduEventManager(this.driver, this.waiter); + } + + public void dispose() { + this.eventManager.stopPolling(); + this.driver.quit(); + } + +} \ No newline at end of file diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/ChromeUser.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/ChromeUser.java new file mode 100644 index 00000000..e9434ead --- /dev/null +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/ChromeUser.java @@ -0,0 +1,37 @@ +package io.openvidu.test.e2e.browser; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.springframework.core.io.ClassPathResource; + +public class ChromeUser extends BrowserUser { + + public ChromeUser(String userName, int timeOfWait) { + super(userName, timeOfWait); + + System.setProperty("webdriver.chrome.driver", "/home/chromedriver"); + + ChromeOptions options = new ChromeOptions(); + // This flag avoids to grant the user media + options.addArguments("--use-fake-ui-for-media-stream"); + // This flag fakes user media with synthetic video + options.addArguments("--use-fake-device-for-media-stream"); + // This flag selects the entire screen as video source when screen sharing + options.addArguments("--auto-select-desktop-capture-source=Entire screen"); + + try { + // Add Screen Sharing extension + options.addExtensions(new ClassPathResource("ScreenCapturing.crx").getFile()); + } catch (IOException e) { + e.printStackTrace(); + } + + this.driver = new ChromeDriver(options); + this.driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS); + + this.configureDriver(); + } + +} \ No newline at end of file diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/FirefoxUser.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/FirefoxUser.java similarity index 85% rename from openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/FirefoxUser.java rename to openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/FirefoxUser.java index ba2d1030..0f2a6a0e 100644 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/FirefoxUser.java +++ b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/browser/FirefoxUser.java @@ -1,14 +1,15 @@ -package io.openvidu.test.e2e.cucumbertest; +package io.openvidu.test.e2e.browser; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; -import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class FirefoxUser extends BrowserUser { public FirefoxUser(String userName, int timeOfWait) { super(userName, timeOfWait); + + System.setProperty("webdriver.gecko.driver", "/home/geckodriver"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("acceptInsecureCerts", true); @@ -21,9 +22,10 @@ public class FirefoxUser extends BrowserUser { profile.setPreference("media.navigator.streams.fake", true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); - this.driver = new FirefoxDriver(capabilities); - this.configWaiterAndScript(); + this.driver = new FirefoxDriver(capabilities); + + this.configureDriver(); } -} +} \ No newline at end of file diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/BrowserUser.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/BrowserUser.java deleted file mode 100644 index 00711099..00000000 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/BrowserUser.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.openvidu.test.e2e.cucumbertest; - -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.WebDriverWait; - -public class BrowserUser { - - protected WebDriver driver; - protected WebDriverWait waiter; - protected String userName; - - private int timeOfWait; - - public BrowserUser(String userName, int timeOfWait) { - this.userName = userName; - this.timeOfWait = timeOfWait; - } - - public WebDriver getDriver() { - return this.driver; - } - - public WebDriverWait getWaiter() { - return this.waiter; - } - - public String getUserName() { - return this.userName; - } - - public Object runJavascript(String script, Object... args) { - return ((JavascriptExecutor)this.driver).executeScript(script, args); - } - - public void navigateTo(String url){ - this.driver.get(url); - - String scriptAppend = "var s = document.createElement('script'); " + "s.type = 'text/javascript';" - + "s.innerHTML = arguments[0];" + "document.body.appendChild(s);"; - - String scriptContent = "window['MY_FUNC']= function(videoOwner) { " - + "var elem = document.createElement('div');" + "elem.id = videoOwner + '-video-is-playing';" - + "document.body.appendChild(elem); " - + "document.getElementById(videoOwner + '-video-is-playing').innerHTML = (videoOwner + ' VIDEO PLAYING')" - + "}"; - this.runJavascript(scriptAppend, scriptContent); - } - - protected void configWaiterAndScript() { - this.waiter = new WebDriverWait(this.driver, this.timeOfWait); - } -} diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/ChromeUser.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/ChromeUser.java deleted file mode 100644 index 4d3d911a..00000000 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/ChromeUser.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.openvidu.test.e2e.cucumbertest; - -import java.util.concurrent.TimeUnit; - -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; - -public class ChromeUser extends BrowserUser { - - public ChromeUser(String userName, int timeOfWait) { - super(userName, timeOfWait); - - System.setProperty("webdriver.chrome.driver", "/home/pablo/Downloads/chromedriver"); - - ChromeOptions options = new ChromeOptions(); - // This flag avoids to grant the user media - options.addArguments("--use-fake-ui-for-media-stream"); - // This flag fakes user media with synthetic video (green with spinner - // and timer) - options.addArguments("--use-fake-device-for-media-stream"); - - this.driver = new ChromeDriver(options); - this.driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS); - - this.configWaiterAndScript(); - } - -} diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/TestRunner.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/TestRunner.java deleted file mode 100644 index 1fd1cb41..00000000 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/cucumbertest/TestRunner.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.openvidu.test.e2e.cucumbertest; - -import org.junit.runner.RunWith; -import cucumber.api.CucumberOptions; -import cucumber.api.junit.Cucumber; - -@RunWith(Cucumber.class) -@CucumberOptions( - features = "src/main/features" - ,glue={"io/openvidu/test/e2e/stepdefinition"} - ) -public class TestRunner { } \ No newline at end of file diff --git a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/stepdefinition/StepsConnectingToSession.java b/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/stepdefinition/StepsConnectingToSession.java deleted file mode 100644 index ef2f8a97..00000000 --- a/openvidu-test-e2e/src/main/java/io/openvidu/test/e2e/stepdefinition/StepsConnectingToSession.java +++ /dev/null @@ -1,216 +0,0 @@ -package io.openvidu.test.e2e.stepdefinition; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - -import org.junit.Assert; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.ui.ExpectedConditions; - -import cucumber.api.java.en.And; -import cucumber.api.java.en.Given; -import cucumber.api.java.en.Then; -import cucumber.api.java.en.When; -import io.openvidu.test.e2e.cucumbertest.BrowserUser; -import io.openvidu.test.e2e.cucumbertest.ChromeUser; -import io.openvidu.test.e2e.cucumbertest.FirefoxUser; - -public class StepsConnectingToSession { - - public final int numDrivers = 2; - public Map browserUsers = new ConcurrentHashMap<>(); - - @Given("^Chrome users (.+) and Firefox users (.+) go to \"([^\"]*)\" page with (.+) seconds$") - public void chrome_users_and_firefox_users_go_to_something_page_with_seconds(String chromeusers, - String firefoxusers, String strArg1, String secondsOfWait) throws Throwable { - - // List of Chrome users - List chromeNames = fromArrayStringifyToList(chromeusers); - - // List of Firefox users - List firefoxNames = fromArrayStringifyToList(firefoxusers); - - for (String name : chromeNames) { - browserUsers.put(name, new ChromeUser(name, Integer.parseInt(secondsOfWait))); - } - for (String name : firefoxNames) { - browserUsers.put(name, new FirefoxUser(name, Integer.parseInt(secondsOfWait))); - } - - for (BrowserUser user : this.browserUsers.values()) { - user.navigateTo(strArg1); - } - } - - @When("^users click on \"([^\"]*)\" button$") - public void users_click_on_something_button(String strArg1) throws Throwable { - for (BrowserUser user : browserUsers.values()) { - user.getDriver().findElement(By.name(strArg1)).click(); - } - } - - @Then("^users should see title (.+) in element with id \"([^\"]*)\"$") - public void users_should_see_title_in_element_with_id_something(String session, String strArg1) throws Throwable { - for (BrowserUser user : browserUsers.values()) { - Assert.assertTrue(user.getWaiter().until(ExpectedConditions - .textToBePresentInElement(user.getDriver().findElement(By.id(strArg1)), session))); - } - } - - @And("^users fill \"([^\"]*)\" input$") - public void users_fill_something_input(String strArg1) throws Throwable { - for (Entry entry : this.browserUsers.entrySet()) { - WebElement nicknameInput = entry.getValue().getDriver().findElement(By.id(strArg1)); - nicknameInput.clear(); - nicknameInput.sendKeys(entry.getKey()); - } - } - - @And("^users fill \"([^\"]*)\" input with session name (.+)$") - public void users_fill_something_input_with_session_name(String session, String strArg1) throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - WebElement sessionInput = user.getDriver().findElement(By.id(session)); - sessionInput.clear(); - sessionInput.sendKeys(strArg1); - } - } - - @And("^\"([^\"]*)\" video element/s should be shown in element with id \"([^\"]*)\"$") - public void something_video_elements_should_be_shown_in_element_with_id_something(String strArg1, String strArg2) - throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#" + strArg2 + " video"), Integer.parseInt(strArg1))); - }).run(); - } - } - - @And("^\"([^\"]*)\" video element/s in \"([^\"]*)\" should be playing media$") - public void something_video_elements_in_something_should_be_playing_media(String strArg1, String strArg2) - throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - List videos = user.getDriver().findElements(By.cssSelector("#" + strArg2 + " video")); - int numOfVideosPlaying = 0; - for (int i = 0; i < videos.size(); i++) { - if (this.checkVideoPlaying(user, videos.get(i), strArg2)) { - numOfVideosPlaying++; - } - } - Assert.assertEquals(numOfVideosPlaying, Integer.parseInt(strArg1)); - }).run(); - } - } - - @And("^all video elements should be shown in element with id \"([^\"]*)\"$") - public void all_video_elements_should_be_shown_in_element_with_id_something(String strArg1) throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - user.getWaiter().until(ExpectedConditions.numberOfElementsToBe(By.cssSelector("#" + strArg1 + " video"), this.browserUsers.size())); - }).run(); - } - } - - @And("^all video elements in \"([^\"]*)\" should be playing media$") - public void all_video_elements_in_something_should_be_playing_media(String strArg1) throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - List videos = user.getDriver().findElements(By.cssSelector("#" + strArg1 + " video")); - int numOfVideosPlaying = 0; - for (int i = 0; i < videos.size(); i++) { - if (this.checkVideoPlaying(user, videos.get(i), strArg1)) { - numOfVideosPlaying++; - } - } - Assert.assertEquals(numOfVideosPlaying, this.browserUsers.size()); - }).run(); - } - } - - @Then("^users should see other users nicknames$") - public void users_should_see_other_users_nicknames_in_paragraph_element() throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - for (Entry entry : this.browserUsers.entrySet()) { - user.getWaiter().until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("#data-" + entry.getKey() + " p"), entry.getKey())); - } - }).run(); - } - } - - @And("^(.+) leave session$") - public void leave_session(String firefoxusers) throws Throwable { - List firefoxUsers = this.fromArrayStringifyToList(firefoxusers); - for (String user : firefoxUsers) { - new Thread(() -> { - this.browserUsers.get(user).getDriver().findElement(By.id("buttonLeaveSession")).click(); - }).run(); - } - } - - @And("^(.+) see \"([^\"]*)\" text in \"([^\"]*)\" element$") - public void see_something_text_in_something_element(String firefoxusers, String strArg1, String strArg2) - throws Throwable { - List firefoxUsers = this.fromArrayStringifyToList(firefoxusers); - for (String user : firefoxUsers) { - Assert.assertEquals((this.browserUsers.get(user).getDriver().findElement(By.tagName(strArg2)).getText()), - strArg1); - } - } - - @And("^(.+) div \"([^\"]*)\" should have (.+) videos$") - public void div_something_should_have_videos(String usersInRoom, String strArg1, String usersInRoom2) - throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - new Thread(() -> { - List users = this.fromArrayStringifyToList(usersInRoom); - if (users.contains(user.getUserName())) { - for (String u : users) { - user.getWaiter().until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#" + strArg1 + " video#" + "native-video-" + u + "_webcam"))); - } - } - }).run(); - } - } - - @And("^close all browsers$") - public void close_all_browsers() throws Throwable { - for (BrowserUser user : this.browserUsers.values()) { - user.getDriver().quit(); - } - } - - private List fromArrayStringifyToList(String arrayStringify) { - String[] tokens = arrayStringify.substring(2, arrayStringify.length() - 2).split("'(\\s)*,(\\s)*'"); - return Arrays.asList(tokens); - } - - private boolean checkVideoPlaying(BrowserUser user, WebElement videoElement, String containerId) { - - // Video element should be in 'readyState'='HAVE_ENOUGH_DATA' - user.getWaiter().until(ExpectedConditions.attributeToBe(videoElement, "readyState", "4")); - // Video should have a valid 'src' value - user.getWaiter().until(ExpectedConditions.attributeToBeNotEmpty(videoElement, "src")); - // Video should have a srcObject (type MediaStream) with the - // attribute 'active' to true - Boolean activeSrcObject = (Boolean) user.runJavascript("return document.getElementById('" + containerId - + "').getElementsByTagName('video')[0].srcObject.active"); - Assert.assertTrue(activeSrcObject); - // Video should trigger 'playing' event - user.runJavascript("document.getElementById('" + videoElement.getAttribute("id") - + "').addEventListener('playing', window.MY_FUNC('" + containerId + "'))"); - user.getWaiter() - .until(ExpectedConditions.textToBePresentInElement( - user.getDriver().findElement(By.id(containerId + "-video-is-playing")), - containerId + " VIDEO PLAYING")); - user.runJavascript( - "document.body.removeChild(document.getElementById('" + containerId + "-video-is-playing'))"); - - return true; - } - -} diff --git a/openvidu-test-e2e/src/test/java/example/openvidu/testapp/AppTest.java b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/tes/AppTest.java similarity index 94% rename from openvidu-test-e2e/src/test/java/example/openvidu/testapp/AppTest.java rename to openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/tes/AppTest.java index b99593e4..64aaa69a 100644 --- a/openvidu-test-e2e/src/test/java/example/openvidu/testapp/AppTest.java +++ b/openvidu-test-e2e/src/test/java/io/openvidu/test/e2e/tes/AppTest.java @@ -1,4 +1,4 @@ -package example.openvidu.testapp; +package io.openvidu.test.e2e.tes; import junit.framework.Test; import junit.framework.TestCase; diff --git a/openvidu-test-e2e/src/test/resources/ScreenCapturing.crx b/openvidu-test-e2e/src/test/resources/ScreenCapturing.crx new file mode 100644 index 00000000..804ac3bc Binary files /dev/null and b/openvidu-test-e2e/src/test/resources/ScreenCapturing.crx differ diff --git a/openvidu-test-e2e/src/test/resources/simplelogger.properties b/openvidu-test-e2e/src/test/resources/simplelogger.properties new file mode 100644 index 00000000..9983e130 --- /dev/null +++ b/openvidu-test-e2e/src/test/resources/simplelogger.properties @@ -0,0 +1,7 @@ +org.slf4j.simpleLogger.defaultLogLevel=DEBUG +org.slf4j.simpleLogger.logFile=System.out +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.dateTimeFormat=[yyyy-MM-dd HH:mm:ss:SSS] +org.slf4j.simpleLogger.showThreadName=true +org.slf4j.simpleLogger.showLogName=true +org.slf4j.simpleLogger.showShortLogName=true diff --git a/openvidu-testapp/cert.pem b/openvidu-testapp/cert.pem new file mode 100644 index 00000000..116e7337 --- /dev/null +++ b/openvidu-testapp/cert.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDUTCCAjmgAwIBAgIJAOQFplq7ejUaMA0GCSqGSIb3DQEBCwUAMD8xFjAUBgNV +BAMMDXd3dy5teWRvbS5jb20xGDAWBgNVBAoMD015IENvbXBhbnkgTFRELjELMAkG +A1UEBhMCVVMwHhcNMTcxMDAzMTIxMTU5WhcNMjcxMDAxMTIxMTU5WjA/MRYwFAYD +VQQDDA13d3cubXlkb20uY29tMRgwFgYDVQQKDA9NeSBDb21wYW55IExURC4xCzAJ +BgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6ymIS6N0 +RDQD/hAFUzPZkY4dKOfiRLATTa1EZsssTdPE8FiAYVua+jW5Zm3LFFQ5BMIeJjCZ +jbJFSMSEjC9aNPsqTGc6zeHaBfrJnTxY7nBOv9dAHrhDHs8nuwGwTY3kYUu+r5kd +VEZHht5RRw0wE1PUrXhBKWnziuXnpbx5XWOgk9afn6pf4IfzSlDM7Mgk8ZtEmajy +2TB1okTd7h+pHhGOwKGSGrjY0cCLZwq3B06R4/wuLejJYTm3/QB5dPJnEzZxsXE+ +QXmAP3a4uEsUzyYBK0gW10Xj/EM33VLqepXYAe0T6F8PCqSjeumxhCla520L5Fvl +oBLJ4r2h7XspLwIDAQABo1AwTjAdBgNVHQ4EFgQU3OjBfIpR6o3ALB9JCfq11RYy +AZwwHwYDVR0jBBgwFoAU3OjBfIpR6o3ALB9JCfq11RYyAZwwDAYDVR0TBAUwAwEB +/zANBgkqhkiG9w0BAQsFAAOCAQEAV43AXlj01X3FM6XbdENObBZuHM18ioF/Kw1R +LFXM/ANrNrYRYSHSXuw9N3/WHS68vb5FLnOAkY/oWNBtdPcLOrgcn+Prp2HMAJOj +4eSWEzbT3JGIoPMbxGEGFUalrHU43MzeQbrjCML83BjuLZDe1Nx5r4DJqRcETHyr +SV3spwS2gvhw51cOIVKrYfeB+WYuDd1BPeWgWcQaQgMK9HyMX2XiydwpZAUSHCpq +UrvDU/QHQ5s0hqCmmj2iSTLiP4rwFCsTWTSrYdugntgWlN1RlZInoP4D/NUH2xiY +LhIzviKmNeIqlkLGd1GyC2FQy49SW2SlmAqqq33etjt8b288Yg== +-----END CERTIFICATE----- diff --git a/openvidu-testapp/key.pem b/openvidu-testapp/key.pem new file mode 100644 index 00000000..e4cc45c1 --- /dev/null +++ b/openvidu-testapp/key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDrKYhLo3RENAP+ +EAVTM9mRjh0o5+JEsBNNrURmyyxN08TwWIBhW5r6NblmbcsUVDkEwh4mMJmNskVI +xISML1o0+ypMZzrN4doF+smdPFjucE6/10AeuEMezye7AbBNjeRhS76vmR1URkeG +3lFHDTATU9SteEEpafOK5eelvHldY6CT1p+fql/gh/NKUMzsyCTxm0SZqPLZMHWi +RN3uH6keEY7AoZIauNjRwItnCrcHTpHj/C4t6MlhObf9AHl08mcTNnGxcT5BeYA/ +dri4SxTPJgErSBbXReP8QzfdUup6ldgB7RPoXw8KpKN66bGEKVrnbQvkW+WgEsni +vaHteykvAgMBAAECggEBAJvGrl+Ujk8jucVRrYVZInWWE2Dmgm+Hx7G75kTFr7p6 +Xsnrhld3zCiU8BSXBGCaDg9F25zmssE3Z0f1zevi7jmMa4+jDkQVqUwuveFneW2x +faj9GJ+A5g2Bokrxqm0lYjTFbTJ7Ff+ecoE3wdV0OfWDoa2rrFaXtdm7xAB44lhm +goYQKwabyRNHxq20lF0zHfnkSfiTJACtmU/uaQw9PL1XhIDhLLSECPWbUdtyGice +swV7P56SSsH1Z7Xrpvwbo8YSNl1MkopNTgX1xqNTAA4TBG3MGvsAGbtQ/0euL782 +MEjgVzsEj+KDdLklTTwir8o9+Od7G7XPqoJeM1+Iw1ECgYEA9eHlZuCmbvAj7GB4 +n6Wh8UgB1TLfSbOUr7Ip5wQvEoE4J9TyjTMuhJZvYuKBoQzeKOKFWAoQcw1hazza +/Kk3XftMW81os3nd0Ayt5bJsaHpC71kDPA/y39ih9tyZQxY19QNLOVL3p3UIh3ol +cMJX3knPEztcZgkH5TjyfW9cYVkCgYEA9Na2AUUX3NMRCnXkpHRgD4hN3imyGXKW +nQ7M0c6YK8sw6YcUUthPcLWv1FjyOqTCO+rWHgGJp1G9IQqLfGJrw80c6GxK0tuQ +Y1NRjpVfL9k/TiEqahhVseY0OTiMRmwC6Hp03z1xGwNrQKkA7eddMIRqU2p5QWV6 +MEE586mSxccCgYEAsFPdBRfZgvknad4M4sAPEE7JMbEXu2zTFeQ4dHjloOmV8cqe +Xm/zzhVrr4gr2ei2cK9xXJ9rCHbyA8tSZ5qaIAWUzsjRatPcI9TT6EM5xvrWgXpd +/Xaaf7iE/dlY92k4LIq+KU+8VhRxl2Ya73APP1PC8lHBg1K6nMFn9Fgl8ZECgYAK ++8bWb78OTPmqunczWXUlvTuhB8XRlm5jRVKy5s20yTy8fS7QOJv3tm7Y29SiBNoh +zfslBXSjaOtPHCX9wnyLIBx34MPKiccEbaxu9Qx8HQbV/m7kq4rMnEMjfgHs9tN6 +kmPD0AHO8GxTTkGYapSnpIkQjOo7oM3GdGahI65N6QKBgQC5yz4v7TG0T1AdXkVN +A1tol8iAq5+9PJrEsoUXATorsMZhE7kyZ4CfS0YHThKWEAUZJnXD4CxXrpWAdzyU +tc2b+AJ5XWfjzuWGZ74LAQB1QnRZlDeGvf9CfU2yDaZKZCahBQENTf44UjfWV3Zd +Krj3S50vAzOyTVOOMbWz/+E48w== +-----END PRIVATE KEY----- diff --git a/openvidu-testapp/src/app/app.module.ts b/openvidu-testapp/src/app/app.module.ts index e7e6f9bd..d04a22f6 100644 --- a/openvidu-testapp/src/app/app.module.ts +++ b/openvidu-testapp/src/app/app.module.ts @@ -13,6 +13,7 @@ import { OpenviduInstanceComponent } from './components/openvidu-instance/openvi import { ExtensionDialogComponent } from './components/openvidu-instance/extension-dialog.component'; import { OpenviduRestService } from './services/openvidu-rest.service'; import { OpenviduParamsService } from './services/openvidu-params.service'; +import { TestFeedService } from './services/test-feed.service'; @NgModule({ declarations: [ @@ -32,7 +33,8 @@ import { OpenviduParamsService } from './services/openvidu-params.service'; ], providers: [ OpenviduRestService, - OpenviduParamsService + OpenviduParamsService, + TestFeedService ], entryComponents: [ ExtensionDialogComponent ], bootstrap: [AppComponent] diff --git a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.css b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.css index 12401c35..1b453d65 100644 --- a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.css +++ b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.css @@ -89,7 +89,7 @@ md-radio-button { color: #4d4d4d; } -.event-list { +.event-list-div { display: inline-block; width: 125px; height: 183.5px; @@ -108,9 +108,9 @@ md-chip { } .scroll-custom::-webkit-scrollbar-track { - -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); - box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); - background-color: #F5F5F5; + /*-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); + box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);*/ + background-color: #e0e0e0; } .scroll-custom::-webkit-scrollbar { diff --git a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.html b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.html index 94fe146c..92eb5308 100644 --- a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.html +++ b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.html @@ -44,10 +44,10 @@
- Video + Video
- Screen + Screen
-
- - - +
+ + + {{event.name}} - {{event.content}} +
{{event.content}}
-
diff --git a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts index 58f9fb2a..7c475d2e 100644 --- a/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts +++ b/openvidu-testapp/src/app/components/openvidu-instance/openvidu-instance.component.ts @@ -5,6 +5,7 @@ import { import { OpenVidu, Session, Subscriber, Publisher, Stream } from 'openvidu-browser'; import { MdDialog, MdDialogRef } from '@angular/material'; import { ExtensionDialogComponent } from './extension-dialog.component'; +import { TestFeedService } from '../../services/test-feed.service'; declare var $: any; @@ -83,7 +84,7 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { openviduError: any; - constructor(private changeDetector: ChangeDetectorRef, public extensionDialog: MdDialog) { + constructor(private changeDetector: ChangeDetectorRef, public extensionDialog: MdDialog, public testFeedService: TestFeedService) { this.generateSessionInfo(); } @@ -296,6 +297,7 @@ export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy { private updateEventList(event: string, content: string) { this.events.push({ name: event, content: content }); + this.testFeedService.pushNewEvent(this.sessionName, this.session.connection.connectionId, event, content); } toggleSubscribeTo(): void { diff --git a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.html b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.html index 17c3fa63..d69bf3e8 100644 --- a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.html +++ b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.html @@ -2,13 +2,13 @@
- - + +
- Auto join - - + Auto join + + diff --git a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts index 691b0a24..8008ec21 100644 --- a/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts +++ b/openvidu-testapp/src/app/components/test-sessions/test-sessions.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core'; import { Subscription } from 'rxjs/Subscription'; import { OpenviduParamsService } from '../../services/openvidu-params.service'; +import { TestFeedService } from '../../services/test-feed.service'; import { SessionConf } from '../openvidu-instance/openvidu-instance.component'; @Component({ @@ -14,6 +15,7 @@ export class TestSessionsComponent implements OnInit, OnDestroy { openviduSecret: string; paramsSubscription: Subscription; + eventsInfoSubscription: Subscription; // OpenViduInstance collection users: SessionConf[] = []; @@ -21,7 +23,7 @@ export class TestSessionsComponent implements OnInit, OnDestroy { numberSubs = 3; autoJoin = false; - constructor(private openviduParamsService: OpenviduParamsService) { } + constructor(private openviduParamsService: OpenviduParamsService, private testFeedService: TestFeedService) { } ngOnInit() { const openviduParams = this.openviduParamsService.getParams(); @@ -33,6 +35,11 @@ export class TestSessionsComponent implements OnInit, OnDestroy { this.openviduUrl = params.openviduUrl; this.openviduSecret = params.openviduSecret; }); + + this.eventsInfoSubscription = this.testFeedService.newLastEvent$.subscribe( + newEvent => { + (window as any).myEvents += ('
' + JSON.stringify(newEvent)); + }); } ngOnDestroy() { @@ -49,6 +56,14 @@ export class TestSessionsComponent implements OnInit, OnDestroy { }); } + private removeUser(): void { + this.users.pop(); + } + + private removeAllUsers(): void { + this.users = []; + } + private loadSubsPubs(n: number): void { for (let i = 0; i < n; i++) { this.users.push({ diff --git a/openvidu-testapp/src/app/services/test-feed.service.spec.ts b/openvidu-testapp/src/app/services/test-feed.service.spec.ts new file mode 100644 index 00000000..405cc490 --- /dev/null +++ b/openvidu-testapp/src/app/services/test-feed.service.spec.ts @@ -0,0 +1,15 @@ +import { TestBed, inject } from '@angular/core/testing'; + +import { TestFeedService } from './test-feed.service'; + +describe('TestFeedService', () => { + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [TestFeedService] + }); + }); + + it('should be created', inject([TestFeedService], (service: TestFeedService) => { + expect(service).toBeTruthy(); + })); +}); diff --git a/openvidu-testapp/src/app/services/test-feed.service.ts b/openvidu-testapp/src/app/services/test-feed.service.ts new file mode 100644 index 00000000..a21bc4b6 --- /dev/null +++ b/openvidu-testapp/src/app/services/test-feed.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { Subject } from 'rxjs/Subject'; + +@Injectable() +export class TestFeedService { + + lastEvent; + newLastEvent$ = new Subject(); + + constructor() { } + + getLastEvent() { + return this.lastEvent; + } + + pushNewEvent(session: string, connection: string, event: string, eventContent: string) { + this.lastEvent = ({ session: session, connection: connection, event: event, eventContent: eventContent }); + this.newLastEvent$.next(this.lastEvent); + } + +} diff --git a/openvidu-testapp/src/index.html b/openvidu-testapp/src/index.html index 1fd2f900..9a60cd50 100644 --- a/openvidu-testapp/src/index.html +++ b/openvidu-testapp/src/index.html @@ -14,6 +14,10 @@ + +