@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,
@@ -11364,6 +11405,11 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
11364
11405
  }
11365
11406
  return updateCompression;
11366
11407
  }(),
11408
+ updateHttpConnection: function updateHttpConnection(url, authorization) {
11409
+ if (url.startsWith(CONNECTION_TYPE.HTTP) && authorization) {
11410
+ statCollector.connection.http.setAuthorization(authorization);
11411
+ }
11412
+ },
11367
11413
  checkForCompression: function () {
11368
11414
  var _checkForCompression = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(compression) {
11369
11415
  var _t2;
@@ -11455,6 +11501,9 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
11455
11501
  statCollector.metricsBatch = null;
11456
11502
  }
11457
11503
  },
11504
+ isMetricValid: function isMetricValid(value) {
11505
+ return value != null && value !== "" && value !== "undefined" && value !== "null";
11506
+ },
11458
11507
  collectMetrics: function () {
11459
11508
  var _collectMetrics = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
11460
11509
  var stats, metrics, lostMetrics, headersUpdated;
@@ -11501,7 +11550,7 @@ var StreamStatsCollector = function StreamStatsCollector(description, id, mediaC
11501
11550
  _iterator2.f();
11502
11551
  }
11503
11552
  }
11504
- if (value) {
11553
+ if (statCollector.isMetricValid(value)) {
11505
11554
  metrics.push(value);
11506
11555
  } else {
11507
11556
  lostMetrics.push(descriptor);
@@ -11755,6 +11804,9 @@ var HttpConnection = function HttpConnection(url, headers) {
11755
11804
  var connection = {
11756
11805
  url: addSlash(url),
11757
11806
  headers: headers,
11807
+ setAuthorization: function setAuthorization(token) {
11808
+ this.headers.Authorization = token;
11809
+ },
11758
11810
  send: function () {
11759
11811
  var _send3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(message, data) {
11760
11812
  var code, httpHeaders, _i2, _Object$entries, _Object$entries$_i, header, value, response, _t5;
@@ -13996,6 +14048,66 @@ var available = function available() {
13996
14048
  //return (adapter.browserDetails.browser != "edge") ? navigator.getUserMedia && RTCPeerConnection : false;
13997
14049
  return 'getUserMedia' in navigator && 'RTCPeerConnection' in window;
13998
14050
  };
14051
+
14052
+ /**
14053
+ * Helper function to get media devices list in id, label, type form
14054
+ *
14055
+ * @param devices
14056
+ * @param kind
14057
+ * @param videoFilter
14058
+ * @returns {{audio: *[], video: *[]}}
14059
+ */
14060
+ var getList = function getList(devices, kind) {
14061
+ var videoFilter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
14062
+ var list = {
14063
+ audio: [],
14064
+ video: []
14065
+ };
14066
+ var micCount = 0;
14067
+ var outputCount = 0;
14068
+ var camCount = 0;
14069
+ for (var i = 0; i < devices.length; i++) {
14070
+ var device = devices[i];
14071
+ var ret = {
14072
+ id: device.deviceId,
14073
+ label: device.label
14074
+ };
14075
+ if (device.kind.indexOf("audio" + kind) === 0 && device.deviceId !== "communications") {
14076
+ ret.type = device.kind === "audioinput" ? "mic" : "speaker";
14077
+ if (ret.type === "mic" && ret.label === "") {
14078
+ ret.label = 'microphone' + ++micCount;
14079
+ }
14080
+ if (ret.type === "speaker" && ret.label === "") {
14081
+ ret.label = 'speaker' + ++outputCount;
14082
+ }
14083
+ list.audio.push(ret);
14084
+ } else if (device.kind.indexOf("video" + kind) === 0) {
14085
+ if (!videoFilter || videoFilter.find(function (id) {
14086
+ return id === device.deviceId;
14087
+ })) {
14088
+ if (ret.label === "") {
14089
+ ret.label = 'camera' + ++camCount;
14090
+ }
14091
+ ret.type = "camera";
14092
+ list.video.push(ret);
14093
+ } else {
14094
+ logger.debug(LOG_PREFIX, "Video device " + device.deviceId + "does not conform the filter " + JSON.stringify(videoFilter));
14095
+ }
14096
+ } else {
14097
+ logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14098
+ }
14099
+ }
14100
+ return list;
14101
+ };
14102
+
14103
+ /**
14104
+ * Get media devices list
14105
+ *
14106
+ * @param labels
14107
+ * @param kind
14108
+ * @param deviceConstraints
14109
+ * @returns {Promise<{audio: [], video: []}>}
14110
+ */
13999
14111
  var listDevices = function listDevices(labels, kind, deviceConstraints) {
14000
14112
  //WCS-1963. added deviceConstraints.
14001
14113
  if (!deviceConstraints) {
@@ -14006,7 +14118,7 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14006
14118
  }
14007
14119
  if (!kind) {
14008
14120
  kind = constants.MEDIA_DEVICE_KIND.INPUT;
14009
- } else if (kind == "all") {
14121
+ } else if (kind === constants.MEDIA_DEVICE_KIND.ALL) {
14010
14122
  kind = "";
14011
14123
  }
14012
14124
  var getConstraints = function getConstraints(devices) {
@@ -14014,50 +14126,15 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14014
14126
  for (var i = 0; i < devices.length; i++) {
14015
14127
  var device = devices[i];
14016
14128
  if (device.kind.indexOf("audio" + kind) === 0 && deviceConstraints.audio) {
14017
- constraints.audio = true;
14129
+ constraints.audio = deviceConstraints.audio;
14018
14130
  } else if (device.kind.indexOf("video" + kind) === 0 && deviceConstraints.video) {
14019
- constraints.video = true;
14131
+ constraints.video = deviceConstraints.video;
14020
14132
  } else {
14021
14133
  logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14022
14134
  }
14023
14135
  }
14024
14136
  return constraints;
14025
14137
  };
14026
- var getList = function getList(devices) {
14027
- var list = {
14028
- audio: [],
14029
- video: []
14030
- };
14031
- var micCount = 0;
14032
- var outputCount = 0;
14033
- var camCount = 0;
14034
- for (var i = 0; i < devices.length; i++) {
14035
- var device = devices[i];
14036
- var ret = {
14037
- id: device.deviceId,
14038
- label: device.label
14039
- };
14040
- if (device.kind.indexOf("audio" + kind) === 0 && device.deviceId != "communications") {
14041
- ret.type = device.kind == "audioinput" ? "mic" : "speaker";
14042
- if (ret.type == "mic" && ret.label == "") {
14043
- ret.label = 'microphone' + ++micCount;
14044
- }
14045
- if (ret.type == "speaker" && ret.label == "") {
14046
- ret.label = 'speaker' + ++outputCount;
14047
- }
14048
- list.audio.push(ret);
14049
- } else if (device.kind.indexOf("video" + kind) === 0) {
14050
- if (ret.label == "") {
14051
- ret.label = 'camera' + ++camCount;
14052
- }
14053
- ret.type = "camera";
14054
- list.video.push(ret);
14055
- } else {
14056
- logger.debug(LOG_PREFIX, "unknown device " + device.kind + " id " + device.deviceId);
14057
- }
14058
- }
14059
- return list;
14060
- };
14061
14138
  return new Promise(function (resolve, reject) {
14062
14139
  navigator.mediaDevices.enumerateDevices().then(function (devices) {
14063
14140
  if (labels) {
@@ -14069,18 +14146,153 @@ var listDevices = function listDevices(labels, kind, deviceConstraints) {
14069
14146
  }
14070
14147
  navigator.getUserMedia(constraints, function (stream) {
14071
14148
  navigator.mediaDevices.enumerateDevices().then(function (devicesWithLabels) {
14072
- resolve(getList(devicesWithLabels));
14149
+ resolve(getList(devicesWithLabels, kind));
14073
14150
  stream.getTracks().forEach(function (track) {
14074
14151
  track.stop();
14075
14152
  });
14076
14153
  }, reject);
14077
14154
  }, reject);
14078
14155
  } else {
14079
- resolve(getList(devices));
14156
+ resolve(getList(devices, kind));
14080
14157
  }
14081
14158
  }, reject);
14082
14159
  });
14083
14160
  };
14161
+ var getMobileDevices = /*#__PURE__*/function () {
14162
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(kind) {
14163
+ var deviceConstraints,
14164
+ constraints,
14165
+ videoFilter,
14166
+ list,
14167
+ getCamera,
14168
+ front,
14169
+ back,
14170
+ _stream,
14171
+ mediaDevices,
14172
+ _args4 = arguments,
14173
+ _t2;
14174
+ return _regenerator().w(function (_context4) {
14175
+ while (1) switch (_context4.p = _context4.n) {
14176
+ case 0:
14177
+ deviceConstraints = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : null;
14178
+ constraints = {};
14179
+ videoFilter = [];
14180
+ list = null;
14181
+ if (!kind) {
14182
+ kind = constants.MEDIA_DEVICE_KIND.INPUT;
14183
+ } else if (kind === constants.MEDIA_DEVICE_KIND.ALL) {
14184
+ kind = "";
14185
+ }
14186
+ if (deviceConstraints && deviceConstraints.audio) {
14187
+ constraints.audio = deviceConstraints.audio;
14188
+ } else {
14189
+ constraints.audio = true;
14190
+ }
14191
+ if (deviceConstraints && deviceConstraints.video) {
14192
+ if (_typeof(deviceConstraints.video) === 'object') {
14193
+ constraints.video = deviceConstraints.video;
14194
+ } else {
14195
+ constraints.video = {};
14196
+ }
14197
+ } else {
14198
+ constraints.video = {};
14199
+ }
14200
+ getCamera = /*#__PURE__*/function () {
14201
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(constraints, facingMode) {
14202
+ var deviceId, mediaConstraints, _t;
14203
+ return _regenerator().w(function (_context3) {
14204
+ while (1) switch (_context3.p = _context3.n) {
14205
+ case 0:
14206
+ deviceId = null;
14207
+ mediaConstraints = {
14208
+ audio: false,
14209
+ video: constraints.video
14210
+ };
14211
+ mediaConstraints.video.facingMode = facingMode;
14212
+ _context3.p = 1;
14213
+ _context3.n = 2;
14214
+ return navigator.mediaDevices.getUserMedia(mediaConstraints);
14215
+ case 2:
14216
+ stream = _context3.v;
14217
+ if (stream) {
14218
+ if (stream.getVideoTracks().length > 0) {
14219
+ deviceId = stream.getVideoTracks()[0].getSettings().deviceId;
14220
+ }
14221
+ stream.getTracks().forEach(function (track) {
14222
+ track.stop();
14223
+ });
14224
+ }
14225
+ _context3.n = 4;
14226
+ break;
14227
+ case 3:
14228
+ _context3.p = 3;
14229
+ _t = _context3.v;
14230
+ logger.error(LOG_PREFIX, "Can't get device access with video constraints " + JSON.stringify(constraints.video) + ", error " + _t);
14231
+ case 4:
14232
+ return _context3.a(2, deviceId);
14233
+ }
14234
+ }, _callee3, null, [[1, 3]]);
14235
+ }));
14236
+ return function getCamera(_x5, _x6) {
14237
+ return _ref4.apply(this, arguments);
14238
+ };
14239
+ }();
14240
+ _context4.n = 1;
14241
+ return getCamera(constraints, {
14242
+ ideal: 'user'
14243
+ });
14244
+ case 1:
14245
+ front = _context4.v;
14246
+ if (front && front !== "") {
14247
+ logger.debug(LOG_PREFIX, "Front camera id: " + front);
14248
+ videoFilter.push(front);
14249
+ }
14250
+ _context4.n = 2;
14251
+ return getCamera(constraints, {
14252
+ ideal: 'environment'
14253
+ });
14254
+ case 2:
14255
+ back = _context4.v;
14256
+ if (back && back !== "") {
14257
+ logger.debug(LOG_PREFIX, "Back camera id: " + back);
14258
+ videoFilter.push(back);
14259
+ }
14260
+ _context4.p = 3;
14261
+ _context4.n = 4;
14262
+ return navigator.mediaDevices.getUserMedia(constraints);
14263
+ case 4:
14264
+ _stream = _context4.v;
14265
+ if (!_stream) {
14266
+ _context4.n = 6;
14267
+ break;
14268
+ }
14269
+ _context4.n = 5;
14270
+ return navigator.mediaDevices.enumerateDevices();
14271
+ case 5:
14272
+ mediaDevices = _context4.v;
14273
+ if (mediaDevices) {
14274
+ logger.debug(LOG_PREFIX, "mediaDevices: " + JSON.stringify(mediaDevices));
14275
+ list = getList(mediaDevices, kind, videoFilter);
14276
+ }
14277
+ _stream.getTracks().forEach(function (track) {
14278
+ track.stop();
14279
+ });
14280
+ case 6:
14281
+ _context4.n = 8;
14282
+ break;
14283
+ case 7:
14284
+ _context4.p = 7;
14285
+ _t2 = _context4.v;
14286
+ logger.error(LOG_PREFIX, "Can't get device access with constraints " + JSON.stringify(constraints) + ", error " + _t2);
14287
+ case 8:
14288
+ return _context4.a(2, list);
14289
+ }
14290
+ }, _callee4, null, [[3, 7]]);
14291
+ }));
14292
+ return function getMobileDevices(_x4) {
14293
+ return _ref3.apply(this, arguments);
14294
+ };
14295
+ }();
14084
14296
  function normalizeConstraints(constraints) {
14085
14297
  //WCS-2010. fixed TypeError after publish->stop->publish
14086
14298
  //WCS-2373. fixed customStream
@@ -14209,6 +14421,7 @@ module.exports = {
14209
14421
  getMediaAccess: getMediaAccess,
14210
14422
  releaseMedia: releaseMedia,
14211
14423
  listDevices: listDevices,
14424
+ getMobileDevices: getMobileDevices,
14212
14425
  playFirstSound: playFirstSound,
14213
14426
  playFirstVideo: playFirstVideo,
14214
14427
  available: available,