@techsee/techsee-media-service 999.17.99-alphasa01 → 999.17.111-alphasa01

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 (81) hide show
  1. package/dist/Live2/LocalStreamManager.js +387 -302
  2. package/dist/Live2/LocalStreamManager.js.map +1 -1
  3. package/dist/Live2/MediaConstants.js +1 -1
  4. package/dist/Live2/MediaConstants.js.map +1 -1
  5. package/dist/Live2/MediaPublisher.js +54 -21
  6. package/dist/Live2/MediaPublisher.js.map +1 -1
  7. package/dist/Live2/MediaServiceBase.js +990 -612
  8. package/dist/Live2/MediaServiceBase.js.map +1 -1
  9. package/dist/Live2/MediaSession/MediaServer.js +493 -335
  10. package/dist/Live2/MediaSession/MediaServer.js.map +1 -1
  11. package/dist/Live2/MediaSession/MediaSessionBase.js +134 -80
  12. package/dist/Live2/MediaSession/MediaSessionBase.js.map +1 -1
  13. package/dist/Live2/MediaSession/SessionOpentok.js +472 -325
  14. package/dist/Live2/MediaSession/SessionOpentok.js.map +1 -1
  15. package/dist/Live2/MediaSession/SessionTurn.js +556 -373
  16. package/dist/Live2/MediaSession/SessionTurn.js.map +1 -1
  17. package/dist/Live2/MediaSubscriber.js +271 -132
  18. package/dist/Live2/MediaSubscriber.js.map +1 -1
  19. package/dist/Live2/MediaUtils/Compatibility.js +65 -25
  20. package/dist/Live2/MediaUtils/Compatibility.js.map +1 -1
  21. package/dist/Live2/MediaUtils/MediaDomUtils.js +58 -52
  22. package/dist/Live2/MediaUtils/MediaDomUtils.js.map +1 -1
  23. package/dist/Live2/MediaUtils/MediaTracer.js +1 -1
  24. package/dist/Live2/MediaUtils/MediaTracer.js.map +1 -1
  25. package/dist/Live2/MultiParty/DetectWebRtcService.js +114 -37
  26. package/dist/Live2/MultiParty/DetectWebRtcService.js.map +1 -1
  27. package/dist/Live2/MultiParty/MediaCapabilitiesService.js +201 -62
  28. package/dist/Live2/MultiParty/MediaCapabilitiesService.js.map +1 -1
  29. package/dist/Live2/MultiParty/MediaCapabilitiesUtils.js +109 -39
  30. package/dist/Live2/MultiParty/MediaCapabilitiesUtils.js.map +1 -1
  31. package/dist/Live2/MultiParty/MediaTracer.js +1 -1
  32. package/dist/Live2/MultiParty/MediaTracer.js.map +1 -1
  33. package/dist/Live2/MultiParty/MultiPartyService.js +23 -3
  34. package/dist/Live2/MultiParty/MultiPartyService.js.map +1 -1
  35. package/dist/Live2/MultiParty/MultiPartyServiceFactory.js +3 -3
  36. package/dist/Live2/MultiParty/MultiPartyServiceFactory.js.map +1 -1
  37. package/dist/Live2/MultiParty/opentok/OpentokMultiPartyService.js +620 -318
  38. package/dist/Live2/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -1
  39. package/dist/Live2/MultiParty/opentok/OpentokPublisher.js +172 -56
  40. package/dist/Live2/MultiParty/opentok/OpentokPublisher.js.map +1 -1
  41. package/dist/Live2/MultiParty/opentok/OpentokPublisherEventMapper.js +15 -15
  42. package/dist/Live2/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -1
  43. package/dist/Live2/MultiParty/opentok/OpentokScreenPublisher.js +46 -12
  44. package/dist/Live2/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -1
  45. package/dist/Live2/MultiParty/opentok/OpentokSubscriber.js +5 -5
  46. package/dist/Live2/MultiParty/opentok/OpentokSubscriber.js.map +1 -1
  47. package/dist/Live2/MultiParty/opentok/OpentokVideoPublisher.js +213 -98
  48. package/dist/Live2/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -1
  49. package/dist/Live2/MultiParty/opentok/trace.js +8 -4
  50. package/dist/Live2/MultiParty/opentok/trace.js.map +1 -1
  51. package/dist/Live2/MultiParty/utils.js +1 -1
  52. package/dist/Live2/MultiParty/utils.js.map +1 -1
  53. package/dist/Live2/TechseeMediaStream.js +70 -25
  54. package/dist/Live2/TechseeMediaStream.js.map +1 -1
  55. package/dist/Live2/qos/raw-qos.js +297 -210
  56. package/dist/Live2/qos/raw-qos.js.map +1 -1
  57. package/dist/Live3/DetectWebRtcService.js +114 -38
  58. package/dist/Live3/DetectWebRtcService.js.map +1 -1
  59. package/dist/Live3/MediaCapabilitiesService.js +202 -63
  60. package/dist/Live3/MediaCapabilitiesService.js.map +1 -1
  61. package/dist/Live3/MediaCapabilitiesUtils.js +129 -55
  62. package/dist/Live3/MediaCapabilitiesUtils.js.map +1 -1
  63. package/dist/Live3/MediaTracer.js +1 -1
  64. package/dist/Live3/MediaTracer.js.map +1 -1
  65. package/dist/Live3/MultiPartyService.js +23 -3
  66. package/dist/Live3/MultiPartyService.js.map +1 -1
  67. package/dist/Live3/MultiPartyServiceFactory.js +3 -3
  68. package/dist/Live3/MultiPartyServiceFactory.js.map +1 -1
  69. package/dist/Live3/opentok/OpentokMultiPartyService.js +577 -319
  70. package/dist/Live3/opentok/OpentokMultiPartyService.js.map +1 -1
  71. package/dist/Live3/opentok/OpentokPublisher.js +264 -114
  72. package/dist/Live3/opentok/OpentokPublisher.js.map +1 -1
  73. package/dist/Live3/opentok/OpentokPublisherEventMapper.js +18 -17
  74. package/dist/Live3/opentok/OpentokPublisherEventMapper.js.map +1 -1
  75. package/dist/Live3/opentok/OpentokSubscriber.js +7 -6
  76. package/dist/Live3/opentok/OpentokSubscriber.js.map +1 -1
  77. package/dist/Live3/opentok/trace.js +9 -5
  78. package/dist/Live3/opentok/trace.js.map +1 -1
  79. package/dist/Live3/utils.js +3 -3
  80. package/dist/Live3/utils.js.map +1 -1
  81. package/package.json +1 -1
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -6,344 +17,418 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
17
  exports.LocalStreamManager = void 0;
