@techsee/techsee-media-service 0.21.2 → 0.22.0-alphagb2

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.
Files changed (97) hide show
  1. package/lib/LocalStreamManager.js +435 -317
  2. package/lib/LocalStreamManager.js.map +1 -1
  3. package/lib/MediaConstants.js +72 -44
  4. package/lib/MediaConstants.js.map +1 -1
  5. package/lib/MediaContracts.js +3 -3
  6. package/lib/MediaContracts.js.map +1 -1
  7. package/lib/MediaPublisher.js +45 -35
  8. package/lib/MediaPublisher.js.map +1 -1
  9. package/lib/MediaServiceBase.js +922 -706
  10. package/lib/MediaServiceBase.js.map +1 -1
  11. package/lib/MediaSession/MediaServer.js +512 -379
  12. package/lib/MediaSession/MediaServer.js.map +1 -1
  13. package/lib/MediaSession/MediaSessionBase.js +123 -88
  14. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  15. package/lib/MediaSession/SessionOpentok.js +499 -384
  16. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  17. package/lib/MediaSession/SessionTurn.js +606 -466
  18. package/lib/MediaSession/SessionTurn.js.map +1 -1
  19. package/lib/MediaSession/TurnConstants.js +30 -30
  20. package/lib/MediaSession/TurnConstants.js.map +1 -1
  21. package/lib/MediaSubscriber.js +235 -192
  22. package/lib/MediaSubscriber.js.map +1 -1
  23. package/lib/MediaUtils/Compatibility.js +127 -90
  24. package/lib/MediaUtils/Compatibility.js.map +1 -1
  25. package/lib/MediaUtils/MediaDomUtils.js +230 -179
  26. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  27. package/lib/MediaUtils/MediaTracer.js +8 -4
  28. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  29. package/lib/MultiParty/Contracts.js +3 -3
  30. package/lib/MultiParty/Contracts.js.map +1 -1
  31. package/lib/MultiParty/DetectWebRtcService.js +66 -50
  32. package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
  33. package/lib/MultiParty/MediaCapabilitiesHelper.js +258 -154
  34. package/lib/MultiParty/MediaCapabilitiesHelper.js.map +1 -1
  35. package/lib/MultiParty/MultiParty.d.ts +1 -8
  36. package/lib/MultiParty/MultiParty.d.ts.map +1 -1
  37. package/lib/MultiParty/MultiParty.js +221 -128
  38. package/lib/MultiParty/MultiParty.js.map +1 -1
  39. package/lib/MultiParty/MultipartyFactory.d.ts +1 -2
  40. package/lib/MultiParty/MultipartyFactory.d.ts.map +1 -1
  41. package/lib/MultiParty/MultipartyFactory.js +12 -7
  42. package/lib/MultiParty/MultipartyFactory.js.map +1 -1
  43. package/lib/MultiParty/OpentokMultiparty.js +611 -384
  44. package/lib/MultiParty/OpentokMultiparty.js.map +1 -1
  45. package/lib/TechseeMediaStream.js +58 -53
  46. package/lib/TechseeMediaStream.js.map +1 -1
  47. package/lib/oldCode/constants.js +20 -15
  48. package/lib/oldCode/constants.js.map +1 -1
  49. package/lib/oldCode/event-emitter.js +45 -22
  50. package/lib/oldCode/event-emitter.js.map +1 -1
  51. package/lib/oldCode/index.js +48 -52
  52. package/lib/oldCode/index.js.map +1 -1
  53. package/lib/oldCode/opentok/session.js +261 -236
  54. package/lib/oldCode/opentok/session.js.map +1 -1
  55. package/lib/oldCode/opentok/stream.js +283 -269
  56. package/lib/oldCode/opentok/stream.js.map +1 -1
  57. package/lib/oldCode/publisher.js +96 -71
  58. package/lib/oldCode/publisher.js.map +1 -1
  59. package/lib/oldCode/service.js +294 -272
  60. package/lib/oldCode/service.js.map +1 -1
  61. package/lib/oldCode/session.js +82 -60
  62. package/lib/oldCode/session.js.map +1 -1
  63. package/lib/oldCode/stream.js +153 -125
  64. package/lib/oldCode/stream.js.map +1 -1
  65. package/lib/oldCode/subscriber.js +60 -35
  66. package/lib/oldCode/subscriber.js.map +1 -1
  67. package/lib/oldCode/tracer.js +179 -138
  68. package/lib/oldCode/tracer.js.map +1 -1
  69. package/lib/oldCode/utils/ImageFixer.js +66 -44
  70. package/lib/oldCode/utils/ImageFixer.js.map +1 -1
  71. package/lib/oldCode/webrtc/constants.js +102 -110
  72. package/lib/oldCode/webrtc/constants.js.map +1 -1
  73. package/lib/oldCode/webrtc/helper.js +176 -124
  74. package/lib/oldCode/webrtc/helper.js.map +1 -1
  75. package/lib/oldCode/webrtc/session-kms.js +408 -393
  76. package/lib/oldCode/webrtc/session-kms.js.map +1 -1
  77. package/lib/oldCode/webrtc/session-loopback.js +245 -227
  78. package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
  79. package/lib/oldCode/webrtc/session-turn.js +705 -658
  80. package/lib/oldCode/webrtc/session-turn.js.map +1 -1
  81. package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
  82. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
  83. package/lib/oldCode/webrtc/session.js +12 -6
  84. package/lib/oldCode/webrtc/session.js.map +1 -1
  85. package/lib/oldCode/webrtc/stream.js +526 -504
  86. package/lib/oldCode/webrtc/stream.js.map +1 -1
  87. package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
  88. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
  89. package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
  90. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
  91. package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
  92. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
  93. package/lib/qos/raw-qos.js +348 -274
  94. package/lib/qos/raw-qos.js.map +1 -1
  95. package/lib/webrtc-ie-shim.js +3386 -2985
  96. package/lib/webrtc-ie-shim.js.map +1 -1
  97. package/package.json +12 -15
