@flashphoner/websdk 2.0.271 → 2.0.274

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.
@@ -8171,6 +8171,34 @@ var getMediaDevices = function getMediaDevices(mediaProvider, labels, kind, devi
8171
8171
  return MediaProvider[mediaProvider].listDevices(labels, kind, deviceConstraints);
8172
8172
  };
8173
8173
 
8174
+ /**
8175
+ * Get mobile local media devices
8176
+ *
8177
+ * @param {String=} mediaProvider Media provider that will be asked for device list
8178
+ * @param {Flashphoner.constants.MEDIA_DEVICE_KIND} kind Media devices kind to access:
8179
+ * MEDIA_DEVICE_KIND.INPUT (default) get access to input devices only (camera, mic).
8180
+ * MEDIA_DEVICE_KIND.OUTPUT get access to output devices only (speaker, headphone).
8181
+ * MEDIA_DEVICE_KIND.ALL get access to all devices (cam, mic, speaker, headphone).
8182
+ * @param {Object=} deviceConstraints
8183
+ * If {audio: true, video: false}, then access to the camera will not be requested.
8184
+ * If {audio: false, video: true}, then access to the microphone will not be requested.
8185
+ * @returns {Promise.<Flashphoner.MediaDeviceList>} Promise with media device list on fulfill
8186
+ * @throws {Error} Error if API is not initialized
8187
+ * @memberof Flashphoner
8188
+ */
8189
+ var getMobileDevices = function getMobileDevices(mediaProvider, kind, deviceConstraints) {
8190
+ if (!initialized) {
8191
+ throw new Error("Flashphoner API is not initialized");
8192
+ }
8193
+ if (!mediaProvider) {
8194
+ mediaProvider = getMediaProviders()[0];
8195
+ }
8196
+ if (MediaProvider[mediaProvider].getMobileDevices) {
8197
+ return MediaProvider[mediaProvider].getMobileDevices(kind, deviceConstraints);
8198
+ }
8199
+ return [];
8200
+ };
8201
+
8174
8202
  /**
8175
8203
  * Get access to local media
8176
8204
  *
@@ -8608,36 +8636,19 @@ var createSession = function createSession(options) {
8608
8636
  streamRefreshHandlers[obj.mediaSessionId](obj);
8609
8637
  }
8610
8638
  break;
8611
- case "webRTCMetricsDescriptionUpdate":
8612
- if (obj.ids) {
8613
- obj.ids.forEach(function (id) {
8614
- if (streamRefreshHandlers[id]) {
8615
- streamRefreshHandlers[id](obj);
8616
- }
8617
- });
8618
- } else {
8619
- if (obj.compression) {
8620
- webRTCMetricsServerDescription.compression = obj.compression;
8621
- }
8622
- if (obj.batchSize) {
8623
- webRTCMetricsServerDescription.batchSize = obj.batchSize;
8624
- }
8625
- if (obj.sampling) {
8626
- webRTCMetricsServerDescription.sampling = obj.sampling;
8627
- }
8628
- if (obj.types) {
8629
- webRTCMetricsServerDescription.types = obj.types;
8630
- }
8631
- if (obj.collect) {
8632
- webRTCMetricsServerDescription.collect = obj.collect;
8633
- }
8634
- for (var _i = 0, _Object$entries = Object.entries(streamRefreshHandlers); _i < _Object$entries.length; _i++) {
8635
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
8636
- _id = _Object$entries$_i[0],
8637
- handler = _Object$entries$_i[1];
8638
- handler(obj);
8639
- }
8640
- }
8639
+ case 'webRTCMetricsDescriptionUpdate':
8640
+ handleWebRTCMetricsUpdate(obj, {
8641
+ compression: "compression",
8642
+ batchSize: "batchSize",
8643
+ sampling: "sampling",
8644
+ types: "types",
8645
+ collect: "collect"
8646
+ });
8647
+ break;
8648
+ case 'webRTCMetricsTokenRefresh':
8649
+ handleWebRTCMetricsUpdate(obj, {
8650
+ authorization: "authorization"
8651
+ });
8641
8652
  break;
8642
8653
  default:
8643
8654
  logger.info(LOG_PREFIX, "Unknown server message " + data.message);
@@ -8647,6 +8658,31 @@ var createSession = function createSession(options) {
8647
8658
  wsPingReceiver.success();
8648
8659
  };
8649
8660
  }
8661
+ function handleWebRTCMetricsUpdate(obj) {
8662
+ var updateFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8663
+ if (obj.ids) {
8664
+ obj.ids.forEach(function (id) {
8665
+ if (streamRefreshHandlers[id]) {
8666
+ streamRefreshHandlers[id](obj);
8667
+ }
8668
+ });
8669
+ } else {
8670
+ Object.entries(updateFields).forEach(function (_ref2) {
8671
+ var _ref3 = _slicedToArray(_ref2, 2),
8672
+ key = _ref3[0],
8673
+ value = _ref3[1];
8674
+ if (obj[value] !== undefined) {
8675
+ webRTCMetricsServerDescription[key] = obj[value];
8676
+ }
8677
+ });
8678
+ for (var _i = 0, _Object$entries = Object.entries(streamRefreshHandlers); _i < _Object$entries.length; _i++) {
8679
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
8680
+ _id = _Object$entries$_i[0],
8681
+ handler = _Object$entries$_i[1];
8682
+ handler(obj);
8683
+ }
8684
+ }
8685
+ }
8650
8686
 
8651
8687
  //WebSocket send helper
8652
8688
  function send(message, data) {
@@ -9781,6 +9817,10 @@ var createSession = function createSession(options) {
9781
9817
  statsCollector.start();
9782
9818
  }
9783
9819
  }
9820
+ if (streamInfo.authorization && statsCollector && statsCollector.description.ingestPoint) {
9821
+ statsCollector.description.authorization = streamInfo.authorization;
9822
+ statsCollector.updateHttpConnection(statsCollector.description.ingestPoint, statsCollector.description.authorization);
9823
+ }
9784
9824
 
9785
9825
  // Pause or resume metrics collection
9786
9826
  if (!streamInfo.status && streamInfo.collect !== undefined && statsCollector) {
@@ -10635,7 +10675,7 @@ var createSession = function createSession(options) {
10635
10675
  * @memberof Stream
10636
10676
  */