7
18
  // eslint-disable-next-line eslint-comments/disable-enable-pair
8
19
  /*eslint-disable operator-linebreak */
9
- const assign_1 = __importDefault(require("lodash/assign"));
10
- const get_1 = __importDefault(require("lodash/get"));
11
- const last_1 = __importDefault(require("lodash/last"));
12
- const first_1 = __importDefault(require("lodash/first"));
13
- const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
14
- const bluebird_1 = require("bluebird");
15
- const MediaConstants_1 = require("./MediaConstants");
16
- const MediaTracer_1 = require("./MediaUtils/MediaTracer");
20
+ var assign_1 = __importDefault(require("lodash/assign"));
21
+ var get_1 = __importDefault(require("lodash/get"));
22
+ var last_1 = __importDefault(require("lodash/last"));
23
+ var first_1 = __importDefault(require("lodash/first"));
24
+ var cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
25
+ var bluebird_1 = require("bluebird");
26
+ var MediaConstants_1 = require("./MediaConstants");
27
+ var MediaTracer_1 = require("./MediaUtils/MediaTracer");
17
28
  window.latestUserMediaStream = null;
18
- let userMediaPromise = null;
29
+ var userMediaPromise = null;
19
30
  window.latestDesktopMediaStream = null;
20
- let desktopMediaPromise = null;
31
+ var desktopMediaPromise = null;
21
32
  window.mediaStreamAlreadyReplaced = false;
22
33
  window.latestLocalMediaConstraints = null;
