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