@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.
- package/dist/Live2/LocalStreamManager.js +387 -302
- package/dist/Live2/LocalStreamManager.js.map +1 -1
- package/dist/Live2/MediaConstants.js +1 -1
- package/dist/Live2/MediaConstants.js.map +1 -1
- package/dist/Live2/MediaPublisher.js +54 -21
- package/dist/Live2/MediaPublisher.js.map +1 -1
- package/dist/Live2/MediaServiceBase.js +990 -612
- package/dist/Live2/MediaServiceBase.js.map +1 -1
- package/dist/Live2/MediaSession/MediaServer.js +493 -335
- package/dist/Live2/MediaSession/MediaServer.js.map +1 -1
- package/dist/Live2/MediaSession/MediaSessionBase.js +134 -80
- package/dist/Live2/MediaSession/MediaSessionBase.js.map +1 -1
- package/dist/Live2/MediaSession/SessionOpentok.js +472 -325
- package/dist/Live2/MediaSession/SessionOpentok.js.map +1 -1
- package/dist/Live2/MediaSession/SessionTurn.js +556 -373
- package/dist/Live2/MediaSession/SessionTurn.js.map +1 -1
- package/dist/Live2/MediaSubscriber.js +271 -132
- package/dist/Live2/MediaSubscriber.js.map +1 -1
- package/dist/Live2/MediaUtils/Compatibility.js +65 -25
- package/dist/Live2/MediaUtils/Compatibility.js.map +1 -1
- package/dist/Live2/MediaUtils/MediaDomUtils.js +58 -52
- package/dist/Live2/MediaUtils/MediaDomUtils.js.map +1 -1
- package/dist/Live2/MediaUtils/MediaTracer.js +1 -1
- package/dist/Live2/MediaUtils/MediaTracer.js.map +1 -1
- package/dist/Live2/MultiParty/DetectWebRtcService.js +114 -37
- package/dist/Live2/MultiParty/DetectWebRtcService.js.map +1 -1
- package/dist/Live2/MultiParty/MediaCapabilitiesService.js +201 -62
- package/dist/Live2/MultiParty/MediaCapabilitiesService.js.map +1 -1
- package/dist/Live2/MultiParty/MediaCapabilitiesUtils.js +109 -39
- package/dist/Live2/MultiParty/MediaCapabilitiesUtils.js.map +1 -1
- package/dist/Live2/MultiParty/MediaTracer.js +1 -1
- package/dist/Live2/MultiParty/MediaTracer.js.map +1 -1
- package/dist/Live2/MultiParty/MultiPartyService.js +23 -3
- package/dist/Live2/MultiParty/MultiPartyService.js.map +1 -1
- package/dist/Live2/MultiParty/MultiPartyServiceFactory.js +3 -3
- package/dist/Live2/MultiParty/MultiPartyServiceFactory.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokMultiPartyService.js +620 -318
- package/dist/Live2/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokPublisher.js +172 -56
- package/dist/Live2/MultiParty/opentok/OpentokPublisher.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokPublisherEventMapper.js +15 -15
- package/dist/Live2/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokScreenPublisher.js +46 -12
- package/dist/Live2/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokSubscriber.js +5 -5
- package/dist/Live2/MultiParty/opentok/OpentokSubscriber.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/OpentokVideoPublisher.js +213 -98
- package/dist/Live2/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -1
- package/dist/Live2/MultiParty/opentok/trace.js +8 -4
- package/dist/Live2/MultiParty/opentok/trace.js.map +1 -1
- package/dist/Live2/MultiParty/utils.js +1 -1
- package/dist/Live2/MultiParty/utils.js.map +1 -1
- package/dist/Live2/TechseeMediaStream.js +70 -25
- package/dist/Live2/TechseeMediaStream.js.map +1 -1
- package/dist/Live2/qos/raw-qos.js +297 -210
- package/dist/Live2/qos/raw-qos.js.map +1 -1
- package/dist/Live3/DetectWebRtcService.js +114 -38
- package/dist/Live3/DetectWebRtcService.js.map +1 -1
- package/dist/Live3/MediaCapabilitiesService.js +202 -63
- package/dist/Live3/MediaCapabilitiesService.js.map +1 -1
- package/dist/Live3/MediaCapabilitiesUtils.js +129 -55
- package/dist/Live3/MediaCapabilitiesUtils.js.map +1 -1
- package/dist/Live3/MediaTracer.js +1 -1
- package/dist/Live3/MediaTracer.js.map +1 -1
- package/dist/Live3/MultiPartyService.js +23 -3
- package/dist/Live3/MultiPartyService.js.map +1 -1
- package/dist/Live3/MultiPartyServiceFactory.js +3 -3
- package/dist/Live3/MultiPartyServiceFactory.js.map +1 -1
- package/dist/Live3/opentok/OpentokMultiPartyService.js +577 -319
- package/dist/Live3/opentok/OpentokMultiPartyService.js.map +1 -1
- package/dist/Live3/opentok/OpentokPublisher.js +264 -114
- package/dist/Live3/opentok/OpentokPublisher.js.map +1 -1
- package/dist/Live3/opentok/OpentokPublisherEventMapper.js +18 -17
- package/dist/Live3/opentok/OpentokPublisherEventMapper.js.map +1 -1
- package/dist/Live3/opentok/OpentokSubscriber.js +7 -6
- package/dist/Live3/opentok/OpentokSubscriber.js.map +1 -1
- package/dist/Live3/opentok/trace.js +9 -5
- package/dist/Live3/opentok/trace.js.map +1 -1
- package/dist/Live3/utils.js +3 -3
- package/dist/Live3/utils.js.map +1 -1
- 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
29
|
+
var userMediaPromise = null;
|
|
19
30
|
window.latestDesktopMediaStream = null;
|
|
20
|
-
|
|
31
|
+
var desktopMediaPromise = null;
|
|
21
32
|
window.mediaStreamAlreadyReplaced = false;
|
|
22
33
|
window.latestLocalMediaConstraints = null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
environment
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
trace.error('Error destroying desktop media stream', error);
|
|
85
|
-
});
|
|
167
|
+
return bluebird_1.Promise.resolve();
|
|
86
168
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.
|
|
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
|
-
|
|
104
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
327
|
+
// @ts-ignore
|
|
328
|
+
return this.parseMediaErrorThenThrow(e);
|
|
141
329
|
}
|
|
142
330
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
429
|
+
});
|
|
430
|
+
return LocalStreamManager;
|
|
431
|
+
}());
|
|
347
432
|
exports.LocalStreamManager = LocalStreamManager;
|
|
348
433
|
function _constraintByType(value, type) {
|
|
349
434
|
switch (type) {
|