@flashphoner/websdk 2.0.274 → 2.0.276

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/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@flashphoner/websdk",
3
- "version": "2.0.274",
3
+ "version": "2.0.276",
4
4
  "description": "Official Flashphoner WebCallServer WebSDK package",
5
5
  "main": "./src/flashphoner-core.js",
6
6
  "types": "./src/flashphoner-core.d.ts",
7
7
  "dependencies": {
8
+ "@flashphoner/web-sdk-metrics": "^1.0.0",
8
9
  "adapterjs": "0.15.5",
9
10
  "es6-promise": "4.0.5",
10
11
  "kalmanjs": "^1.1.0",
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const { v1: uuid_v1 } = require('uuid');
3
+ const {
4
+ RTCMetricsCollectorBuilder, RTCMetricsCollectType, RTCMetricsHttpSender
5
+ } = require("@flashphoner/web-sdk-metrics");
6
+ const {v1: uuid_v1} = require('uuid');
4
7
  const constants = require("./constants");
5
8
  const util = require('./util');
6
9
  const LoggerObject = require('./util').logger;
7
10
  const clientInfo = require('./client-info');
8
- const StatsCollector = require('./stats-collector');
9
11
  const Promise = require('promise-polyfill');
10
12
  const KalmanFilter = require('kalmanjs');
11
13
  const browserDetails = require('webrtc-adapter').default.browserDetails;
@@ -30,6 +32,8 @@ const VIDEO_RATE_GOOD_QUALITY_PERCENT_DIFFERENCE = 20;
30
32
  const VIDEO_RATE_BAD_QUALITY_PERCENT_DIFFERENCE = 50;
31
33
  const LOW_VIDEO_RATE_THRESHOLD_BAD_PERFECT = 50000;
32
34
  const LOW_VIDEO_RATE_BAD_QUALITY_PERCENT_DIFFERENCE = 150;
35
+ const WEBRTC_METRICS_DESCRIPTION_UPDATE = "webRTCMetricsDescriptionUpdate";
36
+ const WEBRTC_METRICS_TOKEN_REFRESH = "webRTCMetricsTokenRefresh";
33
37
  const OUTBOUND_VIDEO_RATE = "outboundVideoRate";
34
38
  const INBOUND_VIDEO_RATE = "inboundVideoRate";
35
39
  const CONSTRAINT_AUDIO = "audio";
@@ -758,19 +762,38 @@ var createSession = function (options) {
758
762
  streamRefreshHandlers[obj.mediaSessionId](obj);
759
763
  }
760
764
  break;
761
- case 'webRTCMetricsDescriptionUpdate':
762
- handleWebRTCMetricsUpdate(obj, {
763
- compression: "compression",
764
- batchSize: "batchSize",
765
- sampling: "sampling",
766
- types: "types",
767
- collect: "collect"
768
- });
765
+ case WEBRTC_METRICS_TOKEN_REFRESH:
766
+ for (const [_, handler] of Object.entries(streamRefreshHandlers)) {
767
+ handler(obj);
768
+ }
769
769
  break;
770
- case 'webRTCMetricsTokenRefresh':
771
- handleWebRTCMetricsUpdate(obj, {
772
- authorization: "authorization"
773
- });
770
+ case WEBRTC_METRICS_DESCRIPTION_UPDATE:
771
+ if (obj.ids) {
772
+ obj.ids.forEach((id) => {
773
+ if (streamRefreshHandlers[id]) {
774
+ streamRefreshHandlers[id](obj);
775
+ }
776
+ });
777
+ } else {
778
+ if (obj.compression) {
779
+ webRTCMetricsServerDescription.compression = obj.compression;
780
+ }
781
+ if (obj.batchSize) {
782
+ webRTCMetricsServerDescription.batchSize = obj.batchSize;
783
+ }
784
+ if (obj.sampling) {
785
+ webRTCMetricsServerDescription.sampling = obj.sampling;
786
+ }
787
+ if (obj.types) {
788
+ webRTCMetricsServerDescription.types = obj.types;
789
+ }
790
+ if (obj.collect) {
791
+ webRTCMetricsServerDescription.collect = obj.collect;
792
+ }
793
+ for (const [id, handler] of Object.entries(streamRefreshHandlers)) {
794
+ handler(obj);
795
+ }
796
+ }
774
797
  break;
775
798
  default:
776
799
  logger.info(LOG_PREFIX, "Unknown server message " + data.message);
@@ -781,26 +804,6 @@ var createSession = function (options) {
781
804
  };
782
805
  }