23
- const trace = (0, MediaTracer_1.getMediaTracer)('LocalStreamManager');
24
- class LocalStreamManager {
25
- environment;
26
- _groupedDevices = { video: null, audio: null, camerasCount: 0 };
27
- constructor(environment) {
34
+ var trace = (0, MediaTracer_1.getMediaTracer)('LocalStreamManager');
35
+ var LocalStreamManager = /** @class */ (function () {
36
+ function LocalStreamManager(environment) {
37
+ Object.defineProperty(this, "environment", {
38
+ enumerable: true,
39
+ configurable: true,
40
+ writable: true,
41
+ value: void 0
42
+ });
43
+ Object.defineProperty(this, "_groupedDevices", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: { video: null, audio: null, camerasCount: 0 }
48
+ });
28
49
  this.environment = environment;
29
50
  this.parseMediaErrorThenThrow = this.parseMediaErrorThenThrow.bind(this);
30
51
  this.clearAllStreams = this.clearAllStreams.bind(this);
31
52
  }
32
- get groupedDevices() {
33
- return this._groupedDevices;
34
- }
35
- getUserMediaStream(constraints) {
36
- trace.info('getUserMediaStream', constraints);
37
- if (userMediaPromise) {
38
- return userMediaPromise;
39
- }
40
- if (window.latestUserMediaStream) {
41
- const videoTrack = window.latestUserMediaStream.mediaStream.getVideoTracks();
42
- if (videoTrack.length > 0 && videoTrack[0].readyState === 'live') {
43
- return bluebird_1.Promise.resolve({ ...window.latestUserMediaStream, isNew: false });
53
+ Object.defineProperty(LocalStreamManager.prototype, "groupedDevices", {
54
+ get: function () {
55
+ return this._groupedDevices;
56
+ },
57
+ enumerable: false,
58
+ configurable: true
59
+ });
60
+ Object.defineProperty(LocalStreamManager.prototype, "getUserMediaStream", {
61
+ enumerable: false,
62
+ configurable: true,
63
+ writable: true,
64
+ value: function (constraints) {
65
+ var _this = this;
66
+ trace.info('getUserMediaStream', constraints);
67
+ if (userMediaPromise) {
68
+ return userMediaPromise;
44
69
  }
45
- this.destroyUserMediaStream();
46
- }
47
- userMediaPromise = new bluebird_1.Promise((resolve, reject) => {
48
- const catchHandler = (err) => {
49
- userMediaPromise = null;
50
- window.latestUserMediaStream = null;
51
- trace.error('getUserMedia error', err);
52
- reject(err);
53
- };
54
- try {
55
- this.getHighestResolutionStream(false, constraints)
56
- .then((streamResult) => {
70
+ if (window.latestUserMediaStream) {
71
+ var videoTrack = window.latestUserMediaStream.mediaStream.getVideoTracks();
72
+ if (videoTrack.length > 0 && videoTrack[0].readyState === 'live') {
73
+ return bluebird_1.Promise.resolve(__assign(__assign({}, window.latestUserMediaStream), { isNew: false }));
74
+ }
75
+ this.destroyUserMediaStream();
76
+ }
77
+ userMediaPromise = new bluebird_1.Promise(function (resolve, reject) {
78
+ var catchHandler = function (err) {
57
79
  userMediaPromise = null;
58
- window.latestUserMediaStream = streamResult;
59
- window.latestLocalMediaConstraints = (0, cloneDeep_1.default)(constraints);
60
- window.latestLocalMediaConstraints.audio = (streamResult.constraint &&
61
- streamResult.constraint.audio);
62
- resolve({ ...window.latestUserMediaStream, isNew: true });
63
- })
64
- .catch(catchHandler);
80
+ window.latestUserMediaStream = null;
81
+ trace.error('getUserMedia error', err);
82
+ reject(err);
83
+ };
84
+ try {
85
+ _this.getHighestResolutionStream(false, constraints)
86
+ .then(function (streamResult) {
87
+ userMediaPromise = null;
88
+ window.latestUserMediaStream = streamResult;
89
+ window.latestLocalMediaConstraints = (0, cloneDeep_1.default)(constraints);
90
+ window.latestLocalMediaConstraints.audio = (streamResult.constraint &&
91
+ streamResult.constraint.audio);
92
+ resolve(__assign(__assign({}, window.latestUserMediaStream), { isNew: true }));
93
+ })
94
+ .catch(catchHandler);
95
+ }
96
+ catch (err) {
97
+ catchHandler(err);
98
+ }
99
+ });
100
+ return userMediaPromise;
101
+ }
102
+ });
103
+ Object.defineProperty(LocalStreamManager.prototype, "getDesktopMediaStream", {
104
+ enumerable: false,
105
+ configurable: true,
106
+ writable: true,
107
+ value: function (constraints) {
108
+ var _this = this;
109
+ if (desktopMediaPromise) {
110
+ return desktopMediaPromise;
65
111
  }
66
- catch (err) {
67
- catchHandler(err);
112
+ trace.info('getDesktopMediaStream', constraints);
113
+ if (window.latestDesktopMediaStream) {
114
+ var track = window.latestDesktopMediaStream.mediaStream.getVideoTracks();
115
+ if (track.length > 0 && track[0].readyState === 'live') {
116
+ //return Promise.resolve();
117
+ return bluebird_1.Promise.resolve(__assign(__assign({}, window.latestDesktopMediaStream), { isNew: false }));
118
+ }
119
+ this.destroyDesktopMediaStream().catch(function (error) {
120
+ trace.error('Error destroying desktop media stream', error);
121
+ });
68
122
  }
69
- });
70
- return userMediaPromise;
71
- }
72
- getDesktopMediaStream(constraints) {
73
- if (desktopMediaPromise) {
123
+ desktopMediaPromise = new bluebird_1.Promise(function (resolve, reject) {
124
+ var mediaCatchHandler = function (err) {
125
+ desktopMediaPromise = null;
126
+ window.latestDesktopMediaStream = null;
127
+ trace.error('getDisplayMedia error', err);
128
+ reject(err);
129
+ };
130
+ try {
131
+ _this.getHighestResolutionStream(true, { video: constraints, audio: false })
132
+ .then(function (streamResult) {
133
+ desktopMediaPromise = null;
134
+ window.latestDesktopMediaStream = streamResult;
135
+ resolve(__assign(__assign({}, window.latestDesktopMediaStream), { isNew: true }));
136
+ })
137
+ .catch(mediaCatchHandler);
138
+ }
139
+ catch (err) {
140
+ mediaCatchHandler(err);
141
+ }
142
+ });
74
143
  return desktopMediaPromise;
75
144
  }
76
- trace.info('getDesktopMediaStream', constraints);
77
- if (window.latestDesktopMediaStream) {
78
- const track = window.latestDesktopMediaStream.mediaStream.getVideoTracks();
79
- if (track.length > 0 && track[0].readyState === 'live') {
80
- //return Promise.resolve();
81
- return bluebird_1.Promise.resolve({ ...window.latestDesktopMediaStream, isNew: false });
145
+ });
146
+ Object.defineProperty(LocalStreamManager.prototype, "destroyUserMediaStream", {
147
+ enumerable: false,
148
+ configurable: true,
149
+ writable: true,
150
+ value: function () {
151
+ var streamResult = window.latestUserMediaStream;
152
+ userMediaPromise = null;
153
+ window.latestUserMediaStream = null;
154
+ window.latestLocalMediaConstraints = null;
155
+ window.mediaStreamAlreadyReplaced = false;
156
+ if (streamResult && streamResult.mediaStream) {
157
+ try {
158
+ streamResult.mediaStream.getTracks().forEach(function (track) {
159
+ track.stop();
160
+ });
161
+ trace.info('destroyUserMediaStream - stop all tracks');
162
+ }
163
+ catch (e) {
164
+ trace.info('destroyUserMediaStream - Failed to stop all tracks', e);
165
+ }
82
166
  }
83
- this.destroyDesktopMediaStream().catch((error) => {
84
- trace.error('Error destroying desktop media stream', error);
85
- });
167
+ return bluebird_1.Promise.resolve();
86
168
  }
87
- desktopMediaPromise = new bluebird_1.Promise((resolve, reject) => {
88
- const mediaCatchHandler = (err) => {
89
- desktopMediaPromise = null;
90
- window.latestDesktopMediaStream = null;
91
- trace.error('getDisplayMedia error', err);
92
- reject(err);
93
- };
94
- try {
95
- this.getHighestResolutionStream(true, { video: constraints, audio: false })
96
- .then((streamResult) => {
97
- desktopMediaPromise = null;
98
- window.latestDesktopMediaStream = streamResult;
99
- resolve({ ...window.latestDesktopMediaStream, isNew: true });
100
- })
101
- .catch(mediaCatchHandler);
169
+ });
170
+ Object.defineProperty(LocalStreamManager.prototype, "destroyDesktopMediaStream", {
171
+ enumerable: false,
172
+ configurable: true,
173
+ writable: true,
174
+ value: function () {
175
+ var streamResult = window.latestDesktopMediaStream;
176
+ window.latestDesktopMediaStream = null;
177
+ desktopMediaPromise = null;
178
+ if (streamResult && streamResult.mediaStream) {
179
+ try {
180
+ streamResult.mediaStream.getTracks().forEach(function (track) {
181
+ track.stop();
182
+ });
183
+ trace.info('destroyDesktopMediaStream - stop all tracks');
184
+ }
185
+ catch (e) {
186
+ trace.info('destroyDesktopMediaStream - Failed to stop all tracks', e);
187
+ }
102
188
  }
103
- catch (err) {
104
- mediaCatchHandler(err);
189
+ return bluebird_1.Promise.resolve();
190
+ }
191
+ });
192
+ Object.defineProperty(LocalStreamManager.prototype, "clearAllStreams", {
193
+ enumerable: false,
194
+ configurable: true,
195
+ writable: true,
196
+ value: function () {
197
+ trace.info('LocalStreamManager Clearing all streams');
198
+ return bluebird_1.Promise.all([this.destroyDesktopMediaStream(), this.destroyUserMediaStream()]).then(function () { return undefined; });
199
+ }
200
+ });
201
+ Object.defineProperty(LocalStreamManager.prototype, "getHighestResolutionStream", {
202
+ enumerable: false,
203
+ configurable: true,
204
+ writable: true,
205
+ value: function (isDesktopMedia, constraints) {
206
+ var _this = this;
207
+ var constraintsCandidates = this.getParsedConstraints(isDesktopMedia, constraints);
208
+ trace.info('getHighestResolutionStream - constraintsCandidates:', constraintsCandidates);
209
+ if (constraintsCandidates.length === 0) {
210
+ return bluebird_1.Promise.reject(new Error('No constraints to retrieve the stream'));
105
211
  }
106
- });
107
- return desktopMediaPromise;
108
- }
109
- destroyUserMediaStream() {
110
- const streamResult = window.latestUserMediaStream;
111
- userMediaPromise = null;
112
- window.latestUserMediaStream = null;
113
- window.latestLocalMediaConstraints = null;
114
- window.mediaStreamAlreadyReplaced = false;
115
- if (streamResult && streamResult.mediaStream) {
116
- try {
117
- streamResult.mediaStream.getTracks().forEach((track) => {
118
- track.stop();
212
+ return new bluebird_1.Promise(function (resolve, reject) {
213
+ var lastSuccessfulResult = null;
214
+ var lastFailedResult = null;
215
+ var isStreamRequestFulfilled = false;
216
+ bluebird_1.Promise
217
+ .reduce(constraintsCandidates, function (total, candidate) {
218
+ if (isStreamRequestFulfilled) {
219
+ return;
220
+ }
221
+ var constraintType = (0, get_1.default)(constraints, 'video.videoResolution.constraintType') ||
222
+ (0, get_1.default)(constraints, 'video.videoResolution[0].constraintType');
223
+ return _this.getStreamPromiseByParsedConstraints(candidate, isDesktopMedia)
224
+ .then(function (stream) {
225
+ lastSuccessfulResult = {
226
+ mediaStream: stream,
227
+ constraint: candidate,
228
+ constraintType: constraintType,
229
+ isNew: true
230
+ };
231
+ trace.info('getHighestResolutionStream Success', lastSuccessfulResult);
232
+ isStreamRequestFulfilled = true;
233
+ resolve(lastSuccessfulResult);
234
+ })
235
+ .catch(function (failResult) {
236
+ lastFailedResult = failResult;
237
+ if (lastFailedResult.errorCode === MediaConstants_1.MediaRequestErrorCode.PermissionDenied) {
238
+ isStreamRequestFulfilled = true;
239
+ reject(lastFailedResult);
240
+ }
241
+ });
242
+ }, 0)
243
+ .then(function () {
244
+ if (!isStreamRequestFulfilled) {
245
+ if (!lastFailedResult) {
246
+ lastFailedResult = {
247
+ errorCode: MediaConstants_1.MediaRequestErrorCode.GeneralError,
248
+ message: 'Suitable stream cannot be created'
249
+ };
250
+ }
251
+ reject(lastFailedResult);
252
+ }
119
253
  });
120
- trace.info('destroyUserMediaStream - stop all tracks');
254
+ });
255
+ }
256
+ });
257
+ Object.defineProperty(LocalStreamManager.prototype, "getUserMediaStreamMediaDevice", {
258
+ enumerable: false,
259
+ configurable: true,
260
+ writable: true,
261
+ value: function (constraints, isDesktopMedia) {
262
+ var streamPromise = null;
263
+ if (!isDesktopMedia) {
264
+ streamPromise = navigator.mediaDevices.getUserMedia(constraints);
121
265
  }
122
- catch (e) {
123
- trace.info('destroyUserMediaStream - Failed to stop all tracks', e);
266
+ else {
267
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
268
+ //@ts-ignore
269
+ streamPromise = navigator.mediaDevices.getDisplayMedia
270
+ ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
271
+ //@ts-ignore
272
+ navigator.mediaDevices.getDisplayMedia(constraints)
273
+ : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
274
+ //@ts-ignore
275
+ navigator.getDisplayMedia(constraints);
124
276
  }
277
+ return streamPromise;
125
278
  }
126
- return bluebird_1.Promise.resolve();
127
- }
128
- destroyDesktopMediaStream() {
129
- const streamResult = window.latestDesktopMediaStream;
130
- window.latestDesktopMediaStream = null;
131
- desktopMediaPromise = null;
132
- if (streamResult && streamResult.mediaStream) {
279
+ });
280
+ Object.defineProperty(LocalStreamManager.prototype, "getStreamPromiseByParsedConstraints", {
281
+ enumerable: false,
282
+ configurable: true,
283
+ writable: true,
284
+ value: function (constraints, isDesktopMedia) {
285
+ var _this = this;
286
+ trace.info('getStreamPromiseByParsedConstraints', constraints);
133
287
  try {
134
- streamResult.mediaStream.getTracks().forEach((track) => {
135
- track.stop();
288
+ return this.getUserMediaStreamMediaDevice(constraints, isDesktopMedia).catch(function (err) {
289
+ var streamPromise = null;
290
+ trace.info('getStreamPromiseByParsedConstraints - get user stream error', err.name);
291
+ // Android (Galaxy esp.) have a bug that when using facingMode it might cause NotReadableError. So
292
+ // we should try again but without facingMode. The exception to the rule is when we don't have specific
293
+ // device to use (like in IOS13 bug, as can be seen in MediaServiceBase.ts), in that case, we might end
294
+ // up using the front camera, which is a privacy concern and the preference is to fallback from video
295
+ if (err &&
296
+ err.name === 'NotReadableError' &&
297
+ (0, get_1.default)(constraints, 'video.facingMode') &&
298
+ (0, get_1.default)(constraints, 'video.deviceId')) {
299
+ var newConstraints = constraints;
300
+ trace.info("getStreamPromiseByParsedConstraints - NotReadableError - Failed to get video user media stream with facingMode=".concat((0, get_1.default)(constraints, 'video.facingMode')), err.name);
301
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
302
+ // @ts-ignore
303
+ delete newConstraints.video.facingMode;
304
+ newConstraints.video.deviceId = {
305
+ exact: constraints.video.deviceId
306
+ };
307
+ streamPromise = _this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
308
+ }
309
+ else if (err && err.name && constraints.audio && !constraints.video) {
310
+ trace.info('getStreamPromiseByParsedConstraints - audioStreamFailed - Failed to get audio user media stream', err.name);
311
+ return _this.parseMediaErrorThenThrow({ name: 'audioStreamFailed' });
312
+ }
313
+ else if (err && err.name && constraints.audio) {
314
+ var newConstraints = constraints;
315
+ trace.info('getStreamPromiseByParsedConstraints - Failed to get video and audio user media stream, try to get video media stream only', err.name);
316
+ newConstraints.audio = false;
317
+ streamPromise = _this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
318
+ }
319
+ else if (err && !streamPromise) {
320
+ trace.info('getStreamPromiseByParsedConstraints - Failed to get video user media stream', err && err.name);
321
+ streamPromise = bluebird_1.Promise.reject(err);
322
+ }
323
+ return streamPromise && streamPromise.catch(_this.parseMediaErrorThenThrow);
136
324
  });
137
- trace.info('destroyDesktopMediaStream - stop all tracks');
138
325
  }
139
326
  catch (e) {
140
- trace.info('destroyDesktopMediaStream - Failed to stop all tracks', e);
327
+ // @ts-ignore
328
+ return this.parseMediaErrorThenThrow(e);
141
329
  }
142
330
  }
143
- return bluebird_1.Promise.resolve();
144
- }
145
- clearAllStreams() {
146
- trace.info('LocalStreamManager Clearing all streams');
147
- return bluebird_1.Promise.all([this.destroyDesktopMediaStream(), this.destroyUserMediaStream()]).then(() => undefined);
148
- }
149
- getHighestResolutionStream(isDesktopMedia, constraints) {
150
- const constraintsCandidates = this.getParsedConstraints(isDesktopMedia, constraints);
151
- trace.info('getHighestResolutionStream - constraintsCandidates:', constraintsCandidates);
152
- if (constraintsCandidates.length === 0) {
153
- return bluebird_1.Promise.reject(new Error('No constraints to retrieve the stream'));
154
- }
155
- return new bluebird_1.Promise((resolve, reject) => {
156
- let lastSuccessfulResult = null;
157
- let lastFailedResult = null;
158
- let isStreamRequestFulfilled = false;
159
- bluebird_1.Promise
160
- .reduce(constraintsCandidates, (total, candidate) => {
161
- if (isStreamRequestFulfilled) {
162
- return;
163
- }
164
- const constraintType = (0, get_1.default)(constraints, 'video.videoResolution.constraintType') ||
165
- (0, get_1.default)(constraints, 'video.videoResolution[0].constraintType');
166
- return this.getStreamPromiseByParsedConstraints(candidate, isDesktopMedia)
167
- .then((stream) => {
168
- lastSuccessfulResult = {
169
- mediaStream: stream,
170
- constraint: candidate,
171
- constraintType,
172
- isNew: true
173
- };
174
- trace.info('getHighestResolutionStream Success', lastSuccessfulResult);
175
- isStreamRequestFulfilled = true;
176
- resolve(lastSuccessfulResult);
177
- })
178
- .catch((failResult) => {
179
- lastFailedResult = failResult;
180
- if (lastFailedResult.errorCode === MediaConstants_1.MediaRequestErrorCode.PermissionDenied) {
181
- isStreamRequestFulfilled = true;
182
- reject(lastFailedResult);
183
- }
184
- });
185
- }, 0)
186
- .then(() => {
187
- if (!isStreamRequestFulfilled) {
188
- if (!lastFailedResult) {
189
- lastFailedResult = {
190
- errorCode: MediaConstants_1.MediaRequestErrorCode.GeneralError,
191
- message: 'Suitable stream cannot be created'
192
- };
193
- }
194
- reject(lastFailedResult);
195
- }
196
- });
197
- });
198
- }
199
- getUserMediaStreamMediaDevice(constraints, isDesktopMedia) {
200
- let streamPromise = null;
201
- if (!isDesktopMedia) {
202
- streamPromise = navigator.mediaDevices.getUserMedia(constraints);
203
- }
204
- else {
205
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
206
- //@ts-ignore
207
- streamPromise = navigator.mediaDevices.getDisplayMedia
208
- ? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
209
- //@ts-ignore
210
- navigator.mediaDevices.getDisplayMedia(constraints)
211
- : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
212
- //@ts-ignore
213
- navigator.getDisplayMedia(constraints);
331
+ });
332
+ Object.defineProperty(LocalStreamManager.prototype, "setGroupedDevices", {
333
+ enumerable: false,
334
+ configurable: true,
335
+ writable: true,
336
+ value: function (groupedDevices) {
337
+ var _a;
338
+ trace.info('setGroupedDevices', groupedDevices);
339
+ this._groupedDevices = {
340
+ video: groupedDevices.video
341
+ ? (_a = {}, _a[MediaConstants_1.CameraTypes.BACK] = (0, last_1.default)(groupedDevices.video), _a[MediaConstants_1.CameraTypes.FRONT] = (0, first_1.default)(groupedDevices.video), _a) : null,
342
+ audio: (0, last_1.default)(groupedDevices.audio) || null,
343
+ camerasCount: groupedDevices.video.length
344
+ };
214
345
  }
215
- return streamPromise;
216
- }
217
- getStreamPromiseByParsedConstraints(constraints, isDesktopMedia) {
218
- trace.info('getStreamPromiseByParsedConstraints', constraints);
219
- try {
220
- return this.getUserMediaStreamMediaDevice(constraints, isDesktopMedia).catch((err) => {
221
- let streamPromise = null;
222
- trace.info('getStreamPromiseByParsedConstraints - get user stream error', err.name);
223
- // Android (Galaxy esp.) have a bug that when using facingMode it might cause NotReadableError. So
224
- // we should try again but without facingMode. The exception to the rule is when we don't have specific
225
- // device to use (like in IOS13 bug, as can be seen in MediaServiceBase.ts), in that case, we might end
226
- // up using the front camera, which is a privacy concern and the preference is to fallback from video
227
- if (err &&
228
- err.name === 'NotReadableError' &&
229
- (0, get_1.default)(constraints, 'video.facingMode') &&
230
- (0, get_1.default)(constraints, 'video.deviceId')) {
231
- const newConstraints = constraints;
232
- trace.info(`getStreamPromiseByParsedConstraints - NotReadableError - Failed to get video user media stream with facingMode=${(0, get_1.default)(constraints, 'video.facingMode')}`, err.name);
233
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
234
- // @ts-ignore
235
- delete newConstraints.video.facingMode;
236
- newConstraints.video.deviceId = {
237
- exact: constraints.video.deviceId
346
+ });
347
+ Object.defineProperty(LocalStreamManager.prototype, "getParsedConstraints", {
348
+ enumerable: false,
349
+ configurable: true,
350
+ writable: true,
351
+ value: function (isDesktopMedia, streamConstraints) {
352
+ var constraintCandidates = [];
353
+ //TODO - Alex: need to understand which constraints not compatible with screen share
354
+ if (isDesktopMedia) {
355
+ return [{ video: true }];
356
+ }
357
+ if (!streamConstraints) {
358
+ return constraintCandidates;
359
+ }
360
+ var baseConstraints = {};
361
+ baseConstraints.audio = typeof streamConstraints.audio === 'boolean' ? streamConstraints.audio : undefined;
362
+ if (!streamConstraints.video) {
363
+ return [baseConstraints];
364
+ }
365
+ var cameraType = streamConstraints.video !== 'boolean' &&
366
+ streamConstraints.video.videoSourceType;
367
+ baseConstraints.video = {
368
+ facingMode: cameraType && cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? 'user' : 'environment',
369
+ frameRate: { ideal: 15, max: 30 }
370
+ };
371
+ var deviceId = (0, get_1.default)(this._groupedDevices, "video.".concat(cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? MediaConstants_1.CameraTypes.FRONT : MediaConstants_1.CameraTypes.BACK, ".deviceId"));
372
+ if (deviceId) {
373
+ baseConstraints.video.deviceId = deviceId;
374
+ if (this._groupedDevices.camerasCount > 1) {
375
+ baseConstraints.video.facingMode = {
376
+ exact: baseConstraints.video.facingMode
238
377
  };
239
- streamPromise = this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
240
- }
241
- else if (err && err.name && constraints.audio && !constraints.video) {
242
- trace.info('getStreamPromiseByParsedConstraints - audioStreamFailed - Failed to get audio user media stream', err.name);
243
- return this.parseMediaErrorThenThrow({ name: 'audioStreamFailed' });
244
378
  }
245
- else if (err && err.name && constraints.audio) {
246
- const newConstraints = constraints;
247
- trace.info('getStreamPromiseByParsedConstraints - Failed to get video and audio user media stream, try to get video media stream only', err.name);
248
- newConstraints.audio = false;
249
- streamPromise = this.getStreamPromiseByParsedConstraints(newConstraints, isDesktopMedia);
250
- }
251
- else if (err && !streamPromise) {
252
- trace.info('getStreamPromiseByParsedConstraints - Failed to get video user media stream', err && err.name);
253
- streamPromise = bluebird_1.Promise.reject(err);
254
- }
255
- return streamPromise && streamPromise.catch(this.parseMediaErrorThenThrow);
256
- });
257
- }
258
- catch (e) {
259
- // @ts-ignore
260
- return this.parseMediaErrorThenThrow(e);
261
- }
262
- }
263
- setGroupedDevices(groupedDevices) {
264
- trace.info('setGroupedDevices', groupedDevices);
265
- this._groupedDevices = {
266
- video: groupedDevices.video
267
- ? { [MediaConstants_1.CameraTypes.BACK]: (0, last_1.default)(groupedDevices.video), [MediaConstants_1.CameraTypes.FRONT]: (0, first_1.default)(groupedDevices.video) }
268
- : null,
269
- audio: (0, last_1.default)(groupedDevices.audio) || null,
270
- camerasCount: groupedDevices.video.length
271
- };
272
- }
273
- getParsedConstraints(isDesktopMedia, streamConstraints) {
274
- const constraintCandidates = [];
275
- //TODO - Alex: need to understand which constraints not compatible with screen share
276
- if (isDesktopMedia) {
277
- return [{ video: true }];
278
- }
279
- if (!streamConstraints) {
280
- return constraintCandidates;
281
- }
282
- const baseConstraints = {};
283
- baseConstraints.audio = typeof streamConstraints.audio === 'boolean' ? streamConstraints.audio : undefined;
284
- if (!streamConstraints.video) {
285
- return [baseConstraints];
286
- }
287
- const cameraType = streamConstraints.video !== 'boolean' &&
288
- streamConstraints.video.videoSourceType;
289
- baseConstraints.video = {
290
- facingMode: cameraType && cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? 'user' : 'environment',
291
- frameRate: { ideal: 15, max: 30 }
292
- };
293
- const deviceId = (0, get_1.default)(this._groupedDevices, `video.${cameraType === MediaConstants_1.LocalVideoSourceType.CAMERA_FRONT ? MediaConstants_1.CameraTypes.FRONT : MediaConstants_1.CameraTypes.BACK}.deviceId`);
294
- if (deviceId) {
295
- baseConstraints.video.deviceId = deviceId;
296
- if (this._groupedDevices.camerasCount > 1) {
297
- baseConstraints.video.facingMode = {
298
- exact: baseConstraints.video.facingMode
299
- };
300
379
  }
301
- }
302
- const assignConstraint = (videoResolution) => {
303
- const [width, height] = videoResolution.resolution.split('x');
304
- const constraintCandidate = (0, assign_1.default)({}, baseConstraints);
305
- constraintCandidate.video = (0, assign_1.default)({}, baseConstraints.video, {
306
- width: _constraintByType(width, videoResolution.constraintType),
307
- height: _constraintByType(height, videoResolution.constraintType)
308
- });
309
- constraintCandidates.push(constraintCandidate);
310
- };
311
- if ((baseConstraints.video && typeof streamConstraints.video === 'boolean') ||
312
- !(streamConstraints.video.videoResolution instanceof Array)) {
313
- const defaultResolution = {
314
- resolution: MediaConstants_1.DEFAULT_VIDEO_RESOLUTION,
315
- constraintType: MediaConstants_1.DEFAULT_VIDEO_CONSTRAINT_TYPE
380
+ var assignConstraint = function (videoResolution) {
381
+ var _a = videoResolution.resolution.split('x'), width = _a[0], height = _a[1];
382
+ var constraintCandidate = (0, assign_1.default)({}, baseConstraints);
383
+ constraintCandidate.video = (0, assign_1.default)({}, baseConstraints.video, {
384
+ width: _constraintByType(width, videoResolution.constraintType),
385
+ height: _constraintByType(height, videoResolution.constraintType)
386
+ });
387
+ constraintCandidates.push(constraintCandidate);
316
388
  };
317
- assignConstraint(defaultResolution);
389
+ if ((baseConstraints.video && typeof streamConstraints.video === 'boolean') ||
390
+ !(streamConstraints.video.videoResolution instanceof Array)) {
391
+ var defaultResolution = {
392
+ resolution: MediaConstants_1.DEFAULT_VIDEO_RESOLUTION,
393
+ constraintType: MediaConstants_1.DEFAULT_VIDEO_CONSTRAINT_TYPE
394
+ };
395
+ assignConstraint(defaultResolution);
396
+ return constraintCandidates;
397
+ }
398
+ streamConstraints.video.videoResolution.forEach(assignConstraint);
318
399
  return constraintCandidates;
319
400
  }
320
- streamConstraints.video.videoResolution.forEach(assignConstraint);
321
- return constraintCandidates;
322
- }
323
- parseMediaErrorThenThrow(error) {
324
- if (error && error.errorCode) {
325
- throw error;
326
- }
327
- trace.error('Get media stream error.', error);
328
- const errorName = error && error.name ? error.name : '';
329
- const permissionErrorNames = ['NotAllowedError', 'PermissionDismissedError', 'PermissionDeniedError'];
330
- // const generalError = [
331
- // 'NotFoundError',
332
- // 'DevicesNotFoundError',
333
- // 'NotReadableError',
334
- // 'TrackStartError'
335
- // ];
336
- const constraintsErrors = ['OverconstrainedError', 'ConstraintNotSatisfiedError'];
337
- const isErrorOfType = (errorsArr) => errorsArr.filter((err) => err === errorName).length > 0;
338
- if (isErrorOfType(permissionErrorNames)) {
339
- throw { errorCode: MediaConstants_1.MediaRequestErrorCode.PermissionDenied, message: errorName };
340
- }
341
- if (isErrorOfType(constraintsErrors)) {
342
- throw { errorCode: MediaConstants_1.MediaRequestErrorCode.Overconstrained, message: errorName };
401
+ });
402
+ Object.defineProperty(LocalStreamManager.prototype, "parseMediaErrorThenThrow", {
403
+ enumerable: false,
404
+ configurable: true,
405
+ writable: true,
406
+ value: function (error) {
407
+ if (error && error.errorCode) {
408
+ throw error;
409
+ }
410
+ trace.error('Get media stream error.', error);
411
+ var errorName = error && error.name ? error.name : '';
412
+ var permissionErrorNames = ['NotAllowedError', 'PermissionDismissedError', 'PermissionDeniedError'];
413
+ // const generalError = [
414
+ // 'NotFoundError',
415
+ // 'DevicesNotFoundError',
416
+ // 'NotReadableError',
417
+ // 'TrackStartError'
418
+ // ];
419
+ var constraintsErrors = ['OverconstrainedError', 'ConstraintNotSatisfiedError'];
420
+ var isErrorOfType = function (errorsArr) { return errorsArr.filter(function (err) { return err === errorName; }).length > 0; };
421
+ if (isErrorOfType(permissionErrorNames)) {
422
+ throw { errorCode: MediaConstants_1.MediaRequestErrorCode.PermissionDenied, message: errorName };
423
+ }
424
+ if (isErrorOfType(constraintsErrors)) {
425
+ throw { errorCode: MediaConstants_1.MediaRequestErrorCode.Overconstrained, message: errorName };
426
+ }
427
+ throw { errorCode: MediaConstants_1.MediaRequestErrorCode.GeneralError, message: errorName };
343
428
  }
344
- throw { errorCode: MediaConstants_1.MediaRequestErrorCode.GeneralError, message: errorName };
345
- }
346
- }
429
+ });
430
+ return LocalStreamManager;
431
+ }());
347
432
  exports.LocalStreamManager = LocalStreamManager;
348
433
  function _constraintByType(value, type) {
349
434
  switch (type) {