From 39dc91e2057c98f49756a207da24600a7430628a Mon Sep 17 00:00:00 2001 From: Fritz Heiden Date: Mon, 19 Oct 2020 15:46:25 +0200 Subject: [PATCH] Implemented on_receive mode for event registration --- .../listening-to-SCTE-EMSG-events.html | 38 ++++++-- src/core/EventBus.js | 26 +++-- src/streaming/MediaPlayer.js | 7 +- src/streaming/MediaPlayerEvents.js | 12 +++ src/streaming/controllers/EventController.js | 13 ++- .../controllers/PlaybackController.js | 2 +- test/unit/core.EventBus.js | 18 +++- test/unit/mocks/PlaybackControllerMock.js | 7 +- .../streaming.controllers.EventController.js | 94 +++++++++++++++++++ 9 files changed, 189 insertions(+), 28 deletions(-) diff --git a/samples/advanced/listening-to-SCTE-EMSG-events.html b/samples/advanced/listening-to-SCTE-EMSG-events.html index f30d3e4522..18e486f091 100644 --- a/samples/advanced/listening-to-SCTE-EMSG-events.html +++ b/samples/advanced/listening-to-SCTE-EMSG-events.html @@ -13,35 +13,46 @@ var player; const URL = "https://livesim.dashif.org/livesim/scte35_2/testpic_2s/Manifest.mpd"; const SCHEMEIDURI = "urn:scte:scte35:2013:xml"; + const EVENT_MODE_ON_START = dashjs.MediaPlayer.events.EVENT_MODE_ON_START; + const EVENT_MODE_ON_RECEIVE = dashjs.MediaPlayer.events.EVENT_MODE_ON_RECEIVE; function init() { player = dashjs.MediaPlayer().create(); player.updateSettings({ 'debug': { 'logLevel': dashjs.Debug.LOG_LEVEL_NONE }}); - player.on(SCHEMEIDURI, showEvent); + player.on(SCHEMEIDURI, showStartEvent, null, { mode: EVENT_MODE_ON_START }); + player.on(SCHEMEIDURI, showReceiveEvent, null, { mode: EVENT_MODE_ON_RECEIVE }); player.initialize(document.querySelector("video"), URL, true); } - function showEvent(e) { - log("EVENT RECEIVED: " + e.type); + function showStartEvent(e) { + showEvent(e, "start"); + } + + function showReceiveEvent(e) { + showEvent(e, "receive"); + } + + function showEvent(e, output) { /* We double process in order to pretty-print. Only two levels of object properties are exposed. */ for (var name in e) { if (typeof e[name] != 'object') { - log(" " + name + ": " + e[name]); + log(" " + name + ": " + e[name], output); } } for (name in e) { if (typeof e[name] == 'object' ) { - log(" " + name + ":"); + log(" " + name + ":", output); for (name2 in e[name]) { - log(" " + name2 + ": " + JSON.stringify(e[name][name2])); + log(" " + name2 + ": " + JSON.stringify(e[name][name2]), output); } } } + log("", output); } - function log(msg) { + function log(msg, output) { msg = msg.length > 200 ? msg.substring(0, 200) + "..." : msg; /* to avoid repeated wrapping with large objects */ - var tracePanel = document.getElementById("trace"); + var tracePanel = document.getElementById(output); tracePanel.innerHTML += msg + "\n"; tracePanel.scrollTop = tracePanel.scrollHeight; console.log(msg); @@ -68,7 +79,16 @@
- +
+
+
+

Received Events

+ +
+
+

Started Events

+ +