@techsee/techsee-media-service 999.20.0-nodejs20 → 999.20.2-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 +1 -7
- 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 +0 -1
- 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/Contracts.d.ts +10 -0
- package/lib/MultiParty/Contracts.d.ts.map +1 -0
- package/lib/MultiParty/Contracts.js +6 -0
- package/lib/MultiParty/Contracts.js.map +1 -0
- 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 +19 -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 +25 -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 +61 -66
- 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,880 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.TurnWebRTCSession = 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 _session = require('../session');
|
|
9
|
+
|
|
10
|
+
var _publisher = require('../publisher');
|
|
11
|
+
|
|
12
|
+
var _stream = require('./stream');
|
|
13
|
+
|
|
14
|
+
var _socket = require('socket.io-client');
|
|
15
|
+
|
|
16
|
+
var io = _interopRequireWildcard(_socket);
|
|
17
|
+
|
|
18
|
+
var _tsEnvironmentDetect = require('@techsee/techsee-common/lib/helpers/ts-environment-detect');
|
|
19
|
+
|
|
20
|
+
var _constants = require('./constants');
|
|
21
|
+
|
|
22
|
+
var _helper = require('./helper');
|
|
23
|
+
|
|
24
|
+
var _tracer = require('../tracer');
|
|
25
|
+
|
|
26
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
27
|
+
|
|
28
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
var isIE11 = new _tsEnvironmentDetect.TsEnvironmentDetect().isIE11();
|
|
35
|
+
|
|
36
|
+
var _require = require('kurento-utils'),
|
|
37
|
+
WebRtcPeer = _require.WebRtcPeer; // eslint-disable-line global-require
|
|
38
|
+
|
|
39
|
+
var tracer = (0, _tracer.getTracer)();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* WebRTC-specific implementation of TsMediaSession.
|
|
43
|
+
*
|
|
44
|
+
* Instance of this class is returned by TsMediaService.initSession call
|
|
45
|
+
* with 'TURN_SERVER' as desired mediaType.
|
|
46
|
+
*
|
|
47
|
+
* @class
|
|
48
|
+
* @extends TsMediaSession
|
|
49
|
+
*
|
|
50
|
+
* @see TsMediaSession
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
var TurnWebRTCSession = exports.TurnWebRTCSession = function (_TsMediaSession) {
|
|
54
|
+
_inherits(TurnWebRTCSession, _TsMediaSession);
|
|
55
|
+
|
|
56
|
+
function TurnWebRTCSession(_ref, localStreamFactory) {
|
|
57
|
+
var credentials = _ref.credentials,
|
|
58
|
+
isMobile = _ref.isMobile,
|
|
59
|
+
resolution = _ref.resolution,
|
|
60
|
+
deviceOpts = _ref.deviceOpts;
|
|
61
|
+
|
|
62
|
+
_classCallCheck(this, TurnWebRTCSession);
|
|
63
|
+
|
|
64
|
+
var _this = _possibleConstructorReturn(this, _TsMediaSession.call(this));
|
|
65
|
+
|
|
66
|
+
tracer.trace('Constructor');
|
|
67
|
+
|
|
68
|
+
_this._credentials = credentials;
|
|
69
|
+
_this._isMobile = isMobile;
|
|
70
|
+
_this._resolution = resolution;
|
|
71
|
+
_this._deviceOpts = deviceOpts;
|
|
72
|
+
_this._incomingIce = [];
|
|
73
|
+
_this._localStreamFactory = localStreamFactory;
|
|
74
|
+
|
|
75
|
+
var iceServers = credentials.ice.map(function (item) {
|
|
76
|
+
return {
|
|
77
|
+
urls: item.url,
|
|
78
|
+
username: item.login,
|
|
79
|
+
credential: item.password
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
_this._configuration = {
|
|
84
|
+
iceServers: iceServers,
|
|
85
|
+
|
|
86
|
+
iceTransportPolicy: 'relay'
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Socket.io connection to the signaling server
|
|
91
|
+
*
|
|
92
|
+
* @private
|
|
93
|
+
* @member { Object }
|
|
94
|
+
*/
|
|
95
|
+
_this._socket = null;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* RTCPeerConnection to the media server.
|
|
99
|
+
*
|
|
100
|
+
* For now kurento-utils is used for connection establishment.
|
|
101
|
+
*
|
|
102
|
+
* @private
|
|
103
|
+
* @member { Object }
|
|
104
|
+
*/
|
|
105
|
+
_this._pcs = {};
|
|
106
|
+
return _this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Id of the session.
|
|
111
|
+
*
|
|
112
|
+
* @member { String }
|
|
113
|
+
*
|
|
114
|
+
* @type { String }
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* @member { String }
|
|
121
|
+
*
|
|
122
|
+
* @type { String }
|
|
123
|
+
*/
|
|
124
|
+
TurnWebRTCSession.prototype._connectSocket = function _connectSocket(url) {
|
|
125
|
+
var _this2 = this;
|
|
126
|
+
|
|
127
|
+
return new Promise(function (resolve, reject) {
|
|
128
|
+
tracer.trace('Connect socket');
|
|
129
|
+
var socket = io.connect(url, {
|
|
130
|
+
'forceNew': true,
|
|
131
|
+
'reconnectionDelay': _constants.SOCKET_RECONNECTION_DELAY,
|
|
132
|
+
'reconnectionDelayMax': _constants.SOCKET_RECONNECTION_DELAY_MAX,
|
|
133
|
+
'reconnectionAttempts': _constants.SOCKET_RECONNECTION_ATTEMPTS,
|
|
134
|
+
'path': _constants.SOCKET_PATH
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
var done = _.once(function (err) {
|
|
138
|
+
tracer.trace(err ? 'Error' : 'Connected', err);
|
|
139
|
+
err ? reject(err) : resolve();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
//
|
|
143
|
+
// When connection is established
|
|
144
|
+
//
|
|
145
|
+
socket.once('connect', function () {
|
|
146
|
+
return done();
|
|
147
|
+
});
|
|
148
|
+
//
|
|
149
|
+
// errorOccured is ts-media-client signal
|
|
150
|
+
//
|
|
151
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
152
|
+
//
|
|
153
|
+
// And these 2 are socket.io connection failed events
|
|
154
|
+
//
|
|
155
|
+
socket.on('connect_error', done);
|
|
156
|
+
socket.on('connect_timeout', done);
|
|
157
|
+
|
|
158
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, function (_ref2) {
|
|
159
|
+
var sdpAnswer = _ref2.sdpAnswer,
|
|
160
|
+
uid = _ref2.uid,
|
|
161
|
+
peerId = _ref2.peerId;
|
|
162
|
+
|
|
163
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.JOIN_RESPONSE');
|
|
164
|
+
|
|
165
|
+
var pc = _this2._pcs[peerId];
|
|
166
|
+
|
|
167
|
+
if (!pc) {
|
|
168
|
+
tracer.trace('No peer found');
|
|
169
|
+
var error = 'pc not found. peer=' + peerId + ' uid=' + uid;
|
|
170
|
+
|
|
171
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'JOIN_RESPONSE', error: error });
|
|
172
|
+
|
|
173
|
+
return done(error);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
pc.processAnswer(sdpAnswer, function (error) {
|
|
177
|
+
if (error) {
|
|
178
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'processAnswer', error: error });
|
|
179
|
+
|
|
180
|
+
return done(error);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
tracer.trace('ANSWER PROCESSED');
|
|
184
|
+
|
|
185
|
+
// FIXME why don't we have _incomingIce per PC? current assumes we don't have parallel connections, not good
|
|
186
|
+
_.forEach(_this2._incomingIce, function (candidate) {
|
|
187
|
+
pc.addIceCandidate(candidate, function (error) {
|
|
188
|
+
tracer.trace('ICE ADDED AFTER ANSWER');
|
|
189
|
+
if (error) {
|
|
190
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'JOIN_RESPONSE addIceCandidate', error: error });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
_this2._incomingIce.length = 0;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
_this2.emit(_session.EVENTS.CONNECTED);
|
|
199
|
+
|
|
200
|
+
_this2.publish(_this2.publisher).catch(function (error) {
|
|
201
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'publish', error: error });
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, function (_ref3) {
|
|
206
|
+
var candidate = _ref3.candidate,
|
|
207
|
+
peerId = _ref3.peerId;
|
|
208
|
+
|
|
209
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.ICE_CANDIDATE');
|
|
210
|
+
var pc = _this2._pcs[peerId];
|
|
211
|
+
|
|
212
|
+
if (!pc) {
|
|
213
|
+
tracer.trace('NO PEER FOUND ADD TO ICE QUEUE');
|
|
214
|
+
_this2._incomingIce.push(candidate);
|
|
215
|
+
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
pc.addIceCandidate(candidate, function (error) {
|
|
220
|
+
tracer.trace('ICE ADDED AFTER INCOMING');
|
|
221
|
+
if (error) {
|
|
222
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'ICE_CANDIDATE addIceCandidate', error: error });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Received by publisher, causing him to emit SDP_OFFER
|
|
228
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.SEND_OFFER, function (_ref4) {
|
|
229
|
+
var uid = _ref4.uid,
|
|
230
|
+
peerId = _ref4.peerId;
|
|
231
|
+
|
|
232
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.SEND_OFFER');
|
|
233
|
+
|
|
234
|
+
_this2._createRTCPeerConnection(peerId).then(function (pc) {
|
|
235
|
+
tracer.trace('GENERATING OFFER');
|
|
236
|
+
|
|
237
|
+
pc.generateOffer(function (error, offer) {
|
|
238
|
+
tracer.trace('OFFER GENERATED');
|
|
239
|
+
|
|
240
|
+
if (error) {
|
|
241
|
+
return done(error);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
socket.emit(_constants.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
245
|
+
uid: uid,
|
|
246
|
+
peerId: peerId,
|
|
247
|
+
sessionId: _this2._credentials.sessionId,
|
|
248
|
+
sdpOffer: offer
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}).catch(function (error) {
|
|
252
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: '_createRTCPeerConnection', error: error });
|
|
253
|
+
if (error && error.name) {
|
|
254
|
+
_this2.lastError = error.name;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// Received by subscriber, causing him to emit SDP_ANSWER
|
|
260
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.SDP_OFFER, function (_ref5) {
|
|
261
|
+
var sdpOffer = _ref5.sdpOffer,
|
|
262
|
+
peerId = _ref5.peerId,
|
|
263
|
+
uid = _ref5.uid;
|
|
264
|
+
|
|
265
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.SDP_OFFER');
|
|
266
|
+
|
|
267
|
+
Promise.resolve().then(function () {
|
|
268
|
+
var pc = _this2._pcs[peerId];
|
|
269
|
+
|
|
270
|
+
if (pc) {
|
|
271
|
+
tracer.trace('PEER ALREADY EXISTS');
|
|
272
|
+
return pc;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return _this2._createRTCPeerConnection(peerId);
|
|
276
|
+
}).then(function (pc) {
|
|
277
|
+
tracer.trace('PROCESS OFFER');
|
|
278
|
+
pc.processOffer(sdpOffer, function (error, sdpAnswer) {
|
|
279
|
+
tracer.trace('OFFER PROCESSED');
|
|
280
|
+
if (error) {
|
|
281
|
+
return done(error);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
socket.emit(_constants.SOCKET_EVENTS.OUTGOING.SDP_ANSWER, {
|
|
285
|
+
uid: uid,
|
|
286
|
+
peerId: peerId,
|
|
287
|
+
sessionId: _this2._credentials.sessionId,
|
|
288
|
+
sdpAnswer: sdpAnswer
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}).catch(function (error) {
|
|
292
|
+
_this2.emit(_session.EVENTS.EXCEPTION, { source: 'response on INCOMING.SDP_OFFER', error: error });
|
|
293
|
+
if (error && error.name) {
|
|
294
|
+
_this2.lastError = error.name;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// Received by subscriber after a publisher reconnects to room
|
|
300
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, function () {
|
|
301
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT');
|
|
302
|
+
|
|
303
|
+
// Clean up and reconnect with a new peer-connection,
|
|
304
|
+
// to prevent reconnection issues
|
|
305
|
+
|
|
306
|
+
_this2._streams.clear();
|
|
307
|
+
socket.off();
|
|
308
|
+
_.forEach(_this2._pcs, function (_ref6) {
|
|
309
|
+
var peerConnection = _ref6.peerConnection;
|
|
310
|
+
|
|
311
|
+
tracer.trace('CLOSING PEER');
|
|
312
|
+
peerConnection.close();
|
|
313
|
+
});
|
|
314
|
+
_this2._pcs = {};
|
|
315
|
+
|
|
316
|
+
_this2.emit(_session.EVENTS.RECONNECT_TURN_SERVER);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Received by publisher after a subscriber's socket has been disconnected
|
|
320
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED, function () {
|
|
321
|
+
var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
322
|
+
peerId = _ref7.peerId;
|
|
323
|
+
|
|
324
|
+
tracer.trace('SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED');
|
|
325
|
+
|
|
326
|
+
if (peerId && _this2._pcs[peerId]) {
|
|
327
|
+
if (_this2._lastPc === _this2._pcs[peerId]) {
|
|
328
|
+
_this2._lastPc = null;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (Object.getOwnPropertyNames(_this2._pcs).length === 1) {
|
|
332
|
+
_this2._toggleAllStreams(false);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
_this2._pcs[peerId].peerConnection.close();
|
|
336
|
+
|
|
337
|
+
delete _this2._pcs[peerId];
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
_this2._socket = socket;
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
TurnWebRTCSession.prototype._setupConnection = function _setupConnection(pc) {
|
|
346
|
+
var _this3 = this;
|
|
347
|
+
|
|
348
|
+
return new Promise(function (resolve) {
|
|
349
|
+
tracer.trace('_setupConnection');
|
|
350
|
+
pc.peerConnection.oniceconnectionstatechange = function (e) {
|
|
351
|
+
tracer.trace('oniceconnectionstatechange', e);
|
|
352
|
+
|
|
353
|
+
if (_this3.iceCheckingTimeout) {
|
|
354
|
+
clearTimeout(_this3.iceCheckingTimeout);
|
|
355
|
+
_this3.iceCheckingTimeout = null;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (e.target.iceConnectionState === 'failed') {
|
|
359
|
+
// if this is one of many in the publisher, skip
|
|
360
|
+
|
|
361
|
+
// already attempting a reconnect
|
|
362
|
+
if (_this3._turnServerReconnectInterval) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
_this3._turnServerReconnectInterval = setInterval(function () {
|
|
367
|
+
if (!navigator.onLine) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
clearInterval(_this3._turnServerReconnectInterval);
|
|
372
|
+
_this3._turnServerReconnectInterval = null;
|
|
373
|
+
|
|
374
|
+
if (!_this3._socket.connected) {
|
|
375
|
+
_this3.disconnected = false;
|
|
376
|
+
_this3._socket.connect();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
_this3.emit(_session.EVENTS.RECONNECT_TURN_SERVER);
|
|
380
|
+
}, _constants.RECONNECT_TURN_SERVER_INTERVAL);
|
|
381
|
+
} else if (e.target.iceConnectionState === 'checking') {
|
|
382
|
+
_this3.iceCheckingTimeout = setTimeout(function () {
|
|
383
|
+
_this3.emit(_session.EVENTS.TURN_SERVER_CONNECTION_FAILED);
|
|
384
|
+
}, _constants.FAILED_CONNECTING_TURN_SERVER_INTERVAL);
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
pc.peerConnection.onremovestream = function (_ref8) {
|
|
389
|
+
var stream = _ref8.stream;
|
|
390
|
+
|
|
391
|
+
tracer.trace('onremovestream');
|
|
392
|
+
_this3._streams.delete(stream.id);
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
resolve();
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
TurnWebRTCSession.prototype._getPeerType = function _getPeerType(constraints, isMobile) {
|
|
400
|
+
if (isMobile || constraints.audio) {
|
|
401
|
+
return _constants.PEER_CONNECTION_TYPES.SEND_RECV;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return _constants.PEER_CONNECTION_TYPES.RECV_ONLY;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
TurnWebRTCSession.prototype._connectRTCPeer = function _connectRTCPeer(_ref9) {
|
|
408
|
+
var _this4 = this;
|
|
409
|
+
|
|
410
|
+
var constraints = _ref9.constraints,
|
|
411
|
+
configuration = _ref9.configuration,
|
|
412
|
+
sessionId = _ref9.sessionId,
|
|
413
|
+
isMobile = _ref9.isMobile,
|
|
414
|
+
peerId = _ref9.peerId;
|
|
415
|
+
|
|
416
|
+
return new Promise(function (resolve, reject) {
|
|
417
|
+
tracer.trace('_connectRTCPeer');
|
|
418
|
+
|
|
419
|
+
var done = _.once(function (err, pc) {
|
|
420
|
+
tracer.trace(err ? 'Error' : 'Peer Connected', err);
|
|
421
|
+
err ? reject(err) : resolve(pc);
|
|
422
|
+
});
|
|
423
|
+
var setupWebRtcPeer = function setupWebRtcPeer(stream) {
|
|
424
|
+
tracer.trace('setupWebRtcPeer');
|
|
425
|
+
var peerConnectionType = _this4._getPeerType(constraints, isMobile);
|
|
426
|
+
var peerConfig = {
|
|
427
|
+
configuration: configuration,
|
|
428
|
+
videoStream: isMobile ? stream : undefined,
|
|
429
|
+
mediaConstraints: constraints,
|
|
430
|
+
onicecandidate: function onicecandidate(candidate) {
|
|
431
|
+
tracer.trace('onicecandidate', candidate);
|
|
432
|
+
_this4._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
433
|
+
sessionId: sessionId,
|
|
434
|
+
peerId: peerId,
|
|
435
|
+
candidate: candidate,
|
|
436
|
+
clientType: isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
var pc = WebRtcPeer[peerConnectionType](peerConfig, function (error) {
|
|
442
|
+
if (error) {
|
|
443
|
+
return done(error);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
_this4._setupConnection(pc).then(function () {
|
|
447
|
+
return done(null, pc);
|
|
448
|
+
}).catch(done);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
_this4._pcs[peerId] = pc;
|
|
452
|
+
_this4._lastPc = pc;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
_this4._localStreamFactory(constraints).then(function (localStream) {
|
|
456
|
+
setupWebRtcPeer(localStream);
|
|
457
|
+
}).catch(function () {
|
|
458
|
+
setupWebRtcPeer(undefined);
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
TurnWebRTCSession.prototype._setTrackStateTo = function _setTrackStateTo(state) {
|
|
464
|
+
tracer.trace('_setTrackStateTo');
|
|
465
|
+
return function (track) {
|
|
466
|
+
if (track.setEnabled) {
|
|
467
|
+
track.setEnabled(state);
|
|
468
|
+
} else {
|
|
469
|
+
track.enabled = state;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Establish socket and peer connection to the media server.
|
|
476
|
+
*
|
|
477
|
+
* @method
|
|
478
|
+
* @returns { Promise }
|
|
479
|
+
*
|
|
480
|
+
* @fires SESSION_EVENTS#CONNECTED
|
|
481
|
+
*/
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
TurnWebRTCSession.prototype.connect = function connect() {
|
|
485
|
+
var _this5 = this;
|
|
486
|
+
|
|
487
|
+
tracer.trace('connect');
|
|
488
|
+
return this._connectSocket(this._credentials.url).then(function () {
|
|
489
|
+
tracer.trace('Socket connected getting constraints');
|
|
490
|
+
return (0, _helper.getMediaConstraints)({
|
|
491
|
+
resolution: _this5._resolution,
|
|
492
|
+
deviceOpts: _this5._deviceOpts
|
|
493
|
+
});
|
|
494
|
+
}).then(function (constraints) {
|
|
495
|
+
tracer.trace('connect - constraints', constraints);
|
|
496
|
+
|
|
497
|
+
// streaming from dashboard is not supported and we
|
|
498
|
+
// don't want to access the camera without a reason
|
|
499
|
+
if (!_this5._isMobile && constraints.video) {
|
|
500
|
+
tracer.trace('connect - deleting video for non mobile');
|
|
501
|
+
delete constraints.video;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
_this5._constraints = constraints;
|
|
505
|
+
|
|
506
|
+
var clientType = _this5._isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER;
|
|
507
|
+
|
|
508
|
+
tracer.trace('connect - emitting joinRoom', {
|
|
509
|
+
clientType: clientType,
|
|
510
|
+
sessionId: _this5._credentials.sessionId
|
|
511
|
+
});
|
|
512
|
+
_this5._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
|
|
513
|
+
clientType: clientType,
|
|
514
|
+
sessionId: _this5._credentials.sessionId
|
|
515
|
+
});
|
|
516
|
+
}).catch(function (error) {
|
|
517
|
+
tracer.trace('connect error', error);
|
|
518
|
+
_this5.emit(_session.EVENTS.EXCEPTION, { source: 'connect', error: error });
|
|
519
|
+
throw error;
|
|
520
|
+
});
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
TurnWebRTCSession.prototype._createRTCPeerConnection = function _createRTCPeerConnection(peerId) {
|
|
524
|
+
var _this6 = this;
|
|
525
|
+
|
|
526
|
+
tracer.trace('_createRTCPeerConnection');
|
|
527
|
+
return this._connectRTCPeer({
|
|
528
|
+
constraints: this._constraints,
|
|
529
|
+
configuration: this._configuration,
|
|
530
|
+
sessionId: this._credentials.sessionId,
|
|
531
|
+
isMobile: this._isMobile,
|
|
532
|
+
peerId: peerId
|
|
533
|
+
}).then(function (pc) {
|
|
534
|
+
tracer.trace('peer connection created');
|
|
535
|
+
|
|
536
|
+
if (_this6._isMobile) {
|
|
537
|
+
pc.peerConnection.getLocalStreams().forEach(function (stream) {
|
|
538
|
+
if (!_this6.publisher) {
|
|
539
|
+
stream.getTracks().forEach(_this6._setTrackStateTo(false));
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
pc.peerConnection.onaddstream = function (_ref10) {
|
|
545
|
+
var stream = _ref10.stream;
|
|
546
|
+
|
|
547
|
+
tracer.trace('peer connection onaddstream', stream);
|
|
548
|
+
var tsStream = new _stream.TsWebRTCStream(_this6, stream);
|
|
549
|
+
|
|
550
|
+
_this6.emit(_session.EVENTS.STREAM_CREATED, tsStream);
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
return pc;
|
|
554
|
+
});
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
TurnWebRTCSession.prototype._toggleAllStreams = function _toggleAllStreams(state) {
|
|
558
|
+
var _this7 = this;
|
|
559
|
+
|
|
560
|
+
if (this._isMobile) {
|
|
561
|
+
_.forEach(this._pcs, function (pc) {
|
|
562
|
+
pc.peerConnection.getLocalStreams().forEach(function (stream) {
|
|
563
|
+
stream.getTracks().forEach(_this7._setTrackStateTo(state));
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
TurnWebRTCSession.prototype._stopStream = function _stopStream(pc) {
|
|
570
|
+
if (this._isMobile) {
|
|
571
|
+
pc.peerConnection.getLocalStreams().forEach(function (stream) {
|
|
572
|
+
stream.getTracks().forEach(function (track) {
|
|
573
|
+
return track.stop();
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
TurnWebRTCSession.prototype._stopAllStreams = function _stopAllStreams() {
|
|
580
|
+
var _this8 = this;
|
|
581
|
+
|
|
582
|
+
_.forEach(this._pcs, function (pc) {
|
|
583
|
+
return _this8._stopStream(pc);
|
|
584
|
+
});
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Close all media streams, disconnect RTCPeerConnection and socket.io
|
|
589
|
+
*
|
|
590
|
+
* @method
|
|
591
|
+
* @returns { Promise }
|
|
592
|
+
*
|
|
593
|
+
* @fires SESSION_EVENTS#DISCONNECTED
|
|
594
|
+
*/
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
TurnWebRTCSession.prototype.disconnect = function disconnect() {
|
|
598
|
+
var _this9 = this;
|
|
599
|
+
|
|
600
|
+
tracer.trace('disconnect');
|
|
601
|
+
return Promise.resolve().then(function () {
|
|
602
|
+
if (_this9.destroyed) {
|
|
603
|
+
return null;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
_this9._stopAllStreams();
|
|
607
|
+
|
|
608
|
+
_.forEach(_this9._pcs, function (_ref11) {
|
|
609
|
+
var peerConnection = _ref11.peerConnection;
|
|
610
|
+
return peerConnection.close();
|
|
611
|
+
});
|
|
612
|
+
_this9._pcs = {};
|
|
613
|
+
_this9._socket.disconnect();
|
|
614
|
+
|
|
615
|
+
var event = { reason: 'disconnected' };
|
|
616
|
+
|
|
617
|
+
_this9.emit(_session.EVENTS.DISCONNECTED, event);
|
|
618
|
+
|
|
619
|
+
return event;
|
|
620
|
+
});
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
TurnWebRTCSession.prototype._waitForPublishingApproval = function _waitForPublishingApproval(caller, cb) {
|
|
624
|
+
tracer.trace('_waitForPublishingApproval');
|
|
625
|
+
try {
|
|
626
|
+
var pc = _.get(caller, '_lastPc.peerConnection');
|
|
627
|
+
|
|
628
|
+
if (!pc) {
|
|
629
|
+
throw new Error('No peer connection for publishing');
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
//
|
|
633
|
+
// Get media streams that were created on session initialization
|
|
634
|
+
//
|
|
635
|
+
var mediaStream = pc.getLocalStreams()[0];
|
|
636
|
+
|
|
637
|
+
if (mediaStream) {
|
|
638
|
+
return cb(null, mediaStream);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (caller.lastError === 'NotAllowedError') {
|
|
642
|
+
return cb({ code: 1500, name: 'NotAllowedError' });
|
|
643
|
+
} else if (caller.lastError === 'PermissionDismissedError') {
|
|
644
|
+
return cb({ code: 8, name: 'PermissionDismissedError' });
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
setTimeout(caller._waitForPublishingApproval, _constants.PUBLISH_APPROVAL_CHECK_INTERVAL, caller, cb);
|
|
648
|
+
} catch (err) {
|
|
649
|
+
return cb(err);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Create new TsMediaPublisher instance
|
|
655
|
+
*
|
|
656
|
+
* @method
|
|
657
|
+
*
|
|
658
|
+
* @param { DOMElement } [target] Video element
|
|
659
|
+
* that will be used to render publishing video stream
|
|
660
|
+
* @param { Object } params
|
|
661
|
+
* @param { String } [params.videoDevice] Video device id
|
|
662
|
+
* @param { String } [params.videoParams] Video device id
|
|
663
|
+
* @param { String } [params.videoParams.fitMode] Video fit mode
|
|
664
|
+
* @param { Number|String } [params.videoParams.width] Video element width
|
|
665
|
+
* @param { Number|String } [params.videoParams.height] Video element height
|
|
666
|
+
* @param { String } [params.audioDevice] Video device id
|
|
667
|
+
*
|
|
668
|
+
* @returns { Promise<TsMediaPublisher> } publisher
|
|
669
|
+
*
|
|
670
|
+
* @see TsMediaPublisher
|
|
671
|
+
*/
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
TurnWebRTCSession.prototype.createPublisher = function createPublisher(target, params) {
|
|
675
|
+
var _this10 = this;
|
|
676
|
+
|
|
677
|
+
if (!params) {
|
|
678
|
+
params = target;
|
|
679
|
+
target = null;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
tracer.trace('createPublisher');
|
|
683
|
+
|
|
684
|
+
return (this._lastPc ? Promise.resolve() : Promise.delay(_constants.WAIT_FOR_PC_INTERVAL)).then(function () {
|
|
685
|
+
return new Promise(function (resolve, reject) {
|
|
686
|
+
_this10._waitForPublishingApproval(_this10, function (err, mediaStream) {
|
|
687
|
+
if (err) {
|
|
688
|
+
return reject(err);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return resolve(mediaStream);
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
}).then(function (mediaStream) {
|
|
695
|
+
//
|
|
696
|
+
// Get tracks that are related to the publisher (audio or video)
|
|
697
|
+
//
|
|
698
|
+
var tracks = _this10._lastPc.peerConnection.getLocalStreams().reduce(function (result, mediaStream) {
|
|
699
|
+
mediaStream.getTracks().filter(function (track) {
|
|
700
|
+
return track.kind === 'video' && params.videoDevice || track.kind === 'audio' && params.audioDevice;
|
|
701
|
+
}).forEach(function (track) {
|
|
702
|
+
return result.push(track);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
return result;
|
|
706
|
+
}, []);
|
|
707
|
+
|
|
708
|
+
var tsstream = new _stream.TsWebRTCStream(_this10, mediaStream, params.name);
|
|
709
|
+
|
|
710
|
+
tsstream.remote = false;
|
|
711
|
+
|
|
712
|
+
var publisher = new _publisher.TsMediaPublisher(_this10, {
|
|
713
|
+
stream: tsstream,
|
|
714
|
+
tracks: tracks,
|
|
715
|
+
videoParams: params.videoParams,
|
|
716
|
+
|
|
717
|
+
videoHeight: tsstream.videoDimensions.height,
|
|
718
|
+
videoWidth: tsstream.videoDimensions.width,
|
|
719
|
+
|
|
720
|
+
_target: target
|
|
721
|
+
});
|
|
722
|
+
|
|
723
|
+
tsstream.publisher = publisher;
|
|
724
|
+
_this10.publisher = publisher;
|
|
725
|
+
|
|
726
|
+
return publisher;
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Publish stream from previously create TsMediaPublisher instance.
|
|
732
|
+
*
|
|
733
|
+
* Used internally by TsMediaPublisher.publish
|
|
734
|
+
*
|
|
735
|
+
* @method
|
|
736
|
+
*
|
|
737
|
+
* @param { TsMediaPublisher } publisher
|
|
738
|
+
*
|
|
739
|
+
* @returns { Promise }
|
|
740
|
+
*
|
|
741
|
+
* @fires PUBLISHER_EVENTS#STREAM_CREATED
|
|
742
|
+
* @fires SESSION_EVENTS#STREAM_PROPERTY_CHANGED
|
|
743
|
+
* @fires STREAM_EVENTS#PROPERTY_CHANGED
|
|
744
|
+
*
|
|
745
|
+
* @see TsMediaPublisher#publish
|
|
746
|
+
*/
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
TurnWebRTCSession.prototype.publish = function publish(publisher) {
|
|
750
|
+
var _this11 = this;
|
|
751
|
+
|
|
752
|
+
tracer.trace('publish');
|
|
753
|
+
return Promise.resolve().then(function () {
|
|
754
|
+
if (!publisher) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
publisher.emit(_publisher.EVENTS.STREAM_CREATED, publisher.stream);
|
|
759
|
+
_this11.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
|
|
760
|
+
stream: publisher.stream,
|
|
761
|
+
property: 'hasVideo',
|
|
762
|
+
value: publisher.stream.hasVideo
|
|
763
|
+
});
|
|
764
|
+
_this11.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
|
|
765
|
+
stream: publisher.stream,
|
|
766
|
+
property: 'hasAudio',
|
|
767
|
+
value: publisher.stream.hasAudio
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
if (_this11.publisher._element) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
if (publisher._target) {
|
|
775
|
+
//
|
|
776
|
+
// New video element where publishing video stream will be rendered
|
|
777
|
+
//
|
|
778
|
+
var video = document.createElement('video');
|
|
779
|
+
|
|
780
|
+
//Currently this code is used only in mobile, so when publishing, then we always need only video track
|
|
781
|
+
//to set to video element. Otherwise, when VOIP enabled, technician side will hear himself through this video element.
|
|
782
|
+
var videoTracks = publisher.stream._mediaStream.getVideoTracks();
|
|
783
|
+
|
|
784
|
+
if (!isIE11) {
|
|
785
|
+
video.srcObject = new MediaStream(videoTracks);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
video.playsInline = true;
|
|
789
|
+
video.autoplay = true;
|
|
790
|
+
|
|
791
|
+
if (_this11._isMobile) {
|
|
792
|
+
video.muted = true;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
if (isIE11) {
|
|
796
|
+
publisher._target.appendChild(video);
|
|
797
|
+
publisher._element = attachMediaStream(video, publisher.stream._mediaStream);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
var params = _.assign({}, {
|
|
801
|
+
fitMode: 'contain',
|
|
802
|
+
insertMode: 'append',
|
|
803
|
+
mirror: false,
|
|
804
|
+
resolution: '480x640',
|
|
805
|
+
width: '100%',
|
|
806
|
+
height: '100%'
|
|
807
|
+
}, publisher.videoParams);
|
|
808
|
+
|
|
809
|
+
var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
|
|
810
|
+
var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
|
|
811
|
+
|
|
812
|
+
_.assign((isIE11 ? publisher._element : video).style, {
|
|
813
|
+
height: elementHeight,
|
|
814
|
+
width: elementWidth,
|
|
815
|
+
|
|
816
|
+
position: 'relative',
|
|
817
|
+
'object-fit': params.fitMode
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
if (!isIE11) {
|
|
821
|
+
publisher._target.appendChild(video);
|
|
822
|
+
publisher._element = video;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
publisher.stream.setupDimensionsListener(video);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
//
|
|
829
|
+
// Enable (unpause) all media tracks related to publisher.
|
|
830
|
+
// They are sending data to the server from this moment.
|
|
831
|
+
//
|
|
832
|
+
_this11._toggleAllStreams(true);
|
|
833
|
+
});
|
|
834
|
+
};
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Unpublish stream and destroy publisher's view.
|
|
838
|
+
*
|
|
839
|
+
* Used internally by TsMediaPublisher.destroy
|
|
840
|
+
*
|
|
841
|
+
* @method
|
|
842
|
+
*
|
|
843
|
+
* @param { TsMediaPublisher } publisher
|
|
844
|
+
*
|
|
845
|
+
* @returns { Promise }
|
|
846
|
+
*
|
|
847
|
+
* @fires PUBLISHER_EVENTS#DESTROYED
|
|
848
|
+
*
|
|
849
|
+
* @see TsMediaPublisher#destroy
|
|
850
|
+
*/
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
TurnWebRTCSession.prototype.destroyPublisher = function destroyPublisher(publisher) {
|
|
854
|
+
var _this12 = this;
|
|
855
|
+
|
|
856
|
+
tracer.trace('destroyPublisher');
|
|
857
|
+
return new Promise(function (resolve) {
|
|
858
|
+
_this12._toggleAllStreams(false);
|
|
859
|
+
|
|
860
|
+
if (publisher._element) {
|
|
861
|
+
publisher._element.remove();
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
_this12.publisher = null;
|
|
865
|
+
publisher.emit(_publisher.EVENTS.DESTROYED);
|
|
866
|
+
|
|
867
|
+
return resolve();
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
_createClass(TurnWebRTCSession, [{
|
|
872
|
+
key: 'id',
|
|
873
|
+
get: function get() {
|
|
874
|
+
return this._credentials.sessionId;
|
|
875
|
+
}
|
|
876
|
+
}]);
|
|
877
|
+
|
|
878
|
+
return TurnWebRTCSession;
|
|
879
|
+
}(_session.TsMediaSession);
|
|
880
|
+
//# sourceMappingURL=session-turn.js.map
|