10637
10677
  var setZoom = /*#__PURE__*/function () {
10638
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(value) {
10678
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(value) {
10639
10679
  return _regenerator().w(function (_context2) {
10640
10680
  while (1) switch (_context2.n) {
10641
10681
  case 0:
@@ -10655,7 +10695,7 @@ var createSession = function createSession(options) {
10655
10695
  }, _callee2);
10656
10696
  }));
10657
10697
  return function setZoom(_x2) {
10658
- return _ref2.apply(this, arguments);
10698
+ return _ref4.apply(this, arguments);
10659
10699
  };
10660
10700
  }();
10661
10701
  stream.play = play;
@@ -11007,6 +11047,7 @@ module.exports = {
11007
11047
  isUsingTemasys: isUsingTemasys,
11008
11048
  getMediaProviders: getMediaProviders,
11009
11049
  getMediaDevices: getMediaDevices,
11050
+ getMobileDevices: getMobileDevices,
11010
11051
  getMediaAccess: getMediaAccess,
11011
11052
  releaseLocalMedia: releaseLocalMedia,
11012
11053
  getSessions: getSessions,
@@ -11936,6 +11977,11 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
11936
11977
  }
11937
11978
  return updateCompression;
11938
11979
  }(),
11980
+ updateHttpConnection: function updateHttpConnection(url, authorization) {
11981
+ if (url.startsWith(CONNECTION_TYPE.HTTP) && authorization) {
11982
+ statCollector.connection.http.setAuthorization(authorization);
11983
+ }
11984
+ },
11939
11985
  checkForCompression: function () {
11940
11986
  var _checkForCompression = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(compression) {
11941
11987
  var _t2;
@@ -12027,6 +12073,9 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
12027
12073
  statCollector.metricsBatch = null;
12028
12074
  }
12029
12075
  },
12076
+ isMetricValid: function isMetricValid(value) {
12077
+ return value != null && value !== "" && value !== "undefined" && value !== "null";
12078
+ },
12030
12079
  collectMetrics: function () {
12031
12080
  var _collectMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
12032
12081
  var stats, metrics, lostMetrics, headersUpdated;
@@ -12073,7 +12122,7 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
12073
12122
  _iterator2.f();
12074
12123
  }
12075
12124
  }
