@flashphoner/websdk 2.0.259 → 2.0.261

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.
@@ -66,6 +66,8 @@ var createConnection = function (options) {
66
66
  var useControls = options.useControls || false;
67
67
  // Stream event handler to rise an event #WCS-4097
68
68
  var unmuteRequiredEvent = options.unmuteRequiredEvent ? options.unmuteRequiredEvent : null;
69
+ // Current video capturer zoom #WCS-4579
70
+ let zoom = null;
69
71
 
70
72
  if (bidirectional) {
71
73
  localVideo = getCacheInstance(localDisplay);
@@ -451,66 +453,53 @@ var createConnection = function (options) {
451
453
  return true;
452
454
  };
453
455
 
454
- var getStat = function (callbackFn, nativeStats) {
455
- let browser = browserDetails.browser;
456
+ var getStat = async function (callbackFn, nativeStats) {
456
457
  let result = {outboundStream: {}, inboundStream: {}, otherStats: []};
457
- if (connection && validBrowsers.includes(browser)) {
458
- if (nativeStats) {
459
- return connection.getStats(null);
460
- } else {
461
- connection.getStats(null).then(function (stat) {
462
- if (stat) {
463
- stat.forEach(function (report) {
464
- if (!report.isRemote) {
465
- let mediaType = "";
466
- if (report.type === 'outbound-rtp') {
467
- mediaType = getReportMediaType(report);
468
- fillStatObject(result.outboundStream, report, mediaType);
469
- if (mediaType === 'video') {
470
- getVideoSize(result.outboundStream[mediaType], report);
471
- }
472
- } else if (report.type === 'inbound-rtp') {
473
- mediaType = getReportMediaType(report);
474
- fillStatObject(result.inboundStream, report, mediaType);
475
- if (mediaType === 'video') {
476
- getVideoSize(result.inboundStream[mediaType], report);
477
- }
478
- } else if (report.type === 'candidate-pair' && report.state === 'succeeded' && report.nominated) {
479
- if (report.availableIncomingBitrate) {
480
- result.otherStats.availableIncomingBitrate = report.availableIncomingBitrate;
481
- } else if (localVideo && report.availableOutgoingBitrate) {
482
- // availableOutgoingBitrate is defined for incoming stream too #WCS-4175
483
- result.otherStats.availableOutgoingBitrate = report.availableOutgoingBitrate;
484
- }
485
- }
486
- }
487
- });
458
+ let rawStat = await getWebRTCStats();
488
459
 
460
+ if (nativeStats) {
461
+ callbackFn(rawStat);
462
+ }
463
+ else {
464
+ if (rawStat["candidate-pair"]) {
465
+ rawStat["candidate-pair"].forEach((report) => {
466
+ if (report.state === 'succeeded' && report.nominated) {
467
+ if (report.availableIncomingBitrate) {
468
+ result.otherStats.availableIncomingBitrate = report.availableIncomingBitrate;
469
+ } else if (localVideo && report.availableOutgoingBitrate) {
470
+ // availableOutgoingBitrate is defined for incoming stream too #WCS-4175
471
+ result.otherStats.availableOutgoingBitrate = report.availableOutgoingBitrate;
472
+ }
489
473
  }
490
- callbackFn(result);
491
474
  });
492
475
  }
476
+ if (rawStat["outbound-rtp"]) {
477
+ rawStat["outbound-rtp"].forEach((report) => {
478
+ fillStatObject(result.outboundStream, report, report.kind);
479
+ if (report.kind === "video") {
480
+ getVideoSize(result.outboundStream[report.kind], report.type, report);
481
+ }
482
+ });
483
+ }
484
+ if (rawStat["inbound-rtp"]) {
485
+ rawStat["inbound-rtp"].forEach((report) => {
486
+ fillStatObject(result.inboundStream, report, report.kind);
487
+ if (report.kind === "video") {
488
+ getVideoSize(result.inboundStream["video"], report.type, report);
489
+ }
490
+ });
491
+ }
492
+ callbackFn(result);
493
493
  }
494
494
  };
495
495
 
496
- var getReportMediaType = function (report) {
497
- // Since Safari 17 report.mediaType is undefined #WCS-3922
498
- if (report.mediaType !== undefined) {
499
- return report.mediaType;
500
- } else if (report.kind !== undefined) {
501
- return report.kind;
502
- }
503
- logger.warn(LOG_PREFIX, "No media type provided in WebRTC statistics");
504
- return "media";
505
- };
506
-
507
- var getVideoSize = function (obj, report) {
496
+ var getVideoSize = function (obj, type, report) {
508
497
  let videoSize = {};
509
- if (report.type == 'outbound-rtp') {
498
+ if (type === 'outbound-rtp') {
510
499
  if (localVideo !== undefined && localVideo != null) {
511
500
  videoSize = localVideo.srcObject.getVideoTracks()[0].getSettings();
512
501
  }
513
- } else if (report.type == 'inbound-rtp') {
502
+ } else if (type === 'inbound-rtp') {
514
503
  if (remoteVideo !== undefined && remoteVideo != null) {
515
504
  videoSize.width = remoteVideo.videoWidth;
516
505
  videoSize.height = remoteVideo.videoHeight;
@@ -551,6 +540,7 @@ var createConnection = function (options) {
551
540
  key.indexOf("audioLevel") != -1 ||
552
541
  key === "framesPerSecond" ||
553
542
  key === "qualityLimitationReason" ) {
543
+
554
544
  obj[mediaType][key] = report[key];
555
545
  }
556
546
  if (key === "qualityLimitationDurations") {
@@ -896,6 +886,83 @@ var createConnection = function (options) {
896
886
  }
897
887
  };
898
888
 
889
+ const getZoomCapabilities = function() {
890
+ if (localVideo && localVideo.srcObject) {
891
+ if (constraints.video && constraints.video.zoom) {
892
+ const [track] = localVideo.srcObject.getVideoTracks();
893
+ const capabilities = track.getCapabilities();
894
+ const settings = track.getSettings();
895
+
896
+ if (!('zoom' in settings)) {
897
+ logger.info(LOG_PREFIX, "Zoom is not supported by " + track.label);
898
+ zoom = null;
899
+ } else {
900
+ zoom = {
901
+ min: capabilities.zoom.min,
902
+ max: capabilities.zoom.max,
903
+ step: capabilities.zoom.step,
904
+ value: settings.zoom
905
+ }
906
+ }
907
+ } else {
908
+ zoom = null;
909
+ }
910
+ }
911
+ return zoom;
912
+ };
913
+
914
+ const setZoom = async function(value) {
915
+ if (zoom) {
916
+ if (value >= zoom.min && value <= zoom.max) {
917
+ if (localVideo && localVideo.srcObject) {
918
+ const [track] = localVideo.srcObject.getVideoTracks();
919
+ await track.applyConstraints({advanced: [{zoom: value}]});
920
+ zoom.value = value;
921
+ } else {
922
+ logger.warn(LOG_PREFIX, "Can't set zoom value: no local video");
923
+ }
924
+ } else {
925
+ logger.info(LOG_PREFIX, "Zoom value " + value + "is out of range: " + zoom.min + "-" + zoom.max);
926
+ }
927
+ } else {
928
+ logger.info(LOG_PREFIX, "Zoom is not supported or zoom capabilities unknown yet");
929
+ }
930
+ }
931
+
932
+ const getZoom = function() {
933
+ if (zoom) {
934
+ return zoom.value;
935
+ }
936
+ return -1;
937
+ }
938
+
939
+ var getWebRTCStats = function() {
940
+ return new Promise(function (resolve, reject) {
941
+ let browser = browserDetails.browser;
942
+ if (connection && validBrowsers.includes(browser)) {
943
+ connection.getStats(null).then((stats) => {
944
+ let statObject = {};
945
+ if (stats) {
946
+ stats.forEach((report) => {
947
+ if (report) {
948
+ if (statObject[report.type] === undefined) {
949
+ statObject[report.type] = [];
950
+ }
951
+ statObject[report.type].push(report);
952
+ }
953
+ });
954
+ }
955
+ resolve(statObject);
956
+ }).catch((reason) => {
957
+ logger.error(LOG_PREFIX, reason);
958
+ reject(reason);
959
+ });
960
+ } else {
961
+ reject(constants.ERROR_INFO.CAN_NOT_GET_STATS);
962
+ }
963
+ });
964
+ };
965
+
899
966
  var exports = {};
900
967
  exports.state = state;
901
968
  exports.createOffer = createOffer;
@@ -925,6 +992,10 @@ var createConnection = function (options) {
925
992
  exports.setPublishingBitrate = setPublishingBitrate;
926
993
  exports.updateVideoSettings = updateVideoSettings;
927
994
  exports.updateVideoResolution = updateVideoResolution;
995
+ exports.getZoomCapabilities = getZoomCapabilities;
996
+ exports.setZoom = setZoom;
997
+ exports.getZoom = getZoom;
998
+ exports.getWebRTCStats = getWebRTCStats;
928
999
  connections[id] = exports;
929
1000
  resolve(exports);
930
1001
  });