@@ -1,320 +1,394 @@
1
1
  'use strict';
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RawQos = void 0;
4
7
 
5
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
6
9
 
7
- var RawQos = exports.RawQos = function () {
8
- function RawQos() {
9
- _classCallCheck(this, RawQos);
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
11
 
11
- if (RawQos.instance) {
12
- return RawQos.instance;
13
- }
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
14
17
 
15
- this.VIDEO_CODECS = ['vp9', 'vp8', 'h264'];
16
- this.rawQoSEntry = {};
17
- this.enableRawEntries = true;
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
18
19
 
19
- this.bytesPrev = null;
20
- this.timestampPrev = null;
21
- this.startTimestamp = null;
20
+ var RawQos = /*#__PURE__*/function () {
21
+ function RawQos() {
22
+ _classCallCheck(this, RawQos);
22
23
 
23
- RawQos.instance = this;
24
+ if (RawQos.instance) {
25
+ return RawQos.instance;
24
26
  }
25
27
 
26
- RawQos.prototype.parse = function parse(stats) {
27
- // eslint-disable-next-line @typescript-eslint/no-this-alias
28
- var self = this;
28
+ this.VIDEO_CODECS = ['vp9', 'vp8', 'h264'];
29
+ this.rawQoSEntry = {};
30
+ this.enableRawEntries = true;
31
+ this.bytesPrev = null;
32
+ this.timestampPrev = null;
33
+ this.startTimestamp = null;
34
+ RawQos.instance = this;
35
+ }
29
36
 
30
- self.rawQoSEntry = {};
31
- self._clearRaw();
37
+ _createClass(RawQos, [{
38
+ key: "parse",
39
+ value: function parse(stats) {
40
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
41
+ var self = this;
42
+ self.rawQoSEntry = {};
32
43
 
33
- for (var _iterator = stats.values(), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
34
- var _ref;
44
+ self._clearRaw();
35
45
 
36
- if (_isArray) {
37
- if (_i >= _iterator.length) break;
38
- _ref = _iterator[_i++];
39
- } else {
40
- _i = _iterator.next();
41
- if (_i.done) break;
42
- _ref = _i.value;
43
- }
46
+ var _iterator = _createForOfIteratorHelper(stats.values()),
47
+ _step;
48
+
49
+ try {
50
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
51
+ var stat = _step.value;
52
+
53
+ if (!stat.isRemote) {
54
+ switch (stat.type) {
55
+ case 'outbound-rtp':
56
+ {
57
+ self._addRaw(stat);
58
+
59
+ self._parseOutStats(stat, self.rawQoSEntry);
60
+
61
+ var remote = stats.get(stat.remoteId);
62
+
63
+ if (remote) {
64
+ self._addRaw(remote);
65
+
66
+ self.rawQoSEntry.remote = {};
44
67
 
45
- var stat = _ref;
46
-
47
- if (!stat.isRemote) {
48
- switch (stat.type) {
49
- case 'outbound-rtp':
50
- {
51
- self._addRaw(stat);
52
- self._parseOutStats(stat, self.rawQoSEntry);
53
-
54
- var remote = stats.get(stat.remoteId);
55
-
56
- if (remote) {
57
- self._addRaw(remote);
58
- self.rawQoSEntry.remote = {};
59
- self._parseInStats(remote, self.rawQoSEntry.remote);
60
- }
61
-
62
- this._parseRelated(stats, stat, self);
63
- break;
64
- }
65
- case 'inbound-rtp':
66
- {
67
- self._addRaw(stat);
68
- self._parseInStats(stat, self.rawQoSEntry);
69
-
70
- var _remote = stats.get(stat.remoteId);
71
-
72
- if (_remote) {
73
- self._addRaw(_remote);
74
- self.rawQoSEntry.remote = {};
75
- self._parseOutStats(_remote, self.rawQoSEntry.remote);
76
- }
77
-
78
- this._parseRelated(stats, stat, self);
79
- break;
80
- }
81
- case 'remote-inbound-rtp':
82
- {
83
- self._addRaw(stat);
84
- self.rawQoSEntry.remote = {};
85
- self._parseInStats(stat, self.rawQoSEntry.remote);
86
- break;
87
- }
88
- case 'remote-outbound-rtp':
89
- {
90
- self._addRaw(stat);
91
- self.rawQoSEntry.remote = {};
92
- self._parseOutStats(stat, self.rawQoSEntry.remote);
93
- break;
94
- }
95
- case 'candidate-pair':
96
- {
97
- if ((stat.bytesSent > 0 || stat.bytesReceived > 0) && (!self.rawQoSEntry.servers || stat.bytesSent > self.rawQoSEntry.servers.bytesSent || stat.bytesReceived > self.rawQoSEntry.servers.bytesReceived)) {
98
- self.rawQoSEntry.servers = {};
99
- self._addRaw(stat);
100
- self._parseServerStats(stat, self.rawQoSEntry.servers, stats);
101
- }
102
- break;
103
- }
104
- case 'track':
105
- {
106
- self.track = stat;
107
- break;
108
- }
68
+ self._parseInStats(remote, self.rawQoSEntry.remote);
69
+ }
70
+
71
+ this._parseRelated(stats, stat, self);
72
+
73
+ break;
109
74
  }
110
- }
111
- }
112
75
 
113
- if (!self.rawQoSEntry.frameWidth && self.track) {
114
- self._addRaw(self.track);
115
- self._parseTrack(self.track, self.rawQoSEntry);
116
- }
117
- self.track = null;
76
+ case 'inbound-rtp':
77
+ {
78
+ self._addRaw(stat);
118
79
 
119
- return self.rawQoSEntry;
120
- };
80
+ self._parseInStats(stat, self.rawQoSEntry);
121
81
 
122
- RawQos.prototype._parseRelated = function _parseRelated(stats, stat, self) {
123
- var track = stats.get(stat.trackId);
82
+ var _remote = stats.get(stat.remoteId);
124
83
 
125
- if (track) {
126
- self._addRaw(track);
127
- self._parseTrack(track, self.rawQoSEntry);
128
- }
84
+ if (_remote) {
85
+ self._addRaw(_remote);
129
86
 
130
- var codec = stats.get(stat.codecId);
87
+ self.rawQoSEntry.remote = {};
131
88
 
132
- if (codec) {
133
- self._addRaw(codec);
134
- self._parseCodec(codec, self.rawQoSEntry);
135
- }
136
- };
89
+ self._parseOutStats(_remote, self.rawQoSEntry.remote);
90
+ }
137
91
 
138
- RawQos.prototype._clearRaw = function _clearRaw() {
139
- if (this.enableRawEntries) {
140
- this.rawQoSEntry.raw = [];
141
- }
142
- };
92
+ this._parseRelated(stats, stat, self);
143
93
 
144
- RawQos.prototype._addRaw = function _addRaw(item) {
145
- if (this.enableRawEntries && item) {
146
- if (!this.rawQoSEntry.raw) {
147
- this.rawQoSEntry.raw = [];
148
- }
94
+ break;
95
+ }
149
96
 
150
- this.rawQoSEntry.raw.push(this._dumpItem(item));
151
- }
152
- };
97
+ case 'remote-inbound-rtp':
98
+ {
99
+ self._addRaw(stat);
153
100
 
154
- RawQos.prototype._parseServerStats = function _parseServerStats(result, parent, stats) {
155
- parent.bytesSent = result.bytesSent;
156
- parent.bytesReceived = result.bytesReceived;
157
- if (typeof result.totalRoundTripTime === 'number') {
158
- parent.totalRoundTripTime = result.totalRoundTripTime;
159
- }
160
- if (typeof result.currentRoundTripTime === 'number') {
161
- parent.currentRoundTripTime = result.currentRoundTripTime;
162
- }
163
- if (typeof result.availableOutgoingBitrate === 'number') {
164
- parent.availableOutgoingBitrate = result.availableOutgoingBitrate;
165
- }
101
+ self.rawQoSEntry.remote = {};
166
102
 
167
- var localCandidate = stats.get(result.localCandidateId);
103
+ self._parseInStats(stat, self.rawQoSEntry.remote);
168
104
 
169
- if (localCandidate) {
170
- this._addRaw(localCandidate);
171
- this._parseLocal(localCandidate, parent);
172
- }
105
+ break;
106
+ }
173
107
 
174
- var remoteCandidate = stats.get(result.remoteCandidateId);
108
+ case 'remote-outbound-rtp':
109
+ {
110
+ self._addRaw(stat);
175
111
 
176
- if (remoteCandidate) {
177
- this._addRaw(remoteCandidate);
178
- this._parseRemote(remoteCandidate, parent);
179
- }
180
- };
112
+ self.rawQoSEntry.remote = {};
181
113
 
182
- RawQos.prototype._parseCodec = function _parseCodec(result, parent) {
183
- if (result.mimeType) {
184
- var index = this.VIDEO_CODECS.findIndex(function (codec) {
185
- return result.mimeType.toLowerCase().includes(codec);
186
- });
114
+ self._parseOutStats(stat, self.rawQoSEntry.remote);
187
115
 
188
- if (index >= 0) {
189
- parent.videoCodec = this.VIDEO_CODECS[index];
190
- }
191
- }
192
- };
193
-
194
- RawQos.prototype._parseLocal = function _parseLocal(result, parent) {
195
- parent.localIP = result.ip || result.ipAddress;
196
- parent.localPort = result.port || result.portNumber;
197
- parent.localProtocol = result.protocol || result.transport;
198
- };
199
-
200
- RawQos.prototype._parseRemote = function _parseRemote(result, parent) {
201
- parent.remoteIP = result.ip || result.ipAddress;
202
- parent.remotePort = result.port || result.portNumber;
203
- parent.remoteProtocol = result.protocol || result.transport;
204
- };
205
-
206
- RawQos.prototype._parseTrack = function _parseTrack(result, parent) {
207
- if (typeof result.frameWidth === 'number') {
208
- parent.frameWidth = result.frameWidth;
209
- }
210
- if (typeof result.frameHeight === 'number') {
211
- parent.frameHeight = result.frameHeight;
212
- }
213
- if (typeof result.framesPerSecond === 'number') {
214
- parent.videoFrameRate = result.framesPerSecond;
215
- }
216
- };
217
-
218
- RawQos.prototype._parseOutStats = function _parseOutStats(result, parent) {
219
- parent.isPublisher = true;
220
- parent.videoSentPackets = result.packetsSent;
221
- parent.videoSentPacketsLost = result.packetsLost;
222
- parent.videoSentBytes = result.bytesSent;
223
- this._parseBitrate(result, parent, parent.videoSentBytes);
224
- this._parseFrameRate(result, parent, parent.videoSentBytes);
225
- this._parseOther(result, parent);
226
- this._saveSomeMetrics(parent, result);
227
- };
228
-
229
- RawQos.prototype._parseVideoDuration = function _parseVideoDuration(result, parent) {
230
- if (!this.startTimestamp) {
231
- this.startTimestamp = result.timestamp;
232
- }
233
- parent.videoDuration = ((result.timestamp - this.startTimestamp) / 1000).toFixed(2);
234
- };
235
-
236
- RawQos.prototype._parseInStats = function _parseInStats(result, parent) {
237
- parent.isSubscriber = true;
238
- parent.videoReceivedPackets = result.packetsReceived;
239
- parent.videoReceivedPacketsLost = result.packetsLost;
240
- parent.videoReceivedBytes = result.bytesReceived;
241
- this._parseBitrate(result, parent, parent.videoReceivedBytes);
242
- this._parseFrameRate(result, parent, parent.videoReceivedBytes);
243
- this._parseOther(result, parent);
244
- this._saveSomeMetrics(parent, result);
245
- };
246
-
247
- RawQos.prototype._saveSomeMetrics = function _saveSomeMetrics(parent, result) {
248
- if (parent === this.rawQoSEntry) {
249
- this.bytesPrev = parent.videoReceivedBytes;
250
- this.timestampPrev = result.timestamp;
251
- this.ssrcPrev = result.ssrc;
252
- this.framesDecodedPrev = result.framesDecoded;
253
- this._parseVideoDuration(result, parent);
254
- }
255
- };
116
+ break;
117
+ }
256
118
 
257
- RawQos.prototype._parseOther = function _parseOther(result, parent) {
258
- parent.timestamp = result.timestamp;
259
- parent.ssrc = result.ssrc;
260
- if (typeof result.discardedPackets === 'number') {
261
- parent.discardedPackets = result.discardedPackets;
262
- }
263
- if (typeof result.jitter === 'number') {
264
- parent.jitter = result.jitter;
265
- }
266
- if (typeof result.packetsRepaired === 'number') {
267
- parent.packetsRepaired = result.packetsRepaired;
268
- }
269
- };
119
+ case 'candidate-pair':
120
+ {
121
+ if ((stat.bytesSent > 0 || stat.bytesReceived > 0) && (!self.rawQoSEntry.servers || stat.bytesSent > self.rawQoSEntry.servers.bytesSent || stat.bytesReceived > self.rawQoSEntry.servers.bytesReceived)) {
122
+ self.rawQoSEntry.servers = {};
123
+
124
+ self._addRaw(stat);
270
125
 
271
- RawQos.prototype._parseBitrate = function _parseBitrate(result, parent, bytes) {
272
- if (bytes > 0) {
273
- if (typeof result.bitrateMean === 'number') {
274
- parent.videoBitRate = result.bitrateMean.toFixed(2);
275
- } else if (this.bytesPrev && this.timestampPrev) {
276
- var totalBytes = bytes;
126
+ self._parseServerStats(stat, self.rawQoSEntry.servers, stats);
127
+ }
277
128
 
278
- if (result.ssrc === this.ssrcPrev && bytes > this.bytesPrev) {
279
- totalBytes = bytes - this.bytesPrev;
129
+ break;
280
130
  }
281
131
 
282
- parent.videoBitRate = Math.floor(8 * totalBytes / ((result.timestamp - this.timestampPrev) / 1000));
283
- }
284
- } else {
285
- parent.videoBitRate = 0;
286
- }
287
- };
288
-
289
- RawQos.prototype._parseFrameRate = function _parseFrameRate(result, parent, bytes) {
290
- if (bytes > 0) {
291
- if (typeof result.framerateMean === 'number') {
292
- parent.videoFrameRate = Number(result.framerateMean).toFixed(2);
293
- } else if (this.framesDecodedPrev && this.timestampPrev) {
294
- if (result.framesDecoded >= this.framesDecodedPrev && result.timestamp > this.timestampPrev) {
295
- parent.videoFrameRate = ((result.framesDecoded - this.framesDecodedPrev) / ((result.timestamp - this.timestampPrev) / 1000)).toFixed(2);
132
+ case 'track':
133
+ {
134
+ self.track = stat;
135
+ break;
296
136
  }
297
137
  }
298
- } else {
299
- parent.videoFrameRate = 0;
138
+ }
300
139
  }
301
- };
140
+ } catch (err) {
141
+ _iterator.e(err);
142
+ } finally {
143
+ _iterator.f();
144
+ }
302
145
 
303
- RawQos.prototype._dumpItem = function _dumpItem(res) {
304
- var statsString = '{';
305
- var index = 0;
146
+ if (!self.rawQoSEntry.frameWidth && self.track) {
147
+ self._addRaw(self.track);
306
148
 
307
- Object.keys(res).forEach(function (k) {
308
- statsString += '"' + k + '": "' + res[k] + '"';
309
- if (++index !== res.length) {
310
- statsString += ',';
311
- }
149
+ self._parseTrack(self.track, self.rawQoSEntry);
150
+ }
151
+
152
+ self.track = null;
153
+ return self.rawQoSEntry;
154
+ }
155
+ }, {
156
+ key: "_parseRelated",
157
+ value: function _parseRelated(stats, stat, self) {
158
+ var track = stats.get(stat.trackId);
159
+
160
+ if (track) {
161
+ self._addRaw(track);
162
+
163
+ self._parseTrack(track, self.rawQoSEntry);
164
+ }
165
+
166
+ var codec = stats.get(stat.codecId);
167
+
168
+ if (codec) {
169
+ self._addRaw(codec);
170
+
171
+ self._parseCodec(codec, self.rawQoSEntry);
172
+ }
173
+ }
174
+ }, {
175
+ key: "_clearRaw",
176
+ value: function _clearRaw() {
177
+ if (this.enableRawEntries) {
178
+ this.rawQoSEntry.raw = [];
179
+ }
180
+ }
181
+ }, {
182
+ key: "_addRaw",
183
+ value: function _addRaw(item) {
184
+ if (this.enableRawEntries && item) {
185
+ if (!this.rawQoSEntry.raw) {
186
+ this.rawQoSEntry.raw = [];
187
+ }
188
+
189
+ this.rawQoSEntry.raw.push(this._dumpItem(item));
190
+ }
191
+ }
192
+ }, {
193
+ key: "_parseServerStats",
194
+ value: function _parseServerStats(result, parent, stats) {
195
+ parent.bytesSent = result.bytesSent;
196
+ parent.bytesReceived = result.bytesReceived;
197
+
198
+ if (typeof result.totalRoundTripTime === 'number') {
199
+ parent.totalRoundTripTime = result.totalRoundTripTime;
200
+ }
201
+
202
+ if (typeof result.currentRoundTripTime === 'number') {
203
+ parent.currentRoundTripTime = result.currentRoundTripTime;
204
+ }
205
+
206
+ if (typeof result.availableOutgoingBitrate === 'number') {
207
+ parent.availableOutgoingBitrate = result.availableOutgoingBitrate;
208
+ }
209
+
210
+ var localCandidate = stats.get(result.localCandidateId);
211
+
212
+ if (localCandidate) {
213
+ this._addRaw(localCandidate);
214
+
215
+ this._parseLocal(localCandidate, parent);
216
+ }
217
+
218
+ var remoteCandidate = stats.get(result.remoteCandidateId);
219
+
220
+ if (remoteCandidate) {
221
+ this._addRaw(remoteCandidate);
222
+
223
+ this._parseRemote(remoteCandidate, parent);
224
+ }
225
+ }
226
+ }, {
227
+ key: "_parseCodec",
228
+ value: function _parseCodec(result, parent) {
229
+ if (result.mimeType) {
230
+ var index = this.VIDEO_CODECS.findIndex(function (codec) {
231
+ return result.mimeType.toLowerCase().includes(codec);
312
232
  });
313
- statsString += '}';
314
233
 
315
- return statsString;
316
- };
234
+ if (index >= 0) {
235
+ parent.videoCodec = this.VIDEO_CODECS[index];
236
+ }
237
+ }
238
+ }
239
+ }, {
240
+ key: "_parseLocal",
241
+ value: function _parseLocal(result, parent) {
242
+ parent.localIP = result.ip || result.ipAddress;
243
+ parent.localPort = result.port || result.portNumber;
244
+ parent.localProtocol = result.protocol || result.transport;
245
+ }
246
+ }, {
247
+ key: "_parseRemote",
248
+ value: function _parseRemote(result, parent) {
249
+ parent.remoteIP = result.ip || result.ipAddress;
250
+ parent.remotePort = result.port || result.portNumber;
251
+ parent.remoteProtocol = result.protocol || result.transport;
252
+ }
253
+ }, {
254
+ key: "_parseTrack",
255
+ value: function _parseTrack(result, parent) {
256
+ if (typeof result.frameWidth === 'number') {
257
+ parent.frameWidth = result.frameWidth;
258
+ }
259
+
260
+ if (typeof result.frameHeight === 'number') {
261
+ parent.frameHeight = result.frameHeight;
262
+ }
263
+
264
+ if (typeof result.framesPerSecond === 'number') {
265
+ parent.videoFrameRate = result.framesPerSecond;
266
+ }
267
+ }
268
+ }, {
269
+ key: "_parseOutStats",
270
+ value: function _parseOutStats(result, parent) {
271
+ parent.isPublisher = true;
272
+ parent.videoSentPackets = result.packetsSent;
273
+ parent.videoSentPacketsLost = result.packetsLost;
274
+ parent.videoSentBytes = result.bytesSent;
275
+
276
+ this._parseBitrate(result, parent, parent.videoSentBytes);
277
+
278
+ this._parseFrameRate(result, parent, parent.videoSentBytes);
279
+
280
+ this._parseOther(result, parent);
281
+
282
+ this._saveSomeMetrics(parent, result);
283
+ }
284
+ }, {
285
+ key: "_parseVideoDuration",
286
+ value: function _parseVideoDuration(result, parent) {
287
+ if (!this.startTimestamp) {
288
+ this.startTimestamp = result.timestamp;
289
+ }
290
+
291
+ parent.videoDuration = ((result.timestamp - this.startTimestamp) / 1000).toFixed(2);
292
+ }
293
+ }, {
294
+ key: "_parseInStats",
295
+ value: function _parseInStats(result, parent) {
296
+ parent.isSubscriber = true;
297
+ parent.videoReceivedPackets = result.packetsReceived;
298
+ parent.videoReceivedPacketsLost = result.packetsLost;
299
+ parent.videoReceivedBytes = result.bytesReceived;
300
+
301
+ this._parseBitrate(result, parent, parent.videoReceivedBytes);
302
+
303
+ this._parseFrameRate(result, parent, parent.videoReceivedBytes);
304
+
305
+ this._parseOther(result, parent);
317
306
 
318
- return RawQos;
307
+ this._saveSomeMetrics(parent, result);
308
+ }
309
+ }, {
310
+ key: "_saveSomeMetrics",
311
+ value: function _saveSomeMetrics(parent, result) {
312
+ if (parent === this.rawQoSEntry) {
313
+ this.bytesPrev = parent.videoReceivedBytes;
314
+ this.timestampPrev = result.timestamp;
315
+ this.ssrcPrev = result.ssrc;
316
+ this.framesDecodedPrev = result.framesDecoded;
317
+
318
+ this._parseVideoDuration(result, parent);
319
+ }
320
+ }
321
+ }, {
322
+ key: "_parseOther",
323
+ value: function _parseOther(result, parent) {
324
+ parent.timestamp = result.timestamp;
325
+ parent.ssrc = result.ssrc;
326
+
327
+ if (typeof result.discardedPackets === 'number') {
328
+ parent.discardedPackets = result.discardedPackets;
329
+ }
330
+
331
+ if (typeof result.jitter === 'number') {
332
+ parent.jitter = result.jitter;
333
+ }
334
+
335
+ if (typeof result.packetsRepaired === 'number') {
336
+ parent.packetsRepaired = result.packetsRepaired;
337
+ }
338
+ }
339
+ }, {
340
+ key: "_parseBitrate",
341
+ value: function _parseBitrate(result, parent, bytes) {
342
+ if (bytes > 0) {
343
+ if (typeof result.bitrateMean === 'number') {
344
+ parent.videoBitRate = result.bitrateMean.toFixed(2);
345
+ } else if (this.bytesPrev && this.timestampPrev) {
346
+ var totalBytes = bytes;
347
+
348
+ if (result.ssrc === this.ssrcPrev && bytes > this.bytesPrev) {
349
+ totalBytes = bytes - this.bytesPrev;
350
+ }
351
+
352
+ parent.videoBitRate = Math.floor(8 * totalBytes / ((result.timestamp - this.timestampPrev) / 1000));
353
+ }
354
+ } else {
355
+ parent.videoBitRate = 0;
356
+ }
357
+ }
358
+ }, {
359
+ key: "_parseFrameRate",
360
+ value: function _parseFrameRate(result, parent, bytes) {
361
+ if (bytes > 0) {
362
+ if (typeof result.framerateMean === 'number') {
363
+ parent.videoFrameRate = Number(result.framerateMean).toFixed(2);
364
+ } else if (this.framesDecodedPrev && this.timestampPrev) {
365
+ if (result.framesDecoded >= this.framesDecodedPrev && result.timestamp > this.timestampPrev) {
366
+ parent.videoFrameRate = ((result.framesDecoded - this.framesDecodedPrev) / ((result.timestamp - this.timestampPrev) / 1000)).toFixed(2);
367
+ }
368
+ }
369
+ } else {
370
+ parent.videoFrameRate = 0;
371
+ }
372
+ }
373
+ }, {
374
+ key: "_dumpItem",
375
+ value: function _dumpItem(res) {
376
+ var statsString = '{';
377
+ var index = 0;
378
+ Object.keys(res).forEach(function (k) {
379
+ statsString += "\"".concat(k, "\": \"").concat(res[k], "\"");
380
+
381
+ if (++index !== res.length) {
382
+ statsString += ',';
383
+ }
384
+ });
385
+ statsString += '}';
386
+ return statsString;
387
+ }
388
+ }]);
389
+
390
+ return RawQos;
319
391
  }();
392
+
393
+ exports.RawQos = RawQos;
320
394
  //# sourceMappingURL=raw-qos.js.map