@techsee/techsee-media-service 999.0.2-switch → 999.0.3-alpha

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