783
806
 
784
- function handleWebRTCMetricsUpdate(obj, updateFields = {}) {
785
- if (obj.ids) {
786
- obj.ids.forEach((id) => {
787
- if (streamRefreshHandlers[id]) {
788
- streamRefreshHandlers[id](obj);
789
- }
790
- });
791
- } else {
792
- Object.entries(updateFields).forEach(([key, value]) => {
793
- if (obj[value] !== undefined) {
794
- webRTCMetricsServerDescription[key] = obj[value];
795
- }
796
- });
797
-
798
- for (const [id, handler] of Object.entries(streamRefreshHandlers)) {
799
- handler(obj);
800
- }
801
- }
802
- }
803
-
804
807
  //WebSocket send helper
805
808
  function send(message, data) {
806
809
  if (wsConnection.readyState === WebSocket.OPEN) {
@@ -1843,6 +1846,7 @@ var createSession = function (options) {
1843
1846
  var videoBytes = 0;
1844
1847
 
1845
1848
  var statsCollector = null;
1849
+ var httpStatsSender = null;
1846
1850
 
1847
1851
  /**
1848
1852
  * Represents media stream.
@@ -1949,21 +1953,41 @@ var createSession = function (options) {
1949
1953
  // Set up metrics collection
1950
1954
  if (event === STREAM_STATUS.PUBLISHING || event === STREAM_STATUS.PLAYING) {
1951
1955
  if (webRTCMetricsServerDescription && !statsCollector) {
1952
- statsCollector = StatsCollector.StreamStatsCollector(webRTCMetricsServerDescription, id_, mediaConnection, wsConnection, logger);
1956
+ const builder = new RTCMetricsCollectorBuilder()
1957
+ .id(id_)
1958
+ .description(webRTCMetricsServerDescription)
1959
+ .peerConnection(mediaConnection.getRTCPeerConnection())
1960
+ .logger(logger)
1961
+ .websocket(wsConnection)
1962
+ if(webRTCMetricsServerDescription.ingestPoint != null && webRTCMetricsServerDescription.ingestPoint.startsWith("http")) {
1963
+ httpStatsSender = new RTCMetricsHttpSender(webRTCMetricsServerDescription.ingestPoint, {
1964
+ Authorization: webRTCMetricsServerDescription.authorization,
1965
+ })
1966
+ builder.httpSender(httpStatsSender)
1967
+ }
1968
+ statsCollector = builder.build();
1953
1969
  statsCollector.start();
1954
1970
  }
1955
1971
  }
1956
1972
 
1957
- if (streamInfo.authorization && statsCollector && statsCollector.description.ingestPoint) {
1958
- statsCollector.description.authorization = streamInfo.authorization;
1959
- statsCollector.updateHttpConnection(statsCollector.description.ingestPoint, statsCollector.description.authorization);
1973
+ // Refresh authorization token if defined sender for ingestPoint
1974
+ if(!streamInfo.status && streamInfo.authorization != null && httpStatsSender) {
1975
+ httpStatsSender.headers = {
1976
+ ...httpStatsSender.headers,
1977
+ Authorization: streamInfo.authorization,
1978
+ }
1960
1979
  }
1961
1980
 
1962
1981
  // Pause or resume metrics collection
1963
1982
  if (!streamInfo.status && streamInfo.collect !== undefined && statsCollector) {
1964
- statsCollector.update(streamInfo);
1983
+ if(streamInfo.collect === RTCMetricsCollectType.on){
1984
+ statsCollector.collect(true);
1985
+ }else{
1986
+ statsCollector.collect(false);
1987
+ }
1965
1988
  }
1966
1989
 
1990
+
1967
1991
  //fire stream event
1968
1992
  if (callbacks[event]) {
1969
1993
  callbacks[event](stream);