@techsee/techsee-media-service 9.0.0 → 11.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.
- package/lib/MultiParty/MultiPartyService.d.ts +3 -5
- package/lib/MultiParty/MultiPartyService.d.ts.map +1 -1
- package/lib/MultiParty/MultiPartyService.js +4 -7
- package/lib/MultiParty/MultiPartyService.js.map +1 -1
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -1
- package/lib/MultiParty/MultiPartyServiceFactory.js +2 -2
- package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -1
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +11 -1
- package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -1
- package/lib/MultiParty/{OpentokMultiPartyService.d.ts → opentok/OpentokMultiPartyService.d.ts} +9 -13
- package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/{OpentokMultiPartyService.js → opentok/OpentokMultiPartyService.js} +109 -397
- package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts +25 -0
- package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokPublisher.js +409 -0
- package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.js +32 -0
- package/lib/MultiParty/opentok/OpentokSubscriber.js.map +1 -0
- package/lib/MultiParty/opentok/OpentokUtils.d.ts +2 -0
- package/lib/MultiParty/opentok/OpentokUtils.d.ts.map +1 -0
- package/lib/MultiParty/opentok/OpentokUtils.js +17 -0
- package/lib/MultiParty/opentok/OpentokUtils.js.map +1 -0
- package/lib/MultiParty/opentok/trace.d.ts +2 -0
- package/lib/MultiParty/opentok/trace.d.ts.map +1 -0
- package/lib/MultiParty/opentok/trace.js +31 -0
- package/lib/MultiParty/opentok/trace.js.map +1 -0
- package/package.json +8 -6
- package/lib/MultiParty/OpentokMultiPartyService.d.ts.map +0 -1
- package/lib/MultiParty/OpentokMultiPartyService.js.map +0 -1
- package/lib/oldCode/constants.js +0 -25
- package/lib/oldCode/constants.js.map +0 -1
- package/lib/oldCode/event-emitter.js +0 -62
- package/lib/oldCode/event-emitter.js.map +0 -1
- package/lib/oldCode/index.js +0 -60
- package/lib/oldCode/index.js.map +0 -1
- package/lib/oldCode/opentok/session.js +0 -335
- package/lib/oldCode/opentok/session.js.map +0 -1
- package/lib/oldCode/opentok/stream.js +0 -324
- package/lib/oldCode/opentok/stream.js.map +0 -1
- package/lib/oldCode/publisher.js +0 -168
- package/lib/oldCode/publisher.js.map +0 -1
- package/lib/oldCode/service.js +0 -417
- package/lib/oldCode/service.js.map +0 -1
- package/lib/oldCode/session.js +0 -132
- package/lib/oldCode/session.js.map +0 -1
- package/lib/oldCode/stream.js +0 -223
- package/lib/oldCode/stream.js.map +0 -1
- package/lib/oldCode/subscriber.js +0 -115
- package/lib/oldCode/subscriber.js.map +0 -1
- package/lib/oldCode/tracer.d.ts +0 -36
- package/lib/oldCode/tracer.d.ts.map +0 -1
- package/lib/oldCode/tracer.js +0 -202
- package/lib/oldCode/tracer.js.map +0 -1
- package/lib/oldCode/utils/ImageFixer.d.ts +0 -1
- package/lib/oldCode/utils/ImageFixer.d.ts.map +0 -1
- package/lib/oldCode/utils/ImageFixer.js +0 -83
- package/lib/oldCode/utils/ImageFixer.js.map +0 -1
- package/lib/oldCode/webrtc/constants.js +0 -106
- package/lib/oldCode/webrtc/constants.js.map +0 -1
- package/lib/oldCode/webrtc/helper.js +0 -225
- package/lib/oldCode/webrtc/helper.js.map +0 -1
- package/lib/oldCode/webrtc/session-kms.js +0 -573
- package/lib/oldCode/webrtc/session-kms.js.map +0 -1
- package/lib/oldCode/webrtc/session-loopback.js +0 -354
- package/lib/oldCode/webrtc/session-loopback.js.map +0 -1
- package/lib/oldCode/webrtc/session-turn.js +0 -927
- package/lib/oldCode/webrtc/session-turn.js.map +0 -1
- package/lib/oldCode/webrtc/session-turn.v2.js +0 -592
- package/lib/oldCode/webrtc/session-turn.v2.js.map +0 -1
- package/lib/oldCode/webrtc/session.js +0 -58
- package/lib/oldCode/webrtc/session.js.map +0 -1
- package/lib/oldCode/webrtc/stream.js +0 -696
- package/lib/oldCode/webrtc/stream.js.map +0 -1
- package/lib/oldCode/webrtc/temasys/adapter-loader.js +0 -11
- package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +0 -1
- package/lib/oldCode/webrtc/temasys/adapter.js +0 -5933
- package/lib/oldCode/webrtc/temasys/adapter.js.map +0 -1
- package/lib/oldCode/webrtc/webrtc-ie-shim.js +0 -3437
- package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +0 -1
|
@@ -1,696 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
Object.defineProperty(exports, "EVENTS", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function get() {
|
|
11
|
-
return _stream.EVENTS;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
exports.TsWebRTCStream = void 0;
|
|
15
|
-
|
|
16
|
-
var _stream = require("../stream");
|
|
17
|
-
|
|
18
|
-
var _session = require("../session");
|
|
19
|
-
|
|
20
|
-
var _subscriber = require("../subscriber");
|
|
21
|
-
|
|
22
|
-
var _constants = require("./constants");
|
|
23
|
-
|
|
24
|
-
var _tsEnvironmentDetect = require("@techsee/techsee-common/lib/helpers/ts-environment-detect");
|
|
25
|
-
|
|
26
|
-
var _retryWithTimeout = require("@techsee/techsee-common/lib/core/retry-with-timeout");
|
|
27
|
-
|
|
28
|
-
var _tracer = require("../tracer");
|
|
29
|
-
|
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
|
|
32
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
33
|
-
|
|
34
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
35
|
-
|
|
36
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
|
-
|
|
38
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
39
|
-
|
|
40
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
41
|
-
|
|
42
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
43
|
-
|
|
44
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
45
|
-
|
|
46
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
47
|
-
|
|
48
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
49
|
-
|
|
50
|
-
var TORCH_DELAY = 1500;
|
|
51
|
-
var isIE11 = new _tsEnvironmentDetect.TsEnvironmentDetect().isIE11();
|
|
52
|
-
var tracer = (0, _tracer.getTracer)();
|
|
53
|
-
/**
|
|
54
|
-
* WebRTC-specific implementation of TsMediaStream.
|
|
55
|
-
*
|
|
56
|
-
* Instances of this class are mostly used internally by TsMediaPublisher
|
|
57
|
-
* and for subscribers creating.
|
|
58
|
-
*
|
|
59
|
-
* @class
|
|
60
|
-
* @extends TsMediaStream
|
|
61
|
-
*
|
|
62
|
-
* @see TsMediaStream
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
var TsWebRTCStream = /*#__PURE__*/function (_TsMediaStream) {
|
|
66
|
-
_inherits(TsWebRTCStream, _TsMediaStream);
|
|
67
|
-
|
|
68
|
-
var _super = _createSuper(TsWebRTCStream);
|
|
69
|
-
|
|
70
|
-
function TsWebRTCStream(session, mediaStream, name, isRemote, videoTrackSettings) {
|
|
71
|
-
var _this;
|
|
72
|
-
|
|
73
|
-
_classCallCheck(this, TsWebRTCStream);
|
|
74
|
-
|
|
75
|
-
_this = _super.call(this, mediaStream.id, session, isRemote, videoTrackSettings); //In TurnWebRtcSessionV2, we keep connection on instance of stream.
|
|
76
|
-
|
|
77
|
-
_this.peerConnection = null;
|
|
78
|
-
_this._torchDelayTimeOut = null;
|
|
79
|
-
_this._torchOffTimeOut = null;
|
|
80
|
-
/**
|
|
81
|
-
* Browser's native media stream
|
|
82
|
-
*
|
|
83
|
-
* @public
|
|
84
|
-
* @member { Object }
|
|
85
|
-
*
|
|
86
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream API}
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
_this._mediaStream = mediaStream;
|
|
90
|
-
/**
|
|
91
|
-
* Instance of TsWebRTCSession
|
|
92
|
-
*
|
|
93
|
-
* @private
|
|
94
|
-
* @member { Object }
|
|
95
|
-
*
|
|
96
|
-
* @see TsWebRTCSession
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
_this._session = session;
|
|
100
|
-
_this._name = name;
|
|
101
|
-
|
|
102
|
-
if (!_this._name) {
|
|
103
|
-
if (_this.hasVideo) {
|
|
104
|
-
if (!_this._session._isMobile) {
|
|
105
|
-
_this._name = _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_VIDEO_STREAM;
|
|
106
|
-
}
|
|
107
|
-
} else if (_this.hasAudio) {
|
|
108
|
-
if (_this._session._isMobile) {
|
|
109
|
-
_this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM;
|
|
110
|
-
} else {
|
|
111
|
-
_this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (!_this._name) {
|
|
117
|
-
_this._name = Math.random().toString();
|
|
118
|
-
} // TODO I think this will never be emitted, as both app/mobile call session.off() before they call session.disconnect(). And we call the destroy elsewhere
|
|
119
|
-
// TODO Need to make sure that it's always the case, especially for IOS
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
session.on(_session.EVENTS.DISCONNECTED, function () {
|
|
123
|
-
if (_this.publisher) {
|
|
124
|
-
_this.publisher.destroy();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (_this.subscriber) {
|
|
128
|
-
_this.subscriber.destroy();
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
return _this;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Unique id of the stream
|
|
135
|
-
*
|
|
136
|
-
* @member { String }
|
|
137
|
-
* @type { String }
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
_createClass(TsWebRTCStream, [{
|
|
142
|
-
key: "id",
|
|
143
|
-
get: function get() {
|
|
144
|
-
return this._mediaStream.id;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Unique name of the stream
|
|
148
|
-
*
|
|
149
|
-
* @member { String }
|
|
150
|
-
* @type { String }
|
|
151
|
-
*/
|
|
152
|
-
|
|
153
|
-
}, {
|
|
154
|
-
key: "name",
|
|
155
|
-
get: function get() {
|
|
156
|
-
return this._name;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Whether or not stream has enabled video tracks
|
|
160
|
-
*
|
|
161
|
-
* @member { Boolean }
|
|
162
|
-
* @type { Boolean }
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
|
-
}, {
|
|
166
|
-
key: "hasVideo",
|
|
167
|
-
get: function get() {
|
|
168
|
-
var enabledVideoTracks = this._mediaStream.getVideoTracks().filter(function (track) {
|
|
169
|
-
return track.enabled;
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
return enabledVideoTracks.length > 0;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Whether or not stream has enabled audio tracks
|
|
176
|
-
*
|
|
177
|
-
* @member { Boolean }
|
|
178
|
-
* @type { Boolean }
|
|
179
|
-
*/
|
|
180
|
-
|
|
181
|
-
}, {
|
|
182
|
-
key: "hasAudio",
|
|
183
|
-
get: function get() {
|
|
184
|
-
var enabledAudioTracks = this._mediaStream.getAudioTracks().filter(function (track) {
|
|
185
|
-
return track.enabled;
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return enabledAudioTracks.length > 0;
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
key: "_getPeerConnection",
|
|
192
|
-
value: function _getPeerConnection() {
|
|
193
|
-
// KMS store the peer connection as _pc, TURN store it as _lastPc
|
|
194
|
-
return this.peerConnection || _.get(this._session, '_lastPc.peerConnection') || _.get(this._session, '_pc.peerConnection');
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Publish or unpublish audio tracks.
|
|
198
|
-
*
|
|
199
|
-
* Used internally by TsMediaPublisher.publishAudio
|
|
200
|
-
*
|
|
201
|
-
* @method
|
|
202
|
-
*
|
|
203
|
-
* @param { Boolean } publish
|
|
204
|
-
*
|
|
205
|
-
* @fires SESSION_EVENTS.STREAM_PROPERTY_CHANGED
|
|
206
|
-
* @fires STREAM_EVENTS.PROPERTY_CHANGED
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
|
-
}, {
|
|
210
|
-
key: "publishAudio",
|
|
211
|
-
value: function publishAudio(publish) {
|
|
212
|
-
this._mediaStream.getTracks().forEach(function (track) {
|
|
213
|
-
if (track.kind === 'audio') {
|
|
214
|
-
if (track.setEnabled) {
|
|
215
|
-
track.setEnabled(publish);
|
|
216
|
-
} else {
|
|
217
|
-
track.enabled = publish;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
|
|
223
|
-
stream: this,
|
|
224
|
-
property: 'hasAudio',
|
|
225
|
-
value: publish
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
this.emit(_stream.EVENTS.PROPERTY_CHANGED, {
|
|
229
|
-
stream: this,
|
|
230
|
-
property: 'hasAudio',
|
|
231
|
-
value: publish
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Publish or unpublish video tracks.
|
|
236
|
-
*
|
|
237
|
-
* Used internally by TsMediaPublisher.publishVideo
|
|
238
|
-
*
|
|
239
|
-
* @method
|
|
240
|
-
*
|
|
241
|
-
* @param { Boolean } publish
|
|
242
|
-
*
|
|
243
|
-
* @fires SESSION_EVENTS.STREAM_PROPERTY_CHANGED
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
|
-
}, {
|
|
247
|
-
key: "publishVideo",
|
|
248
|
-
value: function publishVideo(publish) {
|
|
249
|
-
this._mediaStream.getTracks().forEach(function (track) {
|
|
250
|
-
if (track.kind === 'video') {
|
|
251
|
-
if (track.setEnabled) {
|
|
252
|
-
track.setEnabled(publish);
|
|
253
|
-
} else {
|
|
254
|
-
track.enabled = publish;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
|
|
260
|
-
stream: this,
|
|
261
|
-
property: 'hasVideo',
|
|
262
|
-
value: publish
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Subscribe to a remote stream.
|
|
267
|
-
*
|
|
268
|
-
* Used internally by TsMediaStream.subscribe
|
|
269
|
-
*
|
|
270
|
-
* @method
|
|
271
|
-
*
|
|
272
|
-
* @param { TsMediaStream } stream
|
|
273
|
-
* @param { DOMElement } target
|
|
274
|
-
* @param { Object } params
|
|
275
|
-
* @param { String|Number } params.height Subscriber's view height
|
|
276
|
-
* @param { String|Number } params.width Subscriber's view width
|
|
277
|
-
* @param { String } params.fitMode Subscriber's view fit mode
|
|
278
|
-
* @param { String } params.insertMode Subscriber's view insert mode (Is not in use yet)
|
|
279
|
-
*
|
|
280
|
-
* @returns { Promise<TsMediaSubscriber> } subsriber instance
|
|
281
|
-
*
|
|
282
|
-
* @see TsMediaStream
|
|
283
|
-
*/
|
|
284
|
-
|
|
285
|
-
}, {
|
|
286
|
-
key: "subscribe",
|
|
287
|
-
value: function subscribe(target) {
|
|
288
|
-
var _this2 = this;
|
|
289
|
-
|
|
290
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
291
|
-
height: '100%',
|
|
292
|
-
width: '100%',
|
|
293
|
-
fitMode: 'contain',
|
|
294
|
-
insertMode: 'append'
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
if (!params) {
|
|
298
|
-
params = target;
|
|
299
|
-
target = null;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
|
|
303
|
-
var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
|
|
304
|
-
|
|
305
|
-
var bindVideoStreamToElement = function bindVideoStreamToElement(stream, target) {
|
|
306
|
-
return new Promise(function (resolve, reject) {
|
|
307
|
-
var doResolve = function doResolve(videoEl) {
|
|
308
|
-
tracer.trace('Video element created successfully');
|
|
309
|
-
resolve(videoEl);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
var videoEl = document.createElement('video');
|
|
313
|
-
videoEl.muted = true;
|
|
314
|
-
videoEl.playsInline = true;
|
|
315
|
-
|
|
316
|
-
if (isIE11 && window.WebRTCAdapter) {
|
|
317
|
-
target.appendChild(videoEl);
|
|
318
|
-
window.WebRTCAdapter.bindVideoElement(videoEl);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
videoEl.srcObject = stream;
|
|
322
|
-
|
|
323
|
-
if (!isIE11) {
|
|
324
|
-
// Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play
|
|
325
|
-
videoEl.setAttribute('muted', '');
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
try {
|
|
329
|
-
var playRes = videoEl.play();
|
|
330
|
-
|
|
331
|
-
if (playRes && playRes.then) {
|
|
332
|
-
playRes.then(function () {
|
|
333
|
-
tracer.trace('Video element play success');
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (playRes && playRes["catch"]) {
|
|
338
|
-
playRes["catch"](function (error) {
|
|
339
|
-
tracer.trace('Reject while executing play method on video element', error);
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
} catch (error) {
|
|
343
|
-
tracer.trace('Error while executing play method on video element', error);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (isIE11) {
|
|
347
|
-
var handleComplete = function handleComplete() {
|
|
348
|
-
return videoEl.parentElement.tagName !== 'OBJECT';
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
var waitForObjectSettings = {
|
|
352
|
-
intervalInMs: 30,
|
|
353
|
-
timeoutInMs: 200
|
|
354
|
-
};
|
|
355
|
-
(0, _retryWithTimeout.repeatWithTimeout)(handleComplete, waitForObjectSettings).then(function () {
|
|
356
|
-
//We will wait, until video is played, then we resolve
|
|
357
|
-
var isVideoPlaying = function isVideoPlaying() {
|
|
358
|
-
return videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0;
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
var waitForVideoSettings = {
|
|
362
|
-
intervalInMs: 50,
|
|
363
|
-
timeoutInMs: 10000
|
|
364
|
-
};
|
|
365
|
-
(0, _retryWithTimeout.repeatWithTimeout)(isVideoPlaying, waitForVideoSettings).then(function () {
|
|
366
|
-
return doResolve(videoEl.parentElement);
|
|
367
|
-
})["catch"](function () {
|
|
368
|
-
return reject(new Error('Timeout while waiting for video to play'));
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
} else {
|
|
372
|
-
target.appendChild(videoEl);
|
|
373
|
-
doResolve(videoEl);
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
return bindVideoStreamToElement(this._mediaStream, target).then(function (videoEl) {
|
|
379
|
-
_.assign(videoEl.style, {
|
|
380
|
-
height: elementHeight,
|
|
381
|
-
width: elementWidth,
|
|
382
|
-
'object-fit': params.fitMode
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
var subscriber = new _subscriber.TsMediaSubscriber({
|
|
386
|
-
target: target,
|
|
387
|
-
_session: _this2._session,
|
|
388
|
-
stream: _this2,
|
|
389
|
-
_element: videoEl
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
_this2.setupDimensionsListener(videoEl, subscriber);
|
|
393
|
-
|
|
394
|
-
_this2.subscriber = subscriber;
|
|
395
|
-
return subscriber;
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* Unsubscribe from the stream and destroy subscriber's view.
|
|
400
|
-
*
|
|
401
|
-
* Used internally by TsMediaSubscriber.destroy.
|
|
402
|
-
*
|
|
403
|
-
* @method
|
|
404
|
-
*
|
|
405
|
-
* @param { TsMediaSubscriber } subscriber
|
|
406
|
-
*
|
|
407
|
-
* @returns { Promise }
|
|
408
|
-
*
|
|
409
|
-
* @fires SUBSCRIBER_EVENTS#DESTROYED
|
|
410
|
-
*
|
|
411
|
-
* @see TsMediaSubscriber#destroy
|
|
412
|
-
*/
|
|
413
|
-
|
|
414
|
-
}, {
|
|
415
|
-
key: "destroySubscriber",
|
|
416
|
-
value: function destroySubscriber(subscriber) {
|
|
417
|
-
return new Promise(function (resolve) {
|
|
418
|
-
var doResolve = function doResolve() {
|
|
419
|
-
subscriber.emit(_subscriber.EVENTS.DESTROYED);
|
|
420
|
-
resolve();
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
if (isIE11 && window.WebRTCAdapter) {
|
|
424
|
-
var videoEl = subscriber._element.firstChild;
|
|
425
|
-
window.WebRTCAdapter.unBindVideoElement(videoEl);
|
|
426
|
-
|
|
427
|
-
if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {
|
|
428
|
-
videoEl.parentNode.removeChild(videoEl);
|
|
429
|
-
tracer.trace('Video element removed successfully');
|
|
430
|
-
} else {
|
|
431
|
-
tracer.trace('Video element not removed', videoEl, videoEl.parentNode);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
doResolve();
|
|
435
|
-
} else {
|
|
436
|
-
subscriber._element.remove();
|
|
437
|
-
|
|
438
|
-
doResolve();
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
/* eslint-disable no-unused-vars */
|
|
443
|
-
|
|
444
|
-
}, {
|
|
445
|
-
key: "getSnapshot",
|
|
446
|
-
value: function getSnapshot(tsMediaElement) {
|
|
447
|
-
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
448
|
-
|
|
449
|
-
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
450
|
-
_ref$format = _ref.format,
|
|
451
|
-
format = _ref$format === void 0 ? 'image/png' : _ref$format,
|
|
452
|
-
_ref$quality = _ref.quality,
|
|
453
|
-
quality = _ref$quality === void 0 ? 0.92 : _ref$quality,
|
|
454
|
-
x = _ref.x,
|
|
455
|
-
y = _ref.y,
|
|
456
|
-
w = _ref.w,
|
|
457
|
-
h = _ref.h;
|
|
458
|
-
|
|
459
|
-
var videoElement = tsMediaElement._element;
|
|
460
|
-
var videoWidth = videoElement.videoWidth,
|
|
461
|
-
videoHeight = videoElement.videoHeight;
|
|
462
|
-
var crop = !_.isUndefined(x) && !_.isUndefined(y) && !_.isUndefined(w) && !_.isUndefined(h);
|
|
463
|
-
var resize = !crop && (!_.isUndefined(w) || !_.isUndefined(h));
|
|
464
|
-
|
|
465
|
-
if (resize) {
|
|
466
|
-
if (!h) {
|
|
467
|
-
h = w * (videoHeight / videoWidth);
|
|
468
|
-
} else if (!w) {
|
|
469
|
-
w = h * (videoWidth / videoHeight);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function getImgData() {
|
|
474
|
-
var canvas = document.createElement('canvas');
|
|
475
|
-
var ctx = canvas.getContext('2d');
|
|
476
|
-
|
|
477
|
-
if (crop) {
|
|
478
|
-
canvas.width = w;
|
|
479
|
-
canvas.height = h;
|
|
480
|
-
ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);
|
|
481
|
-
} else if (resize) {
|
|
482
|
-
canvas.width = w;
|
|
483
|
-
canvas.height = h;
|
|
484
|
-
ctx.drawImage(videoElement, 0, 0, w, h);
|
|
485
|
-
} else {
|
|
486
|
-
canvas.height = videoHeight;
|
|
487
|
-
canvas.width = videoWidth;
|
|
488
|
-
ctx.drawImage(videoElement, 0, 0);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
return canvas.toDataURL(format, quality);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
function getImgDataIE11() {
|
|
495
|
-
return new Promise(function (resolve) {
|
|
496
|
-
var canvas = document.createElement('canvas');
|
|
497
|
-
var ctx = canvas.getContext('2d');
|
|
498
|
-
|
|
499
|
-
if (crop || resize) {
|
|
500
|
-
canvas.width = w;
|
|
501
|
-
canvas.height = h;
|
|
502
|
-
} else {
|
|
503
|
-
canvas.height = videoHeight;
|
|
504
|
-
canvas.width = videoWidth;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
function _drawAndRemove(image) {
|
|
508
|
-
if (crop) {
|
|
509
|
-
ctx.drawImage(image, x, y, w, h, 0, 0, w, h);
|
|
510
|
-
} else if (resize) {
|
|
511
|
-
ctx.drawImage(image, 0, 0, w, h);
|
|
512
|
-
} else {
|
|
513
|
-
ctx.drawImage(image, 0, 0, videoWidth, videoHeight);
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
return canvas.toDataURL(format, quality);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
var base64 = videoElement.getFrame();
|
|
520
|
-
var image = new Image();
|
|
521
|
-
|
|
522
|
-
image.onload = function () {
|
|
523
|
-
return resolve(_drawAndRemove(image));
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
image.setAttribute('src', 'data:image/bmp;base64,' + base64);
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return Promise.resolve(isIE11 ? getImgDataIE11() : getImgData()).then(function (imgData) {
|
|
531
|
-
if (!imgData || imgData.length < 10) {
|
|
532
|
-
return Promise.reject('Failed to get a snapshot');
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return imgData;
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
/**
|
|
539
|
-
* Get statistics of the media subscription like bytes received.
|
|
540
|
-
*
|
|
541
|
-
* Used internally by TsMediaSubscriber.getStats
|
|
542
|
-
*
|
|
543
|
-
* @method
|
|
544
|
-
*
|
|
545
|
-
* @param { TsMediaSubscriber } subscriber
|
|
546
|
-
*
|
|
547
|
-
* @returns { Promise<ToBeDefined> } stats
|
|
548
|
-
*
|
|
549
|
-
* @see TsMediaSubscriber#getStats
|
|
550
|
-
*/
|
|
551
|
-
|
|
552
|
-
}, {
|
|
553
|
-
key: "getStats",
|
|
554
|
-
value: function getStats(subscriber) {
|
|
555
|
-
var _this3 = this;
|
|
556
|
-
|
|
557
|
-
return new Promise(function (resolve) {
|
|
558
|
-
try {
|
|
559
|
-
var pc = _this3._getPeerConnection();
|
|
560
|
-
|
|
561
|
-
if (isIE11 || !pc) {
|
|
562
|
-
return resolve();
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
pc.getStats(_this3._mediaStream.getVideoTracks()[0]).then(function (reports) {
|
|
566
|
-
var matches = [];
|
|
567
|
-
reports.forEach(function (report) {
|
|
568
|
-
if (_.includes(['inbound-rtp', 'ssrc'], report.type)) {
|
|
569
|
-
matches.push(report);
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
return resolve({
|
|
573
|
-
video: _.head(matches)
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
} catch (e) {
|
|
577
|
-
// when this fails, it's most likely due ot no support for the getStats
|
|
578
|
-
// functionality, so we don't want to log this as a recurring error
|
|
579
|
-
resolve();
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
/* eslint-enable no-unused-vars */
|
|
584
|
-
|
|
585
|
-
}, {
|
|
586
|
-
key: "getFullVideoStats",
|
|
587
|
-
value: function getFullVideoStats() {
|
|
588
|
-
var _this4 = this;
|
|
589
|
-
|
|
590
|
-
return new Promise(function (resolve, reject) {
|
|
591
|
-
try {
|
|
592
|
-
var pc = _this4._getPeerConnection();
|
|
593
|
-
|
|
594
|
-
if (!pc) {
|
|
595
|
-
return reject('NO_PEER_CONNECTION');
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
return resolve(pc.getStats(_this4._mediaStream.getVideoTracks()[0]));
|
|
599
|
-
} catch (e) {
|
|
600
|
-
reject(e);
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
|
-
}, {
|
|
605
|
-
key: "turnFlashlight",
|
|
606
|
-
value: function turnFlashlight() {
|
|
607
|
-
var _this5 = this;
|
|
608
|
-
|
|
609
|
-
var isTorchOn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
610
|
-
return new Promise(function (resolve, reject) {
|
|
611
|
-
if (_this5._torchDelayTimeOut) {
|
|
612
|
-
return reject('No tourch delay');
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
if (!navigator || !navigator.mediaDevices) {
|
|
616
|
-
return reject('No mediaDevices');
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
var track = _this5._mediaStream.getVideoTracks()[0];
|
|
620
|
-
|
|
621
|
-
if (!track) {
|
|
622
|
-
return reject('No track');
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
if (_this5._torchOffTimeOut) {
|
|
626
|
-
clearInterval(_this5._torchOffTimeOut);
|
|
627
|
-
_this5._torchOffTimeOut = null;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
_this5._torchDelayTimeOut = setTimeout(function () {
|
|
631
|
-
var capatibilitiesAfter = {};
|
|
632
|
-
|
|
633
|
-
try {
|
|
634
|
-
capatibilitiesAfter = track.getCapabilities();
|
|
635
|
-
} catch (e) {
|
|
636
|
-
return reject('No capabilities');
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
if (!capatibilitiesAfter.torch) {
|
|
640
|
-
return reject('No tourch capabilities');
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
return track.applyConstraints({
|
|
644
|
-
advanced: [{
|
|
645
|
-
torch: isTorchOn
|
|
646
|
-
}]
|
|
647
|
-
}).then(function () {
|
|
648
|
-
_this5._torchDelayTimeOut = null;
|
|
649
|
-
resolve(true);
|
|
650
|
-
})["catch"](function (e) {
|
|
651
|
-
_this5._torchDelayTimeOut = null;
|
|
652
|
-
console.error(e);
|
|
653
|
-
reject('Can\'t turn on the light, please try later!');
|
|
654
|
-
});
|
|
655
|
-
}, TORCH_DELAY);
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
}, {
|
|
659
|
-
key: "setAutoLightOffTimer",
|
|
660
|
-
value: function setAutoLightOffTimer(flashlightTimeout) {
|
|
661
|
-
var _this6 = this;
|
|
662
|
-
|
|
663
|
-
return new Promise(function (resolve) {
|
|
664
|
-
if (!flashlightTimeout) {
|
|
665
|
-
return reject('No timeout');
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
var track = _this6._mediaStream.getVideoTracks()[0];
|
|
669
|
-
|
|
670
|
-
if (!track) {
|
|
671
|
-
return reject('No track');
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
_this6._torchOffTimeOut = setTimeout(function () {
|
|
675
|
-
if (!track) {
|
|
676
|
-
return reject('No track');
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
track.applyConstraints({
|
|
680
|
-
advanced: [{
|
|
681
|
-
torch: false
|
|
682
|
-
}]
|
|
683
|
-
}).then(function () {
|
|
684
|
-
_this6._torchOffTimeOut = null;
|
|
685
|
-
resolve();
|
|
686
|
-
});
|
|
687
|
-
}, flashlightTimeout);
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
}]);
|
|
691
|
-
|
|
692
|
-
return TsWebRTCStream;
|
|
693
|
-
}(_stream.TsMediaStream);
|
|
694
|
-
|
|
695
|
-
exports.TsWebRTCStream = TsWebRTCStream;
|
|
696
|
-
//# sourceMappingURL=stream.js.map
|