12076
- if (value) {
12125
+ if (statCollector.isMetricValid(value)) {
12077
12126
  metrics.push(value);
12078
12127
  } else {
12079
12128
  lostMetrics.push(descriptor);
@@ -12327,6 +12376,9 @@ var HttpConnection = function HttpConnection(url, headers) {
12327
12376
  var connection = {
12328
12377
  url: addSlash(url),
12329
12378
  headers: headers,
12379
+ setAuthorization: function setAuthorization(token) {
12380
+ this.headers.Authorization = token;
12381
+ },
12330
12382
  send: function () {
12331
12383
  var _send3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(message, data) {
12332
12384
  var code, httpHeaders, _i2, _Object$entries, _Object$entries$_i, header, value, response, _t5;
@@ -14568,6 +14620,66 @@ var available = function available() {
14568
14620
  //return (adapter.browserDetails.browser != "edge") ? navigator.getUserMedia && RTCPeerConnection : false;
14569
14621
  return 'getUserMedia' in navigator && 'RTCPeerConnection' in window;
14570
14622
  };
14623
+
14624
+ /**
14625
+ * Helper function to get media devices list in id, label, type form
14626
+ *
14627
+ * @param devices
14628
+ * @param kind
14629
+ * @param videoFilter
14630
+ * @returns {{audio: *[], video: *[]}}
14631
+ */
14632
+ var getList = function getList(devices, kind) {
14633
+ var videoFilter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
14634
+ var list = {
14635
+ audio: [],
14636
+ video: []
14637
+ };
14638
+ var micCount = 0;
14639
+ var outputCount = 0;
14640
+ var camCount = 0;
14641
+ for (var i = 0; i < devices.length; i++) {
14642
+ var device = devices[i];
14643
+ var ret = {
14644
+ id: device.deviceId,
14645
+ label: device.label
14646
+ };
14647
+ if (device.kind.indexOf("audio" + kind) === 0 && device.deviceId !== "communications") {
14648
+ ret.type = device.kind === "audioinput" ? "mic" : "speaker";
14649
+ if (ret.type === "mic" && ret.label === "") {
14650
+ ret.label = 'microphone' + ++micCount;
14651
+ }
14652
+ if (ret.type === "speaker" && ret.label === "") {
14653
+ ret.label = 'speaker' + ++outputCount;
14654
+ }
14655
+ list.audio.push(ret);
14656
+ } else if (device.kind.indexOf("video" + kind) === 0) {
14657
+ if (!videoFilter || videoFilter.find(function (id) {
14658
+ return id === device.deviceId;
14659
+ })) {
14660
+ if (ret.label === "") {
14661
+ ret.label = 'camera' + ++camCount;
14662
+ }
14663
+ ret.type = "camera";
14664
+ list.video.push(ret);
14665
+ } else {
14666
+ logger.debug(LOG_PREFIX, "Video device " + device.deviceId + "does not conform the filter " + JSON.stringify(videoFilter));
14667
+ }
14668
+ } else {
14669
+ logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14670
+ }
14671
+ }
14672
+ return list;
14673
+ };
14674
+
14675
+ /**
14676
+ * Get media devices list
14677
+ *
14678
+ * @param labels
14679
+ * @param kind
14680
+ * @param deviceConstraints
14681
+ * @returns {Promise<{audio: [], video: []}>}
14682
+ */
14571
14683
  var listDevices = function listDevices(labels, kind, deviceConstraints) {
14572
14684
  //WCS-1963. added deviceConstraints.
14573
14685
  if (!deviceConstraints) {
@@ -14578,7 +14690,7 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14578
14690
  }
14579
14691
  if (!kind) {
14580
14692
  kind = constants.MEDIA_DEVICE_KIND.INPUT;
14581
- } else if (kind == "all") {
14693
+ } else if (kind === constants.MEDIA_DEVICE_KIND.ALL) {
14582
14694
  kind = "";
14583
14695
  }
14584
14696
  var getConstraints = function getConstraints(devices) {
@@ -14586,50 +14698,15 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14586
14698
  for (var i = 0; i < devices.length; i++) {
14587
14699
  var device = devices[i];
14588
14700
  if (device.kind.indexOf("audio" + kind) === 0 && deviceConstraints.audio) {
14589
- constraints.audio = true;
14701
+ constraints.audio = deviceConstraints.audio;
14590
14702
  } else if (device.kind.indexOf("video" + kind) === 0 && deviceConstraints.video) {
14591
- constraints.video = true;
14703
+ constraints.video = deviceConstraints.video;
14592
14704
  } else {
14593
14705
  logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14594
14706
  }
14595
14707
  }
14596
14708
  return constraints;
14597
14709
  };
14598
- var getList = function getList(devices) {
14599
- var list = {
14600
- audio: [],
14601
- video: []
14602
- };
14603
- var micCount = 0;
14604
- var outputCount = 0;
14605
- var camCount = 0;
14606
- for (var i = 0; i < devices.length; i++) {
14607
- var device = devices[i];
14608
- var ret = {
14609
- id: device.deviceId,
14610
- label: device.label
14611
- };
14612
- if (device.kind.indexOf("audio" + kind) === 0 && device.deviceId != "communications") {
14613
- ret.type = device.kind == "audioinput" ? "mic" : "speaker";
14614
- if (ret.type == "mic" && ret.label == "") {
14615
- ret.label = 'microphone' + ++micCount;
14616
- }
14617
- if (ret.type == "speaker" && ret.label == "") {
14618
- ret.label = 'speaker' + ++outputCount;
14619
- }
14620
- list.audio.push(ret);
14621
- } else if (device.kind.indexOf("video" + kind) === 0) {
14622
- if (ret.label == "") {
14623
- ret.label = 'camera' + ++camCount;
14624
- }
14625
- ret.type = "camera";
14626
- list.video.push(ret);
14627
- } else {
14628
- logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14629
- }
14630
- }
14631
- return list;
14632
- };
14633
14710
  return new Promise(function (resolve, reject) {
14634
14711
  navigator.mediaDevices.enumerateDevices().then(function (devices) {
14635
14712
  if (labels) {
@@ -14641,18 +14718,153 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14641
14718
  }
14642
14719
  navigator.getUserMedia(constraints, function (stream) {
14643
14720
  navigator.mediaDevices.enumerateDevices().then(function (devicesWithLabels) {
14644
- resolve(getList(devicesWithLabels));
14721
+ resolve(getList(devicesWithLabels, kind));
14645
14722
  stream.getTracks().forEach(function (track) {
14646
14723
  track.stop();
14647
14724
  });
14648
14725
  }, reject);
14649
14726
  }, reject);
14650
14727
  } else {
14651
- resolve(getList(devices));
14728
+ resolve(getList(devices, kind));
14652
14729
  }
14653
14730
  }, reject);
14654
14731
  });
14655
14732
  };
14733
+ var getMobileDevices = /*#__PURE__*/function () {
14734
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(kind) {
14735
+ var deviceConstraints,
14736
+ constraints,
14737
+ videoFilter,
14738
+ list,
14739
+ getCamera,
14740
+ front,
14741
+ back,
14742
+ _stream,
14743
+ mediaDevices,
14744
+ _args4 = arguments,
14745
+ _t2;
14746
+ return _regenerator().w(function (_context4) {
14747
+ while (1) switch (_context4.p = _context4.n) {
14748
+ case 0:
14749
+ deviceConstraints = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : null;
14750
+ constraints = {};
14751
+ videoFilter = [];
14752
+ list = null;
14753
+ if (!kind) {
14754
+ kind = constants.MEDIA_DEVICE_KIND.INPUT;
14755
+ } else if (kind === constants.MEDIA_DEVICE_KIND.ALL) {
14756
+ kind = "";
14757
+ }
14758
+ if (deviceConstraints && deviceConstraints.audio) {
14759
+ constraints.audio = deviceConstraints.audio;
14760
+ } else {
14761
+ constraints.audio = true;
14762
+ }
14763
+ if (deviceConstraints && deviceConstraints.video) {
14764
+ if (_typeof(deviceConstraints.video) === 'object') {
14765
+ constraints.video = deviceConstraints.video;
14766
+ } else {
14767
+ constraints.video = {};
14768
+ }
14769
+ } else {
14770
+ constraints.video = {};
14771
+ }
14772
+ getCamera = /*#__PURE__*/function () {
14773
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(constraints, facingMode) {
14774
+ var deviceId, mediaConstraints, _t;
14775
+ return _regenerator().w(function (_context3) {
14776
+ while (1) switch (_context3.p = _context3.n) {
14777
+ case 0:
14778
+ deviceId = null;
14779
+ mediaConstraints = {
14780
+ audio: false,
14781
+ video: constraints.video
14782
+ };
14783
+ mediaConstraints.video.facingMode = facingMode;
14784
+ _context3.p = 1;
14785
+ _context3.n = 2;
14786
+ return navigator.mediaDevices.getUserMedia(mediaConstraints);
14787
+ case 2:
14788
+ stream = _context3.v;
14789
+ if (stream) {
14790
+ if (stream.getVideoTracks().length > 0) {
14791
+ deviceId = stream.getVideoTracks()[0].getSettings().deviceId;
14792
+ }
14793
+ stream.getTracks().forEach(function (track) {
14794
+ track.stop();
14795
+ });
14796
+ }
14797
+ _context3.n = 4;
14798
+ break;
14799
+ case 3:
14800
+ _context3.p = 3;
14801
+ _t = _context3.v;
14802
+ logger.error(LOG_PREFIX, "Can't get device access with video constraints " + JSON.stringify(constraints.video) + ", error " + _t);
14803
+ case 4:
14804
+ return _context3.a(2, deviceId);
14805
+ }
14806
+ }, _callee3, null, [[1, 3]]);
14807
+ }));
14808
+ return function getCamera(_x5, _x6) {
14809
+ return _ref4.apply(this, arguments);
14810
+ };
14811
+ }();
14812
+ _context4.n = 1;
14813
+ return getCamera(constraints, {
14814
+ ideal: 'user'
14815
+ });
14816
+ case 1:
14817
+ front = _context4.v;
14818
+ if (front && front !== "") {
14819
+ logger.debug(LOG_PREFIX, "Front camera id: " + front);
14820
+ videoFilter.push(front);
14821
+ }
14822
+ _context4.n = 2;
14823
+ return getCamera(constraints, {
14824
+ ideal: 'environment'
14825
+ });
14826
+ case 2:
14827
+ back = _context4.v;
14828
+ if (back && back !== "") {
14829
+ logger.debug(LOG_PREFIX, "Back camera id: " + back);
14830
+ videoFilter.push(back);
14831
+ }
14832
+ _context4.p = 3;
14833
+ _context4.n = 4;
14834
+ return navigator.mediaDevices.getUserMedia(constraints);
14835
+ case 4:
14836
+ _stream = _context4.v;
14837
+ if (!_stream) {
14838
+ _context4.n = 6;
14839
+ break;
14840
+ }
14841
+ _context4.n = 5;
14842
+ return navigator.mediaDevices.enumerateDevices();
14843
+ case 5:
14844
+ mediaDevices = _context4.v;
14845
+ if (mediaDevices) {
14846
+ logger.debug(LOG_PREFIX, "mediaDevices: " + JSON.stringify(mediaDevices));
14847
+ list = getList(mediaDevices, kind, videoFilter);
14848
+ }
14849
+ _stream.getTracks().forEach(function (track) {
14850
+ track.stop();
14851
+ });
14852
+ case 6:
14853
+ _context4.n = 8;
14854
+ break;
14855
+ case 7:
14856
+ _context4.p = 7;
14857
+ _t2 = _context4.v;
14858
+ logger.error(LOG_PREFIX, "Can't get device access with constraints " + JSON.stringify(constraints) + ", error " + _t2);
14859
+ case 8:
14860
+ return _context4.a(2, list);
14861
+ }
14862
+ }, _callee4, null, [[3, 7]]);
14863
+ }));
14864
+ return function getMobileDevices(_x4) {
14865
+ return _ref3.apply(this, arguments);
14866
+ };
14867
+ }();
14656
14868
  function normalizeConstraints(constraints) {
14657
14869
  //WCS-2010. fixed TypeError after publish->stop->publish
14658
14870
  //WCS-2373. fixed customStream
@@ -14781,6 +14993,7 @@ module.exports = {
14781
14993
  getMediaAccess: getMediaAccess,
14782
14994
  releaseMedia: releaseMedia,
14783
14995
  listDevices: listDevices,
14996
+ getMobileDevices: getMobileDevices,
14784
14997
  playFirstSound: playFirstSound,
14785
14998
  playFirstVideo: playFirstVideo,
14786
14999
  available: available,