From 3824e68224677422e1ed1e6a15181a8d2b2b235c Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Thu, 20 Jun 2019 14:09:42 +0200 Subject: [PATCH 1/6] support for automated clientStats reporting. --- package.json | 2 +- src/page/test/subscribe/index.js | 3 + src/template/partial/header-scripts.hbs | 1 + static/script/automation-testing.js | 152 ++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 static/script/automation-testing.js diff --git a/package.json b/package.json index 34481611..36ca96ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "red5pro-html-sdk-testbed", - "version": "5.6.0-RC1", + "version": "5.6.0-RC3", "description": "Testbed examples for Red5 Pro HTML SDK", "main": "src/js/index.js", "repository": { diff --git a/src/page/test/subscribe/index.js b/src/page/test/subscribe/index.js index 105b3d23..0c3caf9d 100644 --- a/src/page/test/subscribe/index.js +++ b/src/page/test/subscribe/index.js @@ -92,6 +92,9 @@ window.exposeSubscriberGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { + if (window.red5proMonitorGetStats) { + window.red5proMonitorGetStats(subscriber.getOptions().subscriptionId, subscriber.getPeerConnection()); + } try { window.trackBitrate(subscriber.getPeerConnection(), onBitrateUpdate, onResolutionUpdate, true); } diff --git a/src/template/partial/header-scripts.hbs b/src/template/partial/header-scripts.hbs index d331bf0f..41e3de6e 100644 --- a/src/template/partial/header-scripts.hbs +++ b/src/template/partial/header-scripts.hbs @@ -2,4 +2,5 @@ + diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js new file mode 100644 index 00000000..724612e7 --- /dev/null +++ b/static/script/automation-testing.js @@ -0,0 +1,152 @@ +(function (window) { + + // Should be loaded from red5pro-utils.js + if (!window.query) return; + + var reportClientStats = !!window.query('automation'); + var sampleTime = window.query('sampleTime') ? parseInt(window.query('sampleTime'), 10) : 2000; + sampleTime = isNaN(sampleTime) ? 2000 : sampleTime; + var inspectorEndpoint = window.query('inspectorBaseURL') ? window.query('inspectorBaseURL') : window.location.origin; + + // If we arent concerned with automation reports, forget it. + if (!reportClientStats) return; + + // [Script inject]] + var hasStatsScript = false; + var muazkhans_getstats = 'https://cdn.webrtc-experiment.com/getStats.min.js'; + var loadFn = function () { + hasStatsScript = true; + var pending = pendingMonitors ? Object.keys(pendingMonitors) : []; + var i = pending.length; + while (--i > -1) { + var id = pending[i]; + monitorGetStats(id, pendingMonitors[id]); + delete pendingMonitors[id]; + } + pendingMonitors = undefined; + } + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = muazkhans_getstats; + script.onreadystatechange = loadFn; + script.onload = loadFn; + head.appendChild(script); + // [[Script inject] + + var monitors = []; + var pendingMonitors = {}; + + // The data to pluck from getStats results. + var dataMap = { + 'ssrc': [ // Chrome + 'framesDecoded', + 'googDecodeMs', + 'googMaxDecodeMs', + 'googCurrentDelayMs', + 'googFirstFrameReceivedToDecodedMs', + 'googRenderDelayMs', + 'googFrameRateReceived' + ], + 'inbound-rtp': [ // Firefox :/ + 'framesDecoded' + ], + 'track': [ // Safari :/ + 'framesDecoded' + ] + }; + + var isValidResult = function (result) { + if (result.type === 'inbound-rtp' && result.kind !== 'video') { + // Audio data in Firefox. + return false; + } else if (result.type === 'track') { + // Audio track in Safari. + return !(result.frameWidth === 0 && result.frameHeight === 0); + } + return true; + }; + var gatherDataFromResults = function (resultsArr) { + var i = resultsArr.length, j; + var result, resultKeys; + var data; + var key; + var payload = {}; + while (--i > -1) { + result = resultsArr[i]; + if (dataMap.hasOwnProperty(result.type)) { + if (!isValidResult(result)) { + continue; + } + resultKeys = Object.keys(result); + data = dataMap[result.type]; + j = resultKeys.length; + while (--j > -1) { + key = resultKeys[j]; + if (data.indexOf(key) > -1) { + payload[key] = result[key]; + } + } + } + } + return payload; + }; + + var postResults = function (subscriberId, result) { + var results = result.results; + var data = gatherDataFromResults(results); + data = Object.assign(data, { + id: subscriberId, + event: 'clientStats' + }); + if (typeof window.adapter !== 'undefined') { + data = Object.assign(data, window.adapter.browserDetails); + } + console.log(JSON.stringify(data, null, 2)); + fetch(inspectorEndpoint + '/inspector/streamapi.js', { + method: 'post', + headers: { + 'Accept': 'application/json, text/plain, */*', + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }) + .then(function (res) { + return res.json(); + }) + .then(function (res) { + console.log(res) + }) + .catch(function (error) { + console.error(error); + }); + }; + + var startMonitor = function (id, connection) { + window.getStats(connection, function (result) { + if (monitors.indexOf(id) <= -1) { + return; + } + postResults(id, result); + console.log(result); + }, sampleTime); + }; + var monitorGetStats = function (id, connection) { + if (!hasStatsScript) { + pendingMonitors[id] = connection; + return; + } + monitors.push(id); + startMonitor(id, connection); + }; + var unmonitorGetStats = function (id) { + var index = monitors.indexOf(id); + if (index > -1) { + monitors.splice(index, 1); + } + }; + + window.red5proUnmonitorGetStats = unmonitorGetStats; + window.red5proMonitorGetStats = monitorGetStats; + +})(window); From fabf23507ce0b8d1f0d9e4163afa365fcce881e0 Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Fri, 21 Jun 2019 09:17:03 +0200 Subject: [PATCH 2/6] adding unsubscribe to global getstats call. --- .../sm-test/TwoWayStreamManagerProxy/index.js | 7 +++++-- .../index.js | 8 ++++--- .../sm-test/subscribeStreamManager/index.js | 7 +++++-- .../subscribeStreamManagerProxy/index.js | 7 +++++-- .../index.js | 7 +++++-- .../index.js | 7 +++++-- .../index.js | 7 +++++-- .../index.js | 7 +++++-- .../index.js | 7 +++++-- .../subscribeStreamManagerProxyVP8/index.js | 7 +++++-- .../index.js | 7 +++++-- src/page/test/subscribe/index.js | 10 ++++----- src/page/test/subscribeAudioOnly/index.js | 7 +++++-- src/page/test/subscribeAuth/index.js | 7 +++++-- src/page/test/subscribeCall/index.js | 7 +++++-- src/page/test/subscribeCluster/index.js | 7 +++++-- src/page/test/subscribeHLS/index.js | 7 +++++-- src/page/test/subscribeImageCapture/index.js | 7 +++++-- src/page/test/subscribeMobile/index.js | 7 +++++-- src/page/test/subscribeReconnect/index.js | 7 +++++-- src/page/test/subscribeRemoteCall/index.js | 7 +++++-- .../test/subscribeRetryOnInvalidName/index.js | 7 +++++-- src/page/test/subscribeRoundTripAuth/index.js | 7 +++++-- src/page/test/subscribeScreenShare/index.js | 7 +++++-- src/page/test/subscribeSharedObject/index.js | 7 +++++-- src/page/test/subscribeVideoMute/index.js | 7 +++++-- src/page/test/subscribevp8/index.js | 7 +++++-- src/page/test/twoWay/index.js | 7 +++++-- src/template/partial/body-scripts.hbs | 19 +++++++++++++++++ static/script/automation-testing.js | 21 ++++++++++++------- 30 files changed, 172 insertions(+), 68 deletions(-) diff --git a/src/page/sm-test/TwoWayStreamManagerProxy/index.js b/src/page/sm-test/TwoWayStreamManagerProxy/index.js index 5b53e65d..4d95a668 100644 --- a/src/page/sm-test/TwoWayStreamManagerProxy/index.js +++ b/src/page/sm-test/TwoWayStreamManagerProxy/index.js @@ -84,8 +84,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } } function onUnsubscribeFail (message) { @@ -346,6 +346,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber; + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeBackupStreamSwitchStreammanager/index.js b/src/page/sm-test/subscribeBackupStreamSwitchStreammanager/index.js index 12983eb4..70dcf731 100644 --- a/src/page/sm-test/subscribeBackupStreamSwitchStreammanager/index.js +++ b/src/page/sm-test/subscribeBackupStreamSwitchStreammanager/index.js @@ -163,7 +163,9 @@ document.getElementById(replacement.id).parentNode.classList.remove('hidden'); document.getElementById(replacement.id).parentNode.dataset.activeVideo = replacement.id; replacement.isActive = true; - window.exposeSubscriberGlobally(replacement.subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(replacement.subscriber); + } replacement.subscriber.play(); replacement.subscriber.disableStandby(); var options = replacement.subscriber._options; @@ -219,8 +221,8 @@ new red5prosdk.RTCSubscriber() .init(config) .then(function (subscriber) { - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } return subscriber.subscribe(); }) diff --git a/src/page/sm-test/subscribeStreamManager/index.js b/src/page/sm-test/subscribeStreamManager/index.js index 7f0a5746..3250cb42 100644 --- a/src/page/sm-test/subscribeStreamManager/index.js +++ b/src/page/sm-test/subscribeStreamManager/index.js @@ -117,8 +117,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -225,6 +225,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxy/index.js b/src/page/sm-test/subscribeStreamManagerProxy/index.js index 25cf5167..33c3b5ad 100644 --- a/src/page/sm-test/subscribeStreamManagerProxy/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxy/index.js @@ -120,8 +120,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -263,6 +263,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyRoundTripAuth/index.js b/src/page/sm-test/subscribeStreamManagerProxyRoundTripAuth/index.js index 2c919c82..33ae9d39 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyRoundTripAuth/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyRoundTripAuth/index.js @@ -116,8 +116,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -274,6 +274,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyScreenShare/index.js b/src/page/sm-test/subscribeStreamManagerProxyScreenShare/index.js index 0498fbe1..1384a2a8 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyScreenShare/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyScreenShare/index.js @@ -147,8 +147,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -181,6 +181,9 @@ // Request to unsubscribe. function unsubscribe (subscriber) { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unscubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyTranscoderHLS/index.js b/src/page/sm-test/subscribeStreamManagerProxyTranscoderHLS/index.js index 4446d3a6..e65940c6 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyTranscoderHLS/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyTranscoderHLS/index.js @@ -102,8 +102,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } try { window.trackBitrate(subscriber.getPeerConnection(), onBitrateUpdate, onResolutionUpdate, true); @@ -219,6 +219,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTC/index.js b/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTC/index.js index 278736ef..7da4d3cf 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTC/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTC/index.js @@ -118,8 +118,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } try { window.trackBitrate(subscriber.getPeerConnection(), onBitrateUpdate, onResolutionUpdate, true); @@ -252,6 +252,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTMP/index.js b/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTMP/index.js index d7737096..45bb646d 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTMP/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyTranscoderRTMP/index.js @@ -134,8 +134,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } } function onUnsubscribeFail (message) { @@ -252,6 +252,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyVP8/index.js b/src/page/sm-test/subscribeStreamManagerProxyVP8/index.js index 75e2f3b0..ceee792d 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyVP8/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyVP8/index.js @@ -97,8 +97,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } } function onUnsubscribeFail (message) { @@ -233,6 +233,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/sm-test/subscribeStreamManagerProxyValidation/index.js b/src/page/sm-test/subscribeStreamManagerProxyValidation/index.js index 87f2a76a..09d4962f 100644 --- a/src/page/sm-test/subscribeStreamManagerProxyValidation/index.js +++ b/src/page/sm-test/subscribeStreamManagerProxyValidation/index.js @@ -184,8 +184,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -266,6 +266,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribe/index.js b/src/page/test/subscribe/index.js index 0c3caf9d..b7dccb56 100644 --- a/src/page/test/subscribe/index.js +++ b/src/page/test/subscribe/index.js @@ -88,13 +88,10 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { - if (window.red5proMonitorGetStats) { - window.red5proMonitorGetStats(subscriber.getOptions().subscriptionId, subscriber.getPeerConnection()); - } try { window.trackBitrate(subscriber.getPeerConnection(), onBitrateUpdate, onResolutionUpdate, true); } @@ -126,6 +123,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeAudioOnly/index.js b/src/page/test/subscribeAudioOnly/index.js index cb8455a1..a46db755 100644 --- a/src/page/test/subscribeAudioOnly/index.js +++ b/src/page/test/subscribeAudioOnly/index.js @@ -113,8 +113,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -136,6 +136,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeAuth/index.js b/src/page/test/subscribeAuth/index.js index ec2c017b..a752a6cc 100644 --- a/src/page/test/subscribeAuth/index.js +++ b/src/page/test/subscribeAuth/index.js @@ -88,8 +88,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -110,6 +110,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeCall/index.js b/src/page/test/subscribeCall/index.js index 8fed1186..a64b738d 100644 --- a/src/page/test/subscribeCall/index.js +++ b/src/page/test/subscribeCall/index.js @@ -113,8 +113,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } } function onUnsubscribeFail (message) { @@ -130,6 +130,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeCluster/index.js b/src/page/test/subscribeCluster/index.js index 23f11e49..1ef3f5f3 100644 --- a/src/page/test/subscribeCluster/index.js +++ b/src/page/test/subscribeCluster/index.js @@ -105,8 +105,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -219,6 +219,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeHLS/index.js b/src/page/test/subscribeHLS/index.js index bc7b425e..1687e676 100644 --- a/src/page/test/subscribeHLS/index.js +++ b/src/page/test/subscribeHLS/index.js @@ -108,6 +108,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); @@ -138,8 +141,8 @@ targetSubscriber = subscriberImpl // Subscribe to events. targetSubscriber.on('*', onSubscriberEvent); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(targetSubscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(targetSubscriber); } return targetSubscriber.subscribe() }) diff --git a/src/page/test/subscribeImageCapture/index.js b/src/page/test/subscribeImageCapture/index.js index 721c7d91..8bb787bd 100644 --- a/src/page/test/subscribeImageCapture/index.js +++ b/src/page/test/subscribeImageCapture/index.js @@ -103,8 +103,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -137,6 +137,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeMobile/index.js b/src/page/test/subscribeMobile/index.js index 095f1b02..549636b3 100644 --- a/src/page/test/subscribeMobile/index.js +++ b/src/page/test/subscribeMobile/index.js @@ -86,8 +86,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -121,6 +121,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeReconnect/index.js b/src/page/test/subscribeReconnect/index.js index 33667a70..945b9e8f 100644 --- a/src/page/test/subscribeReconnect/index.js +++ b/src/page/test/subscribeReconnect/index.js @@ -90,8 +90,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -125,6 +125,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeRemoteCall/index.js b/src/page/test/subscribeRemoteCall/index.js index 10262473..a0d6ba01 100644 --- a/src/page/test/subscribeRemoteCall/index.js +++ b/src/page/test/subscribeRemoteCall/index.js @@ -85,8 +85,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -119,6 +119,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off(red5prosdk.SubscriberEventTypes.SUBSCRIBE_SEND_INVOKE, sendClientHandler); diff --git a/src/page/test/subscribeRetryOnInvalidName/index.js b/src/page/test/subscribeRetryOnInvalidName/index.js index d26681fb..538cf87d 100644 --- a/src/page/test/subscribeRetryOnInvalidName/index.js +++ b/src/page/test/subscribeRetryOnInvalidName/index.js @@ -123,8 +123,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -157,6 +157,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeRoundTripAuth/index.js b/src/page/test/subscribeRoundTripAuth/index.js index 2b774724..445fa35e 100644 --- a/src/page/test/subscribeRoundTripAuth/index.js +++ b/src/page/test/subscribeRoundTripAuth/index.js @@ -90,8 +90,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -112,6 +112,9 @@ // Request to unsubscribe. function unsubscribe () { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeScreenShare/index.js b/src/page/test/subscribeScreenShare/index.js index ca60de97..7688e4f1 100644 --- a/src/page/test/subscribeScreenShare/index.js +++ b/src/page/test/subscribeScreenShare/index.js @@ -95,8 +95,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -129,6 +129,9 @@ // Request to unsubscribe. function unsubscribe (subscriber) { return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeSharedObject/index.js b/src/page/test/subscribeSharedObject/index.js index 2d06eda2..03a36e46 100644 --- a/src/page/test/subscribeSharedObject/index.js +++ b/src/page/test/subscribeSharedObject/index.js @@ -96,8 +96,8 @@ function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); establishSharedObject(subscriber); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -183,6 +183,9 @@ so.close(); } return new Promise(function(resolve, reject) { + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(targetSubscriber); + } targetSubscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribeVideoMute/index.js b/src/page/test/subscribeVideoMute/index.js index 43ae4e01..d4e80db6 100644 --- a/src/page/test/subscribeVideoMute/index.js +++ b/src/page/test/subscribeVideoMute/index.js @@ -96,8 +96,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -131,6 +131,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/subscribevp8/index.js b/src/page/test/subscribevp8/index.js index d7a610f1..b65ebcd8 100644 --- a/src/page/test/subscribevp8/index.js +++ b/src/page/test/subscribevp8/index.js @@ -84,8 +84,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } if (subscriber.getType().toLowerCase() === 'rtc') { try { @@ -119,6 +119,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/page/test/twoWay/index.js b/src/page/test/twoWay/index.js index ac3a532e..04f8e11d 100644 --- a/src/page/test/twoWay/index.js +++ b/src/page/test/twoWay/index.js @@ -83,8 +83,8 @@ } function onSubscribeSuccess (subscriber) { console.log('[Red5ProSubsriber] Subscribe Complete.'); - if (window.exposeSubscriberGlobally) { - window.exposeSubscriberGlobally(subscriber); + if (window.handleSubscriberSetupGlobally) { + window.handleSubscriberSetupGlobally(subscriber); } } function onUnsubscribeFail (message) { @@ -324,6 +324,9 @@ function unsubscribe () { return new Promise(function(resolve, reject) { var subscriber = targetSubscriber; + if (window.handleSubscriberTeardownGlobally) { + window.handleSubscriberTeardownGlobally(subscriber); + } subscriber.unsubscribe() .then(function () { targetSubscriber.off('*', onSubscriberEvent); diff --git a/src/template/partial/body-scripts.hbs b/src/template/partial/body-scripts.hbs index 5ed6ff8a..57a2c7e0 100644 --- a/src/template/partial/body-scripts.hbs +++ b/src/template/partial/body-scripts.hbs @@ -41,5 +41,24 @@ testBody.parentNode.insertBefore(node, testBody); } + // Handle all successful setup of subscribers here to forward on to other operations. + window.handleSubscriberSetupGlobally = function (subscriber) { + if (window.exposeSubscriberGlobally) { + window.exposeSubscriberGlobally(subscriber); + } + if (subscriber.getType().toLowerCase() === 'rtc') { + if (window.red5proMonitorGetStats) { + var opt = subscriber.getOptions(); + window.red5proMonitorGetStats(opt.subscriptionId, opt.streamName, subscriber.getPeerConnection()); + } + } + }; + // Handle any teardown of successfully setup subscribers. + window.handleSubscriberTeardownGlobally = function (subscriber) { + if (window.red5proUnmonitorGetStats) { + window.red5proUnmonitorGetStats(subscriber.getOptions().subscriptionId); + } + } + })(this); diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js index 724612e7..870d1e80 100644 --- a/static/script/automation-testing.js +++ b/static/script/automation-testing.js @@ -20,7 +20,8 @@ var i = pending.length; while (--i > -1) { var id = pending[i]; - monitorGetStats(id, pendingMonitors[id]); + var obj = pendingMonitors[id]; + monitorGetStats(id, obj.name, obj.connection); delete pendingMonitors[id]; } pendingMonitors = undefined; @@ -92,12 +93,13 @@ return payload; }; - var postResults = function (subscriberId, result) { + var postResults = function (subscriberId, streamName, result) { var results = result.results; var data = gatherDataFromResults(results); data = Object.assign(data, { id: subscriberId, - event: 'clientStats' + event: 'clientStats', + streamName: streamName }); if (typeof window.adapter !== 'undefined') { data = Object.assign(data, window.adapter.browserDetails); @@ -122,22 +124,25 @@ }); }; - var startMonitor = function (id, connection) { + var startMonitor = function (id, name, connection) { window.getStats(connection, function (result) { if (monitors.indexOf(id) <= -1) { return; } - postResults(id, result); + postResults(id, name, result); console.log(result); }, sampleTime); }; - var monitorGetStats = function (id, connection) { + var monitorGetStats = function (id, name, connection) { if (!hasStatsScript) { - pendingMonitors[id] = connection; + pendingMonitors[id] = { + name: name, + connection: connection + }; return; } monitors.push(id); - startMonitor(id, connection); + startMonitor(id, name, connection); }; var unmonitorGetStats = function (id) { var index = monitors.indexOf(id); From 03c2559960abe4959aea21cdac6b28eaa5ec5a98 Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Mon, 24 Jun 2019 09:48:38 +0200 Subject: [PATCH 3/6] removing console log from automation. --- static/script/automation-testing.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js index 870d1e80..08b30e23 100644 --- a/static/script/automation-testing.js +++ b/static/script/automation-testing.js @@ -113,11 +113,8 @@ }, body: JSON.stringify(data) }) - .then(function (res) { - return res.json(); - }) - .then(function (res) { - console.log(res) + .then(function (res) { // eslint-disable-line no-unused-vars + // console.log(res) }) .catch(function (error) { console.error(error); From 14d64fe3735e2bd32b734173cf51bce4574c0ae4 Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Mon, 24 Jun 2019 10:06:50 +0200 Subject: [PATCH 4/6] sending query params for clientstats in automation. --- static/script/automation-testing.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js index 08b30e23..a3780278 100644 --- a/static/script/automation-testing.js +++ b/static/script/automation-testing.js @@ -85,7 +85,7 @@ while (--j > -1) { key = resultKeys[j]; if (data.indexOf(key) > -1) { - payload[key] = result[key]; + payload[key] = parseInt(result[key], 10); } } } @@ -105,7 +105,8 @@ data = Object.assign(data, window.adapter.browserDetails); } console.log(JSON.stringify(data, null, 2)); - fetch(inspectorEndpoint + '/inspector/streamapi.js', { + var dataJSON = encodeURIComponent(JSON.stringify(data)); + fetch(inspectorEndpoint + '/inspector/streamapi.js?clientstats=' + dataJSON, { method: 'post', headers: { 'Accept': 'application/json, text/plain, */*', From fbeb3d7b23adda939f18e951a7e2769f7e3517ed Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Tue, 2 Jul 2019 21:20:21 +0200 Subject: [PATCH 5/6] automation posting for all browsers. --- static/script/automation-testing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js index a3780278..94f40c09 100644 --- a/static/script/automation-testing.js +++ b/static/script/automation-testing.js @@ -112,7 +112,7 @@ 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, - body: JSON.stringify(data) + body: JSON.stringify({clientstats: data}) }) .then(function (res) { // eslint-disable-line no-unused-vars // console.log(res) From dc9c9351a604674e7b5b43fb332f26db2e27f347 Mon Sep 17 00:00:00 2001 From: bustardcelly Date: Tue, 9 Jul 2019 11:37:06 +0200 Subject: [PATCH 6/6] adding streamTime to automation reports. --- package.json | 2 +- src/template/partial/body-scripts.hbs | 2 +- static/script/automation-testing.js | 17 ++++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 36ca96ea..f8160fad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "red5pro-html-sdk-testbed", - "version": "5.6.0-RC3", + "version": "5.6.0-RC4", "description": "Testbed examples for Red5 Pro HTML SDK", "main": "src/js/index.js", "repository": { diff --git a/src/template/partial/body-scripts.hbs b/src/template/partial/body-scripts.hbs index 57a2c7e0..36b8153a 100644 --- a/src/template/partial/body-scripts.hbs +++ b/src/template/partial/body-scripts.hbs @@ -49,7 +49,7 @@ if (subscriber.getType().toLowerCase() === 'rtc') { if (window.red5proMonitorGetStats) { var opt = subscriber.getOptions(); - window.red5proMonitorGetStats(opt.subscriptionId, opt.streamName, subscriber.getPeerConnection()); + window.red5proMonitorGetStats(opt.subscriptionId, opt.streamName, opt.mediaElementId, subscriber.getPeerConnection()); } } }; diff --git a/static/script/automation-testing.js b/static/script/automation-testing.js index 94f40c09..83b79aa4 100644 --- a/static/script/automation-testing.js +++ b/static/script/automation-testing.js @@ -21,7 +21,7 @@ while (--i > -1) { var id = pending[i]; var obj = pendingMonitors[id]; - monitorGetStats(id, obj.name, obj.connection); + monitorGetStats(id, obj.name, obj.elementId, obj.connection); delete pendingMonitors[id]; } pendingMonitors = undefined; @@ -93,13 +93,14 @@ return payload; }; - var postResults = function (subscriberId, streamName, result) { + var postResults = function (subscriberId, streamName, streamTime, result) { var results = result.results; var data = gatherDataFromResults(results); data = Object.assign(data, { id: subscriberId, event: 'clientStats', - streamName: streamName + streamName: streamName, + streamTime: streamTime }); if (typeof window.adapter !== 'undefined') { data = Object.assign(data, window.adapter.browserDetails); @@ -122,25 +123,27 @@ }); }; - var startMonitor = function (id, name, connection) { + var startMonitor = function (id, name, elementId, connection) { window.getStats(connection, function (result) { if (monitors.indexOf(id) <= -1) { return; } - postResults(id, name, result); + var streamTime = document.getElementById(elementId).currentTime*1000; + postResults(id, name, streamTime, result); console.log(result); }, sampleTime); }; - var monitorGetStats = function (id, name, connection) { + var monitorGetStats = function (id, name, elementId, connection) { if (!hasStatsScript) { pendingMonitors[id] = { name: name, + elementId: elementId, connection: connection }; return; } monitors.push(id); - startMonitor(id, name, connection); + startMonitor(id, name, elementId, connection); }; var unmonitorGetStats = function (id) { var index = monitors.indexOf(id);