@flashphoner/websdk 2.0.265 → 2.0.266
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docTemplate/README.md +1 -1
- package/flashphoner-no-flash.js +316 -84
- package/flashphoner-no-flash.min.js +2 -2
- package/flashphoner-no-webrtc.js +316 -84
- package/flashphoner-no-webrtc.min.js +2 -2
- package/flashphoner-no-wsplayer.js +316 -84
- package/flashphoner-no-wsplayer.min.js +2 -2
- package/flashphoner-room-api-webrtc-only.js +314 -82
- package/flashphoner-room-api-webrtc-only.min.js +1 -1
- package/flashphoner-room-api.js +168 -26
- package/flashphoner-room-api.min.js +4 -4
- package/flashphoner-temasys-flash-websocket-without-adapterjs.js +316 -84
- package/flashphoner-temasys-flash-websocket.js +316 -84
- package/flashphoner-temasys-flash-websocket.min.js +1 -1
- package/flashphoner-webrtc-only.js +314 -82
- package/flashphoner-webrtc-only.min.js +1 -1
- package/flashphoner.js +316 -84
- package/flashphoner.min.js +2 -2
- package/package.json +1 -1
- package/src/media-source-media-provider.js +4 -4
- package/src/stats-collector.js +164 -22
|
@@ -11596,6 +11596,10 @@ module.exports = {
|
|
|
11596
11596
|
'use strict';
|
|
11597
11597
|
|
|
11598
11598
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11599
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11600
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11601
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
11602
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
11599
11603
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
11600
11604
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
11601
11605
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
@@ -11605,14 +11609,25 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
|
|
|
11605
11609
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
11606
11610
|
var util = require('./util');
|
|
11607
11611
|
var LOG_PREFIX = "stats-collector";
|
|
11612
|
+
var CONNECTION_TYPE = {
|
|
11613
|
+
WEBSOCKET: "ws",
|
|
11614
|
+
HTTP: "http"
|
|
11615
|
+
};
|
|
11616
|
+
var MAX_SEND_ERRORS = 3;
|
|
11617
|
+
var CONNECTION_STATUS = {
|
|
11618
|
+
INIT: 0,
|
|
11619
|
+
OK: 200,
|
|
11620
|
+
BAD_REQUEST: 400,
|
|
11621
|
+
INTERNAL_SERVER_ERROR: 500
|
|
11622
|
+
};
|
|
11608
11623
|
|
|
11609
11624
|
// Collect and send WebRTC statistics periodically
|
|
11610
|
-
var StreamStatsCollector = function StreamStatsCollector(description, id, mediaConnection, wsConnection, logger) {
|
|
11625
|
+
var StreamStatsCollector = function StreamStatsCollector(description, id, mediaConnection, wsConnection, logger, maxErrors) {
|
|
11611
11626
|
var statCollector = {
|
|
11612
11627
|
description: description,
|
|
11613
11628
|
id: id,
|
|
11614
11629
|
mediaConnection: mediaConnection,
|
|
11615
|
-
|
|
11630
|
+
connection: Connection(wsConnection, maxErrors),
|
|
11616
11631
|
logger: getLogger(logger),
|
|
11617
11632
|
headers: "",
|
|
11618
11633
|
compression: "none",
|
|
@@ -11622,7 +11637,7 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11622
11637
|
timerBusy: false,
|
|
11623
11638
|
start: function () {
|
|
11624
11639
|
var _start = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
11625
|
-
var error;
|
|
11640
|
+
var error, authHeader;
|
|
11626
11641
|
return _regenerator().w(function (_context) {
|
|
11627
11642
|
while (1) switch (_context.n) {
|
|
11628
11643
|
case 0:
|
|
@@ -11651,19 +11666,25 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11651
11666
|
}
|
|
11652
11667
|
throw new Error(error + "no media connection available");
|
|
11653
11668
|
case 4:
|
|
11654
|
-
|
|
11655
|
-
|
|
11656
|
-
|
|
11669
|
+
statCollector.logger.debug(LOG_PREFIX, "RTCMetricsServerDescription: " + JSON.stringify(statCollector.description));
|
|
11670
|
+
if (statCollector.description.ingestPoint) {
|
|
11671
|
+
authHeader = null;
|
|
11672
|
+
if (statCollector.description.authorization) {
|
|
11673
|
+
authHeader = {
|
|
11674
|
+
Authorization: statCollector.description.authorization
|
|
11675
|
+
};
|
|
11676
|
+
}
|
|
11677
|
+
statCollector.connection.setUp(statCollector.description.ingestPoint, authHeader);
|
|
11657
11678
|
}
|
|
11658
|
-
|
|
11679
|
+
_context.n = 5;
|
|
11680
|
+
return statCollector.updateHeaders();
|
|
11659
11681
|
case 5:
|
|
11660
11682
|
_context.n = 6;
|
|
11661
|
-
return statCollector.
|
|
11683
|
+
return statCollector.updateCompression();
|
|
11662
11684
|
case 6:
|
|
11663
11685
|
_context.n = 7;
|
|
11664
|
-
return statCollector.
|
|
11686
|
+
return statCollector.sendHeaders();
|
|
11665
11687
|
case 7:
|
|
11666
|
-
statCollector.sendHeaders();
|
|
11667
11688
|
if (statCollector.description.collect === "on") {
|
|
11668
11689
|
statCollector.collect(true);
|
|
11669
11690
|
}
|
|
@@ -11678,7 +11699,7 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11678
11699
|
return start;
|
|
11679
11700
|
}(),
|
|
11680
11701
|
collect: function collect(enable) {
|
|
11681
|
-
if (enable) {
|
|
11702
|
+
if (enable && statCollector.connection.status === CONNECTION_STATUS.OK) {
|
|
11682
11703
|
statCollector.startTimer();
|
|
11683
11704
|
} else {
|
|
11684
11705
|
statCollector.stopTimer();
|
|
@@ -11698,15 +11719,12 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11698
11719
|
_context2.n = 1;
|
|
11699
11720
|
break;
|
|
11700
11721
|
}
|
|
11701
|
-
if (!statCollector.logger) {
|
|
11702
|
-
_context2.n = 1;
|
|
11703
|
-
break;
|
|
11704
|
-
}
|
|
11705
11722
|
statCollector.logger.error(LOG_PREFIX + "-" + statCollector.id, "Can't update WebRTC metrics sending: no parameters passed");
|
|
11706
11723
|
return _context2.a(2);
|
|
11707
11724
|
case 1:
|
|
11725
|
+
statCollector.logger.debug(LOG_PREFIX, "New RTCMetricsServerDescription: " + JSON.stringify(description));
|
|
11708
11726
|
if (!(description.types || description.compression)) {
|
|
11709
|
-
_context2.n =
|
|
11727
|
+
_context2.n = 6;
|
|
11710
11728
|
break;
|
|
11711
11729
|
}
|
|
11712
11730
|
statCollector.stop();
|
|
@@ -11726,12 +11744,20 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11726
11744
|
_context2.n = 3;
|
|
11727
11745
|
return statCollector.updateCompression();
|
|
11728
11746
|
case 3:
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
break;
|
|
11747
|
+
_context2.n = 4;
|
|
11748
|
+
return statCollector.sendHeaders();
|
|
11732
11749
|
case 4:
|
|
11733
|
-
statCollector.
|
|
11750
|
+
if (!(statCollector.connection.status !== CONNECTION_STATUS.OK)) {
|
|
11751
|
+
_context2.n = 5;
|
|
11752
|
+
break;
|
|
11753
|
+
}
|
|
11754
|
+
return _context2.a(2);
|
|
11734
11755
|
case 5:
|
|
11756
|
+
_context2.n = 7;
|
|
11757
|
+
break;
|
|
11758
|
+
case 6:
|
|
11759
|
+
statCollector.collect(false);
|
|
11760
|
+
case 7:
|
|
11735
11761
|
if (description.batchSize) {
|
|
11736
11762
|
statCollector.description.batchSize = description.batchSize;
|
|
11737
11763
|
}
|
|
@@ -11742,15 +11768,15 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11742
11768
|
statCollector.description.collect = description.collect;
|
|
11743
11769
|
}
|
|
11744
11770
|
_t = statCollector.description.collect;
|
|
11745
|
-
_context2.n = _t === "on" ?
|
|
11771
|
+
_context2.n = _t === "on" ? 8 : _t === "off" ? 9 : 10;
|
|
11746
11772
|
break;
|
|
11747
|
-
case
|
|
11773
|
+
case 8:
|
|
11748
11774
|
statCollector.collect(true);
|
|
11749
|
-
return _context2.a(3,
|
|
11750
|
-
case
|
|
11775
|
+
return _context2.a(3, 10);
|
|
11776
|
+
case 9:
|
|
11751
11777
|
statCollector.collect(false);
|
|
11752
|
-
return _context2.a(3,
|
|
11753
|
-
case
|
|
11778
|
+
return _context2.a(3, 10);
|
|
11779
|
+
case 10:
|
|
11754
11780
|
return _context2.a(2);
|
|
11755
11781
|
}
|
|
11756
11782
|
}, _callee2);
|
|
@@ -11934,23 +11960,56 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11934
11960
|
}
|
|
11935
11961
|
return checkForCompression;
|
|
11936
11962
|
}(),
|
|
11937
|
-
sendHeaders: function
|
|
11938
|
-
var
|
|
11939
|
-
|
|
11940
|
-
|
|
11941
|
-
|
|
11942
|
-
|
|
11943
|
-
|
|
11944
|
-
|
|
11945
|
-
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11963
|
+
sendHeaders: function () {
|
|
11964
|
+
var _sendHeaders = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
11965
|
+
var data;
|
|
11966
|
+
return _regenerator().w(function (_context6) {
|
|
11967
|
+
while (1) switch (_context6.n) {
|
|
11968
|
+
case 0:
|
|
11969
|
+
data = {
|
|
11970
|
+
mediaSessionId: statCollector.id,
|
|
11971
|
+
compression: statCollector.compression,
|
|
11972
|
+
headers: statCollector.headers
|
|
11973
|
+
};
|
|
11974
|
+
_context6.n = 1;
|
|
11975
|
+
return statCollector.send("webRTCMetricsClientDescription", data);
|
|
11976
|
+
case 1:
|
|
11977
|
+
return _context6.a(2);
|
|
11978
|
+
}
|
|
11979
|
+
}, _callee6);
|
|
11980
|
+
}));
|
|
11981
|
+
function sendHeaders() {
|
|
11982
|
+
return _sendHeaders.apply(this, arguments);
|
|
11952
11983
|
}
|
|
11953
|
-
|
|
11984
|
+
return sendHeaders;
|
|
11985
|
+
}(),
|
|
11986
|
+
send: function () {
|
|
11987
|
+
var _send = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(message, data) {
|
|
11988
|
+
return _regenerator().w(function (_context7) {
|
|
11989
|
+
while (1) switch (_context7.n) {
|
|
11990
|
+
case 0:
|
|
11991
|
+
if (!(statCollector.connection.status === CONNECTION_STATUS.INIT || statCollector.connection.status === CONNECTION_STATUS.OK)) {
|
|
11992
|
+
_context7.n = 2;
|
|
11993
|
+
break;
|
|
11994
|
+
}
|
|
11995
|
+
statCollector.logger.debug(LOG_PREFIX + "-" + statCollector.id, data);
|
|
11996
|
+
_context7.n = 1;
|
|
11997
|
+
return statCollector.connection.send(message, data);
|
|
11998
|
+
case 1:
|
|
11999
|
+
if (statCollector.connection.status !== CONNECTION_STATUS.OK) {
|
|
12000
|
+
statCollector.logger.error(LOG_PREFIX + "-" + statCollector.id, "Error " + statCollector.connection.status + " sending RTC metrics to the server, stop sending");
|
|
12001
|
+
statCollector.stop();
|
|
12002
|
+
}
|
|
12003
|
+
case 2:
|
|
12004
|
+
return _context7.a(2);
|
|
12005
|
+
}
|
|
12006
|
+
}, _callee7);
|
|
12007
|
+
}));
|
|
12008
|
+
function send(_x3, _x4) {
|
|
12009
|
+
return _send.apply(this, arguments);
|
|
12010
|
+
}
|
|
12011
|
+
return send;
|
|
12012
|
+
}(),
|
|
11954
12013
|
startTimer: function startTimer() {
|
|
11955
12014
|
if (!statCollector.timer && statCollector.headers) {
|
|
11956
12015
|
statCollector.batchCount = statCollector.description.batchSize;
|
|
@@ -11965,22 +12024,22 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
11965
12024
|
}
|
|
11966
12025
|
},
|
|
11967
12026
|
collectMetrics: function () {
|
|
11968
|
-
var _collectMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
12027
|
+
var _collectMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
11969
12028
|
var stats, metrics, lostMetrics, headersUpdated;
|
|
11970
|
-
return _regenerator().w(function (
|
|
11971
|
-
while (1) switch (
|
|
12029
|
+
return _regenerator().w(function (_context8) {
|
|
12030
|
+
while (1) switch (_context8.n) {
|
|
11972
12031
|
case 0:
|
|
11973
12032
|
if (!(statCollector.timer && !statCollector.timerBusy)) {
|
|
11974
|
-
|
|
12033
|
+
_context8.n = 7;
|
|
11975
12034
|
break;
|
|
11976
12035
|
}
|
|
11977
12036
|
// Unfortunately there are no real atomics in JS unless SharedArrayBuffer is used
|
|
11978
12037
|
// So we guard the timer callback with a dumb boolean
|
|
11979
12038
|
statCollector.timerBusy = true;
|
|
11980
|
-
|
|
12039
|
+
_context8.n = 1;
|
|
11981
12040
|
return statCollector.mediaConnection.getWebRTCStats();
|
|
11982
12041
|
case 1:
|
|
11983
|
-
stats =
|
|
12042
|
+
stats = _context8.v;
|
|
11984
12043
|
statCollector.startNewBatch();
|
|
11985
12044
|
metrics = [];
|
|
11986
12045
|
lostMetrics = [];
|
|
@@ -12016,42 +12075,45 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
12016
12075
|
}
|
|
12017
12076
|
});
|
|
12018
12077
|
// Metrics list may change if some metrics are added or some metrics are lost #WCS-4627
|
|
12019
|
-
|
|
12078
|
+
_context8.n = 2;
|
|
12020
12079
|
return statCollector.updateHeaders(stats);
|
|
12021
12080
|
case 2:
|
|
12022
|
-
headersUpdated =
|
|
12081
|
+
headersUpdated = _context8.v;
|
|
12023
12082
|
if (!lostMetrics.length) {
|
|
12024
|
-
|
|
12083
|
+
_context8.n = 4;
|
|
12025
12084
|
break;
|
|
12026
12085
|
}
|
|
12027
12086
|
statCollector.logger.info(LOG_PREFIX + "-" + statCollector.id, "Missing metrics: " + JSON.stringify(lostMetrics));
|
|
12028
12087
|
// Send metrics already collected and start a new batch with current metrics array to send them later #WCS-4627
|
|
12029
|
-
|
|
12088
|
+
_context8.n = 3;
|
|
12030
12089
|
return statCollector.sendMetrics();
|
|
12031
12090
|
case 3:
|
|
12032
12091
|
statCollector.startNewBatch(metrics);
|
|
12033
|
-
|
|
12092
|
+
_context8.n = 5;
|
|
12034
12093
|
break;
|
|
12035
12094
|
case 4:
|
|
12036
12095
|
statCollector.metricsBatch.push(metrics);
|
|
12037
12096
|
statCollector.batchCount--;
|
|
12038
12097
|
if (!(statCollector.batchCount === 0 || headersUpdated)) {
|
|
12039
|
-
|
|
12098
|
+
_context8.n = 5;
|
|
12040
12099
|
break;
|
|
12041
12100
|
}
|
|
12042
|
-
|
|
12101
|
+
_context8.n = 5;
|
|
12043
12102
|
return statCollector.sendMetrics();
|
|
12044
12103
|
case 5:
|
|
12045
|
-
|
|
12046
|
-
|
|
12047
|
-
|
|
12048
|
-
statCollector.sendHeaders();
|
|
12104
|
+
if (!headersUpdated) {
|
|
12105
|
+
_context8.n = 6;
|
|
12106
|
+
break;
|
|
12049
12107
|
}
|
|
12050
|
-
statCollector.
|
|
12108
|
+
statCollector.logger.info(LOG_PREFIX + "-" + statCollector.id, "RTC metrics list has changed, sending a new metrics description");
|
|
12109
|
+
_context8.n = 6;
|
|
12110
|
+
return statCollector.sendHeaders();
|
|
12051
12111
|
case 6:
|
|
12052
|
-
|
|
12112
|
+
statCollector.timerBusy = false;
|
|
12113
|
+
case 7:
|
|
12114
|
+
return _context8.a(2);
|
|
12053
12115
|
}
|
|
12054
|
-
},
|
|
12116
|
+
}, _callee8);
|
|
12055
12117
|
}));
|
|
12056
12118
|
function collectMetrics() {
|
|
12057
12119
|
return _collectMetrics.apply(this, arguments);
|
|
@@ -12059,10 +12121,10 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
12059
12121
|
return collectMetrics;
|
|
12060
12122
|
}(),
|
|
12061
12123
|
sendMetrics: function () {
|
|
12062
|
-
var _sendMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
12124
|
+
var _sendMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9() {
|
|
12063
12125
|
var previous, metricsToSend, metricsData, i, metricsString, j, valueString, previousString, delimiter, data, _t3;
|
|
12064
|
-
return _regenerator().w(function (
|
|
12065
|
-
while (1) switch (
|
|
12126
|
+
return _regenerator().w(function (_context9) {
|
|
12127
|
+
while (1) switch (_context9.p = _context9.n) {
|
|
12066
12128
|
case 0:
|
|
12067
12129
|
metricsToSend = [];
|
|
12068
12130
|
for (i = 0; statCollector.metricsBatch && i < statCollector.metricsBatch.length; i++) {
|
|
@@ -12086,39 +12148,43 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
12086
12148
|
metricsToSend.push(metricsString);
|
|
12087
12149
|
}
|
|
12088
12150
|
if (!(statCollector.compression !== "none")) {
|
|
12089
|
-
|
|
12151
|
+
_context9.n = 5;
|
|
12090
12152
|
break;
|
|
12091
12153
|
}
|
|
12092
|
-
|
|
12093
|
-
|
|
12154
|
+
_context9.p = 1;
|
|
12155
|
+
_context9.n = 2;
|
|
12094
12156
|
return util.compress(statCollector.compression, JSON.stringify(metricsToSend), true);
|
|
12095
12157
|
case 2:
|
|
12096
|
-
metricsData =
|
|
12097
|
-
|
|
12158
|
+
metricsData = _context9.v;
|
|
12159
|
+
_context9.n = 4;
|
|
12098
12160
|
break;
|
|
12099
12161
|
case 3:
|
|
12100
|
-
|
|
12101
|
-
_t3 =
|
|
12162
|
+
_context9.p = 3;
|
|
12163
|
+
_t3 = _context9.v;
|
|
12102
12164
|
statCollector.logger.warn(LOG_PREFIX + "-" + statCollector.id, "Can't send metrics data using" + statCollector.compression + ": " + _t3);
|
|
12103
12165
|
metricsData = null;
|
|
12104
12166
|
case 4:
|
|
12105
|
-
|
|
12167
|
+
_context9.n = 6;
|
|
12106
12168
|
break;
|
|
12107
12169
|
case 5:
|
|
12108
12170
|
metricsData = metricsToSend;
|
|
12109
12171
|
case 6:
|
|
12110
|
-
if (metricsData) {
|
|
12111
|
-
|
|
12112
|
-
|
|
12113
|
-
metrics: metricsData
|
|
12114
|
-
};
|
|
12115
|
-
statCollector.send("webRTCMetricsBatch", data);
|
|
12172
|
+
if (!metricsData) {
|
|
12173
|
+
_context9.n = 7;
|
|
12174
|
+
break;
|
|
12116
12175
|
}
|
|
12117
|
-
|
|
12176
|
+
data = {
|
|
12177
|
+
mediaSessionId: statCollector.id,
|
|
12178
|
+
metrics: metricsData
|
|
12179
|
+
};
|
|
12180
|
+
_context9.n = 7;
|
|
12181
|
+
return statCollector.send("webRTCMetricsBatch", data);
|
|
12118
12182
|
case 7:
|
|
12119
|
-
|
|
12183
|
+
statCollector.cleanBatch();
|
|
12184
|
+
case 8:
|
|
12185
|
+
return _context9.a(2);
|
|
12120
12186
|
}
|
|
12121
|
-
},
|
|
12187
|
+
}, _callee9, null, [[1, 3]]);
|
|
12122
12188
|
}));
|
|
12123
12189
|
function sendMetrics() {
|
|
12124
12190
|
return _sendMetrics.apply(this, arguments);
|
|
@@ -12143,6 +12209,163 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
|
|
|
12143
12209
|
return statCollector;
|
|
12144
12210
|
};
|
|
12145
12211
|
|
|
12212
|
+
// Wrapper to send metrics via Websocket or HTTP POST
|
|
12213
|
+
var Connection = function Connection() {
|
|
12214
|
+
var existingConnection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
12215
|
+
var maxErrors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : MAX_SEND_ERRORS;
|
|
12216
|
+
var connection = {
|
|
12217
|
+
type: "",
|
|
12218
|
+
websocket: null,
|
|
12219
|
+
http: null,
|
|
12220
|
+
maxErrors: maxErrors,
|
|
12221
|
+
errorsCount: 0,
|
|
12222
|
+
status: CONNECTION_STATUS.INIT,
|
|
12223
|
+
setUp: function setUp(url) {
|
|
12224
|
+
var headers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
12225
|
+
var existingConnection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
12226
|
+
if (url.startsWith(CONNECTION_TYPE.WEBSOCKET)) {
|
|
12227
|
+
connection.type = CONNECTION_TYPE.WEBSOCKET;
|
|
12228
|
+
// ToDo: create a new Websocket connection
|
|
12229
|
+
} else if (url.startsWith(CONNECTION_TYPE.HTTP)) {
|
|
12230
|
+
connection.type = CONNECTION_TYPE.HTTP;
|
|
12231
|
+
connection.http = HttpConnection(url, headers);
|
|
12232
|
+
} else if (existingConnection) {
|
|
12233
|
+
connection.type = CONNECTION_TYPE.WEBSOCKET;
|
|
12234
|
+
connection.websocket = WebsocketConnection(existingConnection);
|
|
12235
|
+
}
|
|
12236
|
+
connection.errorsCount = 0;
|
|
12237
|
+
connection.status = CONNECTION_STATUS.INIT;
|
|
12238
|
+
},
|
|
12239
|
+
send: function () {
|
|
12240
|
+
var _send2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(message, data) {
|
|
12241
|
+
var code, _t4;
|
|
12242
|
+
return _regenerator().w(function (_context0) {
|
|
12243
|
+
while (1) switch (_context0.n) {
|
|
12244
|
+
case 0:
|
|
12245
|
+
code = CONNECTION_STATUS.BAD_REQUEST;
|
|
12246
|
+
_t4 = connection.type;
|
|
12247
|
+
_context0.n = _t4 === CONNECTION_TYPE.WEBSOCKET ? 1 : _t4 === CONNECTION_TYPE.HTTP ? 2 : 5;
|
|
12248
|
+
break;
|
|
12249
|
+
case 1:
|
|
12250
|
+
if (connection.websocket) {
|
|
12251
|
+
code = connection.websocket.send(message, data);
|
|
12252
|
+
}
|
|
12253
|
+
return _context0.a(3, 5);
|
|
12254
|
+
case 2:
|
|
12255
|
+
if (!connection.http) {
|
|
12256
|
+
_context0.n = 4;
|
|
12257
|
+
break;
|
|
12258
|
+
}
|
|
12259
|
+
_context0.n = 3;
|
|
12260
|
+
return connection.http.send(message, data);
|
|
12261
|
+
case 3:
|
|
12262
|
+
code = _context0.v;
|
|
12263
|
+
case 4:
|
|
12264
|
+
return _context0.a(3, 5);
|
|
12265
|
+
case 5:
|
|
12266
|
+
connection.status = code;
|
|
12267
|
+
if (connection.status === CONNECTION_STATUS.OK) {
|
|
12268
|
+
connection.errorsCount = 0;
|
|
12269
|
+
} else {
|
|
12270
|
+
if (message === "webRTCMetricsBatch") {
|
|
12271
|
+
connection.errorsCount++;
|
|
12272
|
+
if (connection.errorsCount < connection.maxErrors) {
|
|
12273
|
+
connection.status = CONNECTION_STATUS.OK;
|
|
12274
|
+
}
|
|
12275
|
+
}
|
|
12276
|
+
}
|
|
12277
|
+
case 6:
|
|
12278
|
+
return _context0.a(2);
|
|
12279
|
+
}
|
|
12280
|
+
}, _callee0);
|
|
12281
|
+
}));
|
|
12282
|
+
function send(_x5, _x6) {
|
|
12283
|
+
return _send2.apply(this, arguments);
|
|
12284
|
+
}
|
|
12285
|
+
return send;
|
|
12286
|
+
}()
|
|
12287
|
+
};
|
|
12288
|
+
connection.setUp("", null, existingConnection);
|
|
12289
|
+
return connection;
|
|
12290
|
+
};
|
|
12291
|
+
|
|
12292
|
+
// Websocket connection (using existing one)
|
|
12293
|
+
var WebsocketConnection = function WebsocketConnection(wsConnection) {
|
|
12294
|
+
var connection = {
|
|
12295
|
+
websocket: wsConnection,
|
|
12296
|
+
send: function send(message, data) {
|
|
12297
|
+
var code = CONNECTION_STATUS.BAD_REQUEST;
|
|
12298
|
+
if (connection.websocket) {
|
|
12299
|
+
console.log(connection.websocket);
|
|
12300
|
+
if (connection.websocket.readyState === WebSocket.OPEN) {
|
|
12301
|
+
connection.websocket.send(JSON.stringify({
|
|
12302
|
+
message: message,
|
|
12303
|
+
data: [data]
|
|
12304
|
+
}));
|
|
12305
|
+
}
|
|
12306
|
+
code = CONNECTION_STATUS.OK;
|
|
12307
|
+
}
|
|
12308
|
+
return code;
|
|
12309
|
+
}
|
|
12310
|
+
};
|
|
12311
|
+
return connection;
|
|
12312
|
+
};
|
|
12313
|
+
|
|
12314
|
+
// HTTP connection using Fetch API
|
|
12315
|
+
var HttpConnection = function HttpConnection(url, headers) {
|
|
12316
|
+
var connection = {
|
|
12317
|
+
url: addSlash(url),
|
|
12318
|
+
headers: headers,
|
|
12319
|
+
send: function () {
|
|
12320
|
+
var _send3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(message, data) {
|
|
12321
|
+
var code, httpHeaders, _i2, _Object$entries, _Object$entries$_i, header, value, response, _t5;
|
|
12322
|
+
return _regenerator().w(function (_context1) {
|
|
12323
|
+
while (1) switch (_context1.p = _context1.n) {
|
|
12324
|
+
case 0:
|
|
12325
|
+
code = CONNECTION_STATUS.BAD_REQUEST;
|
|
12326
|
+
if (!connection.url) {
|
|
12327
|
+
_context1.n = 4;
|
|
12328
|
+
break;
|
|
12329
|
+
}
|
|
12330
|
+
_context1.p = 1;
|
|
12331
|
+
httpHeaders = new Headers();
|
|
12332
|
+
httpHeaders.append("Content-Type", "application/json");
|
|
12333
|
+
if (connection.headers) {
|
|
12334
|
+
for (_i2 = 0, _Object$entries = Object.entries(connection.headers); _i2 < _Object$entries.length; _i2++) {
|
|
12335
|
+
_Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2), header = _Object$entries$_i[0], value = _Object$entries$_i[1];
|
|
12336
|
+
httpHeaders.append(header, value);
|
|
12337
|
+
}
|
|
12338
|
+
}
|
|
12339
|
+
_context1.n = 2;
|
|
12340
|
+
return fetch(connection.url + message, {
|
|
12341
|
+
method: "POST",
|
|
12342
|
+
headers: httpHeaders,
|
|
12343
|
+
mode: "cors",
|
|
12344
|
+
body: JSON.stringify(data)
|
|
12345
|
+
});
|
|
12346
|
+
case 2:
|
|
12347
|
+
response = _context1.v;
|
|
12348
|
+
code = response.status;
|
|
12349
|
+
_context1.n = 4;
|
|
12350
|
+
break;
|
|
12351
|
+
case 3:
|
|
12352
|
+
_context1.p = 3;
|
|
12353
|
+
_t5 = _context1.v;
|
|
12354
|
+
code = CONNECTION_STATUS.INTERNAL_SERVER_ERROR;
|
|
12355
|
+
case 4:
|
|
12356
|
+
return _context1.a(2, code);
|
|
12357
|
+
}
|
|
12358
|
+
}, _callee1, null, [[1, 3]]);
|
|
12359
|
+
}));
|
|
12360
|
+
function send(_x7, _x8) {
|
|
12361
|
+
return _send3.apply(this, arguments);
|
|
12362
|
+
}
|
|
12363
|
+
return send;
|
|
12364
|
+
}()
|
|
12365
|
+
};
|
|
12366
|
+
return connection;
|
|
12367
|
+
};
|
|
12368
|
+
|
|
12146
12369
|
// Helper function to stringify a value
|
|
12147
12370
|
var valueToString = function valueToString(value) {
|
|
12148
12371
|
var valueString = "undefined";
|
|
@@ -12168,6 +12391,15 @@ var getLogger = function getLogger(logger) {
|
|
|
12168
12391
|
debug: function debug() {}
|
|
12169
12392
|
};
|
|
12170
12393
|
};
|
|
12394
|
+
|
|
12395
|
+
// Helper function to add slash to endpoint
|
|
12396
|
+
var addSlash = function addSlash(value) {
|
|
12397
|
+
var endpoint = value;
|
|
12398
|
+
if (endpoint && !endpoint.endsWith("/")) {
|
|
12399
|
+
endpoint = endpoint + "/";
|
|
12400
|
+
}
|
|
12401
|
+
return endpoint;
|
|
12402
|
+
};
|
|
12171
12403
|
module.exports = {
|
|
12172
12404
|
StreamStatsCollector: StreamStatsCollector
|
|
12173
12405
|
};
|