@techsee/techsee-media-service 18.6.1 → 19.0.0

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