@techsee/techsee-media-service 0.21.2 → 0.22.0-alphagb2
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/LocalStreamManager.js +435 -317
- package/lib/LocalStreamManager.js.map +1 -1
- package/lib/MediaConstants.js +72 -44
- package/lib/MediaConstants.js.map +1 -1
- package/lib/MediaContracts.js +3 -3
- package/lib/MediaContracts.js.map +1 -1
- package/lib/MediaPublisher.js +45 -35
- package/lib/MediaPublisher.js.map +1 -1
- package/lib/MediaServiceBase.js +922 -706
- package/lib/MediaServiceBase.js.map +1 -1
- package/lib/MediaSession/MediaServer.js +512 -379
- package/lib/MediaSession/MediaServer.js.map +1 -1
- package/lib/MediaSession/MediaSessionBase.js +123 -88
- package/lib/MediaSession/MediaSessionBase.js.map +1 -1
- package/lib/MediaSession/SessionOpentok.js +499 -384
- package/lib/MediaSession/SessionOpentok.js.map +1 -1
- package/lib/MediaSession/SessionTurn.js +606 -466
- package/lib/MediaSession/SessionTurn.js.map +1 -1
- package/lib/MediaSession/TurnConstants.js +30 -30
- package/lib/MediaSession/TurnConstants.js.map +1 -1
- package/lib/MediaSubscriber.js +235 -192
- package/lib/MediaSubscriber.js.map +1 -1
- package/lib/MediaUtils/Compatibility.js +127 -90
- package/lib/MediaUtils/Compatibility.js.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.js +230 -179
- package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
- package/lib/MediaUtils/MediaTracer.js +8 -4
- package/lib/MediaUtils/MediaTracer.js.map +1 -1
- package/lib/MultiParty/Contracts.js +3 -3
- package/lib/MultiParty/Contracts.js.map +1 -1
- package/lib/MultiParty/DetectWebRtcService.js +66 -50
- package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
- package/lib/MultiParty/MediaCapabilitiesHelper.js +258 -154
- package/lib/MultiParty/MediaCapabilitiesHelper.js.map +1 -1
- package/lib/MultiParty/MultiParty.d.ts +1 -8
- package/lib/MultiParty/MultiParty.d.ts.map +1 -1
- package/lib/MultiParty/MultiParty.js +221 -128
- package/lib/MultiParty/MultiParty.js.map +1 -1
- package/lib/MultiParty/MultipartyFactory.d.ts +1 -2
- package/lib/MultiParty/MultipartyFactory.d.ts.map +1 -1
- package/lib/MultiParty/MultipartyFactory.js +12 -7
- package/lib/MultiParty/MultipartyFactory.js.map +1 -1
- package/lib/MultiParty/OpentokMultiparty.js +611 -384
- package/lib/MultiParty/OpentokMultiparty.js.map +1 -1
- package/lib/TechseeMediaStream.js +58 -53
- package/lib/TechseeMediaStream.js.map +1 -1
- package/lib/oldCode/constants.js +20 -15
- package/lib/oldCode/constants.js.map +1 -1
- package/lib/oldCode/event-emitter.js +45 -22
- package/lib/oldCode/event-emitter.js.map +1 -1
- package/lib/oldCode/index.js +48 -52
- package/lib/oldCode/index.js.map +1 -1
- package/lib/oldCode/opentok/session.js +261 -236
- package/lib/oldCode/opentok/session.js.map +1 -1
- package/lib/oldCode/opentok/stream.js +283 -269
- package/lib/oldCode/opentok/stream.js.map +1 -1
- package/lib/oldCode/publisher.js +96 -71
- package/lib/oldCode/publisher.js.map +1 -1
- package/lib/oldCode/service.js +294 -272
- package/lib/oldCode/service.js.map +1 -1
- package/lib/oldCode/session.js +82 -60
- package/lib/oldCode/session.js.map +1 -1
- package/lib/oldCode/stream.js +153 -125
- package/lib/oldCode/stream.js.map +1 -1
- package/lib/oldCode/subscriber.js +60 -35
- package/lib/oldCode/subscriber.js.map +1 -1
- package/lib/oldCode/tracer.js +179 -138
- package/lib/oldCode/tracer.js.map +1 -1
- package/lib/oldCode/utils/ImageFixer.js +66 -44
- package/lib/oldCode/utils/ImageFixer.js.map +1 -1
- package/lib/oldCode/webrtc/constants.js +102 -110
- package/lib/oldCode/webrtc/constants.js.map +1 -1
- package/lib/oldCode/webrtc/helper.js +176 -124
- package/lib/oldCode/webrtc/helper.js.map +1 -1
- package/lib/oldCode/webrtc/session-kms.js +408 -393
- package/lib/oldCode/webrtc/session-kms.js.map +1 -1
- package/lib/oldCode/webrtc/session-loopback.js +245 -227
- package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
- package/lib/oldCode/webrtc/session-turn.js +705 -658
- package/lib/oldCode/webrtc/session-turn.js.map +1 -1
- package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
- package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
- package/lib/oldCode/webrtc/session.js +12 -6
- package/lib/oldCode/webrtc/session.js.map +1 -1
- package/lib/oldCode/webrtc/stream.js +526 -504
- package/lib/oldCode/webrtc/stream.js.map +1 -1
- package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
- package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
- package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
- package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
- package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
- package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
- package/lib/qos/raw-qos.js +348 -274
- package/lib/qos/raw-qos.js.map +1 -1
- package/lib/webrtc-ie-shim.js +3386 -2985
- package/lib/webrtc-ie-shim.js.map +1 -1
- package/package.json +12 -15
|
@@ -1,502 +1,642 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var __extends =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
return function (d, b) {
|
|
15
|
-
_extendStatics(d, b);
|
|
16
|
-
function __() {
|
|
17
|
-
this.constructor = d;
|
|
18
|
-
}
|
|
19
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
3
|
+
var __extends = void 0 && (void 0).__extends || function () {
|
|
4
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
5
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
6
|
+
__proto__: []
|
|
7
|
+
} instanceof Array && function (d, b) {
|
|
8
|
+
d.__proto__ = b;
|
|
9
|
+
} || function (d, b) {
|
|
10
|
+
for (var p in b) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
12
|
+
}
|
|
20
13
|
};
|
|
14
|
+
|
|
15
|
+
return _extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return function (d, b) {
|
|
19
|
+
_extendStatics(d, b);
|
|
20
|
+
|
|
21
|
+
function __() {
|
|
22
|
+
this.constructor = d;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
26
|
+
};
|
|
21
27
|
}();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
|
|
29
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
Object.defineProperty(o, k2, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return m[k];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
27
37
|
} : function (o, m, k, k2) {
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
30
40
|
});
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
|
|
42
|
+
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
43
|
+
Object.defineProperty(o, "default", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
value: v
|
|
46
|
+
});
|
|
33
47
|
} : function (o, v) {
|
|
34
|
-
|
|
48
|
+
o["default"] = v;
|
|
35
49
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
|
|
51
|
+
var __importStar = void 0 && (void 0).__importStar || function (mod) {
|
|
52
|
+
if (mod && mod.__esModule) return mod;
|
|
53
|
+
var result = {};
|
|
54
|
+
if (mod != null) for (var k in mod) {
|
|
55
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
__setModuleDefault(result, mod);
|
|
59
|
+
|
|
60
|
+
return result;
|
|
43
61
|
};
|
|
44
|
-
|
|
45
|
-
|
|
62
|
+
|
|
63
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
64
|
+
return mod && mod.__esModule ? mod : {
|
|
65
|
+
"default": mod
|
|
66
|
+
};
|
|
46
67
|
};
|
|
47
|
-
|
|
68
|
+
|
|
69
|
+
Object.defineProperty(exports, "__esModule", {
|
|
70
|
+
value: true
|
|
71
|
+
});
|
|
48
72
|
exports.TurnWebRtcSession = void 0;
|
|
73
|
+
|
|
49
74
|
var io = __importStar(require("socket.io-client"));
|
|
75
|
+
|
|
50
76
|
var once_1 = __importDefault(require("lodash/once"));
|
|
77
|
+
|
|
51
78
|
var MediaConstants_1 = require("../MediaConstants");
|
|
79
|
+
|
|
52
80
|
var TurnConstants_1 = require("./TurnConstants");
|
|
81
|
+
|
|
53
82
|
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
83
|
+
|
|
54
84
|
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
55
|
-
|
|
56
|
-
//Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_this._joinResponseHandler = _this._joinResponseHandler.bind(_this);
|
|
76
|
-
_this._iceCandidateReceivedHandler = _this._iceCandidateReceivedHandler.bind(_this);
|
|
77
|
-
_this._sendOfferHandler = _this._sendOfferHandler.bind(_this);
|
|
78
|
-
_this._sdpOfferHandler = _this._sdpOfferHandler.bind(_this);
|
|
79
|
-
_this._initiatorPeerReconnectHandler = _this._initiatorPeerReconnectHandler.bind(_this);
|
|
80
|
-
_this._peerDisconnectedHandler = _this._peerDisconnectedHandler.bind(_this);
|
|
81
|
-
_this._onSocketDisconnectedHandler = _this._onSocketDisconnectedHandler.bind(_this);
|
|
82
|
-
return _this;
|
|
83
|
-
}
|
|
84
|
-
Object.defineProperty(TurnWebRtcSession.prototype, "id", {
|
|
85
|
-
get: function get() {
|
|
86
|
-
return this._sessionParams.sessionId;
|
|
87
|
-
},
|
|
88
|
-
enumerable: false,
|
|
89
|
-
configurable: true
|
|
85
|
+
|
|
86
|
+
var trace = MediaTracer_1.getMediaTracer('TurnWebRtcSession'); //Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
87
|
+
|
|
88
|
+
var TurnWebRtcSession =
|
|
89
|
+
/** @class */
|
|
90
|
+
function (_super) {
|
|
91
|
+
__extends(TurnWebRtcSession, _super);
|
|
92
|
+
|
|
93
|
+
function TurnWebRtcSession(sessionParams, sessionHandlers, streamFactory) {
|
|
94
|
+
var _this = _super.call(this, sessionParams, streamFactory) || this;
|
|
95
|
+
|
|
96
|
+
_this._sessionHandlers = sessionHandlers;
|
|
97
|
+
_this._socket = null;
|
|
98
|
+
_this._pendingPeersIce = {};
|
|
99
|
+
var iceServers = sessionParams.credentials.ice.map(function (item) {
|
|
100
|
+
return {
|
|
101
|
+
urls: item.url,
|
|
102
|
+
username: item.login,
|
|
103
|
+
credential: item.password
|
|
104
|
+
};
|
|
90
105
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (connectOnly === void 0) {
|
|
95
|
-
connectOnly = false;
|
|
96
|
-
}
|
|
97
|
-
trace.info('Connect to session');
|
|
98
|
-
return this._connectSocket(this._sessionParams.credentials.url, connectOnly).then(function () {
|
|
99
|
-
trace.info('Joining SessionId: ' + _this._sessionParams.sessionId);
|
|
100
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
|
|
101
|
-
clientType: _this._sessionParams.clientType,
|
|
102
|
-
sessionId: _this._sessionParams.sessionId
|
|
103
|
-
});
|
|
104
|
-
}).catch(function (error) {
|
|
105
|
-
throw error;
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
TurnWebRtcSession.prototype.disconnect = function () {
|
|
109
|
-
trace.info('disconnect - call disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
110
|
-
return this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
111
|
-
};
|
|
112
|
-
TurnWebRtcSession.prototype._connectSocket = function (url, connectOnly) {
|
|
113
|
-
var _this = this;
|
|
114
|
-
return new Promise(function (resolve, reject) {
|
|
115
|
-
var socket = _this._socket = io.connect(url, {
|
|
116
|
-
'forceNew': true,
|
|
117
|
-
'reconnectionDelay': TurnConstants_1.SOCKET_RECONNECTION_DELAY,
|
|
118
|
-
'reconnectionDelayMax': TurnConstants_1.SOCKET_RECONNECTION_DELAY_MAX,
|
|
119
|
-
'reconnectionAttempts': TurnConstants_1.SOCKET_RECONNECTION_ATTEMPTS,
|
|
120
|
-
'path': TurnConstants_1.SOCKET_PATH
|
|
121
|
-
});
|
|
122
|
-
var done = once_1.default(function (err) {
|
|
123
|
-
err ? reject(err) : resolve();
|
|
124
|
-
});
|
|
125
|
-
socket.once('connect', function () {
|
|
126
|
-
return done();
|
|
127
|
-
});
|
|
128
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
129
|
-
socket.on('connect_error', done);
|
|
130
|
-
socket.on('connect_timeout', done);
|
|
131
|
-
socket.on('disconnect', _this._onSocketDisconnectedHandler);
|
|
132
|
-
if (!connectOnly) {
|
|
133
|
-
trace.info('Subscribing socket events');
|
|
134
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SEND_OFFER, _this._sendOfferHandler);
|
|
135
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, _this._joinResponseHandler);
|
|
136
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED, _this._peerDisconnectedHandler);
|
|
137
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SDP_OFFER, _this._sdpOfferHandler);
|
|
138
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, _this._initiatorPeerReconnectHandler);
|
|
139
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, _this._iceCandidateReceivedHandler);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
TurnWebRtcSession.prototype._onSocketDisconnectedHandler = function (reason) {
|
|
144
|
-
if (this._socket) {
|
|
145
|
-
// The initial example of differentiating between "forced" disconnect and "network" disconnect is taken from:
|
|
146
|
-
// https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
|
|
147
|
-
if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
|
|
148
|
-
trace.info('_onSocketDisconnectedHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect);
|
|
149
|
-
// the disconnection was initiated by the server or by client, you need to call (connect) manually
|
|
150
|
-
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect).catch(function () {
|
|
151
|
-
return undefined;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
TurnWebRtcSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
157
|
-
var promises = [];
|
|
158
|
-
if (mediaStream && this._peerConnections) {
|
|
159
|
-
trace.info('replaceStreamTracks - Replace local tracks to peer connection');
|
|
160
|
-
this._peerConnections.forEach(function (peerConnection) {
|
|
161
|
-
mediaStream.getTracks().forEach(function (track) {
|
|
162
|
-
var sender = peerConnection.getSenders().find(function (s) {
|
|
163
|
-
return s.track.kind === track.kind;
|
|
164
|
-
});
|
|
165
|
-
if (sender) {
|
|
166
|
-
promises.push(sender.replaceTrack(track).then(function () {
|
|
167
|
-
return trace.info("replaceStreamTracks - Local " + track.kind + " " + track.id + " track replace to peer connection");
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return Promise.all(promises).then(function () {
|
|
174
|
-
window.mediaStreamAlreadyReplaced = true;
|
|
175
|
-
trace.info('replaceStreamTracks: replace stream tracks - Success');
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region WebRTC Initiator - session Initiator (User on mobile device)
|
|
180
|
-
// Received by Initiator, causing him to emit SDP_OFFER
|
|
181
|
-
TurnWebRtcSession.prototype._sendOfferHandler = function (sendOfferEventData) {
|
|
182
|
-
var _this = this;
|
|
183
|
-
var uid = sendOfferEventData.uid,
|
|
184
|
-
peerId = sendOfferEventData.peerId;
|
|
185
|
-
trace.info('_sendOfferHandler');
|
|
186
|
-
//Currently we not support of passing role through signaling, so we assume every connection is "AGENT" like
|
|
187
|
-
var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.GUEST, MediaConstants_1.SessionClientRole.AGENT);
|
|
188
|
-
var offerParams = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
189
|
-
//TODO - Alex: Currently we not sending "role" through signaling, and by default we assume that the one who asks fot offer, is agent.
|
|
190
|
-
//On later stages we can send or the client "role" or the list of "streams" that peer is interested in.
|
|
191
|
-
this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.AGENT).then(function (mediaStream) {
|
|
192
|
-
trace.info('_sendOfferHandler stream and peer created');
|
|
193
|
-
if (mediaStream) {
|
|
194
|
-
trace.info('Adding local tracks to peer connection for sending offer');
|
|
195
|
-
mediaStream.getTracks().forEach(function (track) {
|
|
196
|
-
peerConnection.addTrack(track, mediaStream);
|
|
197
|
-
trace.info("Local " + track.kind + " " + track.id + " track added to peer connection");
|
|
198
|
-
});
|
|
199
|
-
} else {
|
|
200
|
-
trace.info('No media stream was found for publishing');
|
|
201
|
-
}
|
|
202
|
-
}).then(function () {
|
|
203
|
-
return peerConnection.createOffer(offerParams);
|
|
204
|
-
}).then(function (offerDesc) {
|
|
205
|
-
trace.info('Initiator has created sdp offer', { offerDesc: offerDesc });
|
|
206
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
207
|
-
uid: uid,
|
|
208
|
-
peerId: peerId,
|
|
209
|
-
sessionId: _this._sessionParams.sessionId,
|
|
210
|
-
sdpOffer: offerDesc.sdp
|
|
211
|
-
});
|
|
212
|
-
return peerConnection.setLocalDescription(offerDesc).then(function () {
|
|
213
|
-
trace.info('Local description was set on peerConnection', peerConnection);
|
|
214
|
-
_this._setPeerConnectionMonitor(peerConnection);
|
|
215
|
-
// make sure using the tracks of the last stream that used
|
|
216
|
-
if (window.latestUserMediaStream && window.mediaStreamAlreadyReplaced) {
|
|
217
|
-
_this.replaceStreamTracks(window.latestUserMediaStream.mediaStream).catch(function (e) {
|
|
218
|
-
return trace.warn('_sendOfferHandler - Failed to replaceStreamTrace', e);
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}).catch(function (e) {
|
|
223
|
-
trace.warn('Error', e);
|
|
224
|
-
});
|
|
106
|
+
_this._configuration = {
|
|
107
|
+
iceServers: iceServers,
|
|
108
|
+
iceTransportPolicy: 'relay'
|
|
225
109
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
110
|
+
_this._joinResponseHandler = _this._joinResponseHandler.bind(_this);
|
|
111
|
+
_this._iceCandidateReceivedHandler = _this._iceCandidateReceivedHandler.bind(_this);
|
|
112
|
+
_this._sendOfferHandler = _this._sendOfferHandler.bind(_this);
|
|
113
|
+
_this._sdpOfferHandler = _this._sdpOfferHandler.bind(_this);
|
|
114
|
+
_this._initiatorPeerReconnectHandler = _this._initiatorPeerReconnectHandler.bind(_this);
|
|
115
|
+
_this._peerDisconnectedHandler = _this._peerDisconnectedHandler.bind(_this);
|
|
116
|
+
_this._onSocketDisconnectedHandler = _this._onSocketDisconnectedHandler.bind(_this);
|
|
117
|
+
return _this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
Object.defineProperty(TurnWebRtcSession.prototype, "id", {
|
|
121
|
+
get: function get() {
|
|
122
|
+
return this._sessionParams.sessionId;
|
|
123
|
+
},
|
|
124
|
+
enumerable: false,
|
|
125
|
+
configurable: true
|
|
126
|
+
}); //#region Socket Connectivity
|
|
127
|
+
|
|
128
|
+
TurnWebRtcSession.prototype.connect = function (connectOnly) {
|
|
129
|
+
var _this = this;
|
|
130
|
+
|
|
131
|
+
if (connectOnly === void 0) {
|
|
132
|
+
connectOnly = false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
trace.info('Connect to session');
|
|
136
|
+
return this._connectSocket(this._sessionParams.credentials.url, connectOnly).then(function () {
|
|
137
|
+
trace.info('Joining SessionId: ' + _this._sessionParams.sessionId);
|
|
138
|
+
|
|
139
|
+
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
|
|
140
|
+
clientType: _this._sessionParams.clientType,
|
|
141
|
+
sessionId: _this._sessionParams.sessionId
|
|
142
|
+
});
|
|
143
|
+
})["catch"](function (error) {
|
|
144
|
+
throw error;
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
TurnWebRtcSession.prototype.disconnect = function () {
|
|
149
|
+
trace.info('disconnect - call disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
150
|
+
return this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
TurnWebRtcSession.prototype._connectSocket = function (url, connectOnly) {
|
|
154
|
+
var _this = this;
|
|
155
|
+
|
|
156
|
+
return new Promise(function (resolve, reject) {
|
|
157
|
+
var socket = _this._socket = io.connect(url, {
|
|
158
|
+
'forceNew': true,
|
|
159
|
+
'reconnectionDelay': TurnConstants_1.SOCKET_RECONNECTION_DELAY,
|
|
160
|
+
'reconnectionDelayMax': TurnConstants_1.SOCKET_RECONNECTION_DELAY_MAX,
|
|
161
|
+
'reconnectionAttempts': TurnConstants_1.SOCKET_RECONNECTION_ATTEMPTS,
|
|
162
|
+
'path': TurnConstants_1.SOCKET_PATH
|
|
163
|
+
});
|
|
164
|
+
var done = once_1["default"](function (err) {
|
|
165
|
+
err ? reject(err) : resolve();
|
|
166
|
+
});
|
|
167
|
+
socket.once('connect', function () {
|
|
168
|
+
return done();
|
|
169
|
+
});
|
|
170
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
171
|
+
socket.on('connect_error', done);
|
|
172
|
+
socket.on('connect_timeout', done);
|
|
173
|
+
socket.on('disconnect', _this._onSocketDisconnectedHandler);
|
|
174
|
+
|
|
175
|
+
if (!connectOnly) {
|
|
176
|
+
trace.info('Subscribing socket events');
|
|
177
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SEND_OFFER, _this._sendOfferHandler);
|
|
178
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, _this._joinResponseHandler);
|
|
179
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED, _this._peerDisconnectedHandler);
|
|
180
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SDP_OFFER, _this._sdpOfferHandler);
|
|
181
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, _this._initiatorPeerReconnectHandler);
|
|
182
|
+
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, _this._iceCandidateReceivedHandler);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
TurnWebRtcSession.prototype._onSocketDisconnectedHandler = function (reason) {
|
|
188
|
+
if (this._socket) {
|
|
189
|
+
// The initial example of differentiating between "forced" disconnect and "network" disconnect is taken from:
|
|
190
|
+
// https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
|
|
191
|
+
if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
|
|
192
|
+
trace.info('_onSocketDisconnectedHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect); // the disconnection was initiated by the server or by client, you need to call (connect) manually
|
|
193
|
+
|
|
194
|
+
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect)["catch"](function () {
|
|
195
|
+
return undefined;
|
|
298
196
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
TurnWebRtcSession.prototype.replaceStreamTracks = function (mediaStream) {
|
|
202
|
+
var promises = [];
|
|
203
|
+
|
|
204
|
+
if (mediaStream && this._peerConnections) {
|
|
205
|
+
trace.info('replaceStreamTracks - Replace local tracks to peer connection');
|
|
206
|
+
|
|
207
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
208
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
209
|
+
var sender = peerConnection.getSenders().find(function (s) {
|
|
210
|
+
return s.track.kind === track.kind;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (sender) {
|
|
214
|
+
promises.push(sender.replaceTrack(track).then(function () {
|
|
215
|
+
return trace.info("replaceStreamTracks - Local " + track.kind + " " + track.id + " track replace to peer connection");
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
305
218
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return Promise.all(promises).then(function () {
|
|
223
|
+
window.mediaStreamAlreadyReplaced = true;
|
|
224
|
+
trace.info('replaceStreamTracks: replace stream tracks - Success');
|
|
225
|
+
});
|
|
226
|
+
}; //#endregion
|
|
227
|
+
//#region WebRTC Initiator - session Initiator (User on mobile device)
|
|
228
|
+
// Received by Initiator, causing him to emit SDP_OFFER
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
TurnWebRtcSession.prototype._sendOfferHandler = function (sendOfferEventData) {
|
|
232
|
+
var _this = this;
|
|
233
|
+
|
|
234
|
+
var uid = sendOfferEventData.uid,
|
|
235
|
+
peerId = sendOfferEventData.peerId;
|
|
236
|
+
trace.info('_sendOfferHandler'); //Currently we not support of passing role through signaling, so we assume every connection is "AGENT" like
|
|
237
|
+
|
|
238
|
+
var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.GUEST, MediaConstants_1.SessionClientRole.AGENT);
|
|
239
|
+
|
|
240
|
+
var offerParams = {
|
|
241
|
+
offerToReceiveAudio: true,
|
|
242
|
+
offerToReceiveVideo: true
|
|
243
|
+
}; //TODO - Alex: Currently we not sending "role" through signaling, and by default we assume that the one who asks fot offer, is agent.
|
|
244
|
+
//On later stages we can send or the client "role" or the list of "streams" that peer is interested in.
|
|
245
|
+
|
|
246
|
+
this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.AGENT).then(function (mediaStream) {
|
|
247
|
+
trace.info('_sendOfferHandler stream and peer created');
|
|
248
|
+
|
|
249
|
+
if (mediaStream) {
|
|
250
|
+
trace.info('Adding local tracks to peer connection for sending offer');
|
|
251
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
252
|
+
peerConnection.addTrack(track, mediaStream);
|
|
253
|
+
trace.info("Local " + track.kind + " " + track.id + " track added to peer connection");
|
|
318
254
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
255
|
+
} else {
|
|
256
|
+
trace.info('No media stream was found for publishing');
|
|
257
|
+
}
|
|
258
|
+
}).then(function () {
|
|
259
|
+
return peerConnection.createOffer(offerParams);
|
|
260
|
+
}).then(function (offerDesc) {
|
|
261
|
+
trace.info('Initiator has created sdp offer', {
|
|
262
|
+
offerDesc: offerDesc
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
266
|
+
uid: uid,
|
|
267
|
+
peerId: peerId,
|
|
268
|
+
sessionId: _this._sessionParams.sessionId,
|
|
269
|
+
sdpOffer: offerDesc.sdp
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
return peerConnection.setLocalDescription(offerDesc).then(function () {
|
|
273
|
+
trace.info('Local description was set on peerConnection', peerConnection);
|
|
274
|
+
|
|
275
|
+
_this._setPeerConnectionMonitor(peerConnection); // make sure using the tracks of the last stream that used
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
if (window.latestUserMediaStream && window.mediaStreamAlreadyReplaced) {
|
|
279
|
+
_this.replaceStreamTracks(window.latestUserMediaStream.mediaStream)["catch"](function (e) {
|
|
280
|
+
return trace.warn('_sendOfferHandler - Failed to replaceStreamTrace', e);
|
|
281
|
+
});
|
|
329
282
|
}
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
283
|
+
});
|
|
284
|
+
})["catch"](function (e) {
|
|
285
|
+
trace.warn('Error', e);
|
|
286
|
+
});
|
|
287
|
+
}; // Received by the Initiator: Indicates that publish should be started
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
TurnWebRtcSession.prototype._joinResponseHandler = function (joinResponseData) {
|
|
291
|
+
var _this = this;
|
|
292
|
+
|
|
293
|
+
var sdpAnswer = joinResponseData.sdpAnswer,
|
|
294
|
+
uid = joinResponseData.uid,
|
|
295
|
+
peerId = joinResponseData.peerId;
|
|
296
|
+
trace.info('joinResponse Received', {
|
|
297
|
+
sdpAnswer: sdpAnswer
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
this._withPeerConnection(peerId, function (peerConnection) {
|
|
301
|
+
var answer = new RTCSessionDescription({
|
|
302
|
+
type: 'answer',
|
|
303
|
+
sdp: sdpAnswer
|
|
304
|
+
});
|
|
305
|
+
peerConnection.setRemoteDescription(answer).then(function () {
|
|
306
|
+
trace.info('Remote description was set', answer);
|
|
307
|
+
|
|
308
|
+
_this._processQueuedIceCandidates(peerId);
|
|
309
|
+
})["catch"](function (e) {
|
|
310
|
+
trace.warn('Error', e);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}; // Received by Initiator after a guests socket has been disconnected
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
TurnWebRtcSession.prototype._peerDisconnectedHandler = function (peerDisconnectedEvent) {
|
|
317
|
+
var _this = this;
|
|
318
|
+
|
|
319
|
+
var peerId = peerDisconnectedEvent.peerId;
|
|
320
|
+
trace.info('_peerDisconnectedHandler');
|
|
321
|
+
|
|
322
|
+
this._withPeerConnection(peerId, function (peerConnection) {
|
|
323
|
+
_this._destroyPeerConnection(peerConnection); //this._disconnectInternal(MediaSessionDisconnectReason.PeerDisconnected).catch(() => undefined);
|
|
324
|
+
|
|
325
|
+
});
|
|
326
|
+
}; //#endregion WebRTC Initiator - session Initiator (User on mobile device)
|
|
327
|
+
//#region WebRTC Guest - session Guest (Agent on dashboard platform)
|
|
328
|
+
// Received by Guest, causing him to emit SDP_ANSWER
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
TurnWebRtcSession.prototype._sdpOfferHandler = function (sdpOfferEvent) {
|
|
332
|
+
var _this = this;
|
|
333
|
+
|
|
334
|
+
var sdpOffer = sdpOfferEvent.sdpOffer,
|
|
335
|
+
peerId = sdpOfferEvent.peerId,
|
|
336
|
+
uid = sdpOfferEvent.uid;
|
|
337
|
+
trace.info('sdpOffer Received', {
|
|
338
|
+
sdpOffer: sdpOffer
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.INITIATOR, MediaConstants_1.SessionClientRole.USER);
|
|
342
|
+
|
|
343
|
+
this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.USER).then(function (mediaStream) {
|
|
344
|
+
if (mediaStream) {
|
|
345
|
+
trace.info('Adding local tracks to peer connection offer handler');
|
|
346
|
+
mediaStream.getTracks().forEach(function (track) {
|
|
347
|
+
peerConnection.addTrack(track, mediaStream);
|
|
348
|
+
trace.info("Local " + track.kind + " track added to peer connection");
|
|
337
349
|
});
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
366
|
-
if (['closed', 'disconnected', 'failed'].indexOf(cnState) > -1) {
|
|
367
|
-
_this._iceStateDisconnected(peerConnection);
|
|
368
|
-
} else if (cnState === 'connected') {
|
|
369
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
peerConnection.onicecandidate = function (event) {
|
|
373
|
-
if (event.candidate) {
|
|
374
|
-
trace.info(_this._sessionParams.clientType + " peerConn.onicecandidate", event.candidate);
|
|
375
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
376
|
-
sessionId: _this._sessionParams.sessionId,
|
|
377
|
-
peerId: peerId,
|
|
378
|
-
candidate: event.candidate,
|
|
379
|
-
clientType: _this._sessionParams.clientType
|
|
380
|
-
});
|
|
381
|
-
} else {
|
|
382
|
-
trace.info('ICE Candidate is null in peerConnection', event);
|
|
383
|
-
}
|
|
384
|
-
};
|
|
385
|
-
peerConnection.ontrack = function (trackEvent) {
|
|
386
|
-
var track = trackEvent.track;
|
|
387
|
-
trace.info("MediaStreamTrack arrived from peerConnection: " + track.kind, track);
|
|
388
|
-
_this.addRemoteTrackToPeer(peerConnection, track);
|
|
389
|
-
if (peerConnection.connectionState === 'connected') {
|
|
390
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
this._peerConnections.set(peerId, peerConnection);
|
|
394
|
-
trace.info(peerConnectionType + " peerConnection created");
|
|
395
|
-
return peerConnection;
|
|
396
|
-
};
|
|
397
|
-
TurnWebRtcSession.prototype._setPeerConnectionMonitor = function (peerConnection) {
|
|
398
|
-
var _this = this;
|
|
399
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
400
|
-
peerConnection.connectionTimoutPrt = setTimeout(function () {
|
|
401
|
-
trace.info('PeerConnection ICE state timeout', peerConnection);
|
|
402
|
-
_this._handlePeerConnectionTimeout(peerConnection);
|
|
403
|
-
}, this._sessionParams.peerConnectivityTimeoutSeconds * 1000);
|
|
404
|
-
};
|
|
405
|
-
TurnWebRtcSession.prototype._handlePeerConnectionTimeout = function (peerConnection) {
|
|
406
|
-
trace.info('_handlePeerConnectionTimeout disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout);
|
|
407
|
-
if (peerConnection.peerRole === MediaConstants_1.SessionClientRole.USER) {
|
|
408
|
-
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout).catch(function () {
|
|
409
|
-
return undefined;
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
TurnWebRtcSession.prototype._destroyPeerConnection = function (peerConnection) {
|
|
414
|
-
trace.info('Destroying PeerConnection', peerConnection.peerType);
|
|
415
|
-
peerConnection.ontrack = null;
|
|
416
|
-
peerConnection.onicecandidate = null;
|
|
417
|
-
peerConnection.onconnectionstatechange = null;
|
|
418
|
-
peerConnection.oniceconnectionstatechange = null;
|
|
419
|
-
peerConnection.onicegatheringstatechange = null;
|
|
420
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
421
|
-
this.unregisterPeersRemoteMediaTracks(peerConnection).catch(function () {
|
|
422
|
-
return undefined;
|
|
350
|
+
} else {
|
|
351
|
+
trace.info('No media stream was found for publishing');
|
|
352
|
+
}
|
|
353
|
+
}).then(function () {
|
|
354
|
+
var remoteDesc = new RTCSessionDescription({
|
|
355
|
+
type: 'offer',
|
|
356
|
+
sdp: sdpOffer
|
|
357
|
+
});
|
|
358
|
+
return peerConnection.setRemoteDescription(remoteDesc).then(function () {
|
|
359
|
+
trace.info('Remote description was set', remoteDesc);
|
|
360
|
+
return peerConnection.createAnswer().then(function (sdpAnswer) {
|
|
361
|
+
trace.info('_sdpOfferHandler answer created', sdpAnswer);
|
|
362
|
+
|
|
363
|
+
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.SDP_ANSWER, {
|
|
364
|
+
uid: uid,
|
|
365
|
+
peerId: peerId,
|
|
366
|
+
sessionId: _this._sessionParams.sessionId,
|
|
367
|
+
sdpAnswer: sdpAnswer.sdp
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
return peerConnection.setLocalDescription(sdpAnswer).then(function () {
|
|
371
|
+
trace.info('_sdpOfferHandler local desc was set');
|
|
372
|
+
|
|
373
|
+
_this._processQueuedIceCandidates(peerId);
|
|
374
|
+
|
|
375
|
+
_this._setPeerConnectionMonitor(peerConnection);
|
|
376
|
+
});
|
|
423
377
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
378
|
+
});
|
|
379
|
+
})["catch"](function (e) {
|
|
380
|
+
trace.error('Error in _sdpOfferHandler', e);
|
|
381
|
+
throw e;
|
|
382
|
+
});
|
|
383
|
+
}; // Received by Guest after an Initiator reconnects to room
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
TurnWebRtcSession.prototype._initiatorPeerReconnectHandler = function () {
|
|
387
|
+
trace.info('_initiatorPeerReconnectHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.InitiatorPeerReconnected);
|
|
388
|
+
|
|
389
|
+
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.InitiatorPeerReconnected)["catch"](function (error) {
|
|
390
|
+
trace.warn('Error while disconnecting during userPeerReconnectHandler.', error);
|
|
391
|
+
});
|
|
392
|
+
}; //#endregion WebRTC Guest - session Guest (Agent on dashboard platform)
|
|
393
|
+
//#region Peer Connection
|
|
394
|
+
//#region Streams Handling
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
TurnWebRtcSession.prototype.onMediaStreamDestroyed = function (clientRole) {
|
|
398
|
+
var _this = this; //TODO - Alex: need to implement adding new tracks to peer connection and forcing negotiation
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
trace.info('onMediaStreamDestroyed disconnect all peer connections from session', MediaConstants_1.MediaSessionDisconnectReason.PublishedStreamDestroyed);
|
|
402
|
+
|
|
403
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
404
|
+
_this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PublishedStreamDestroyed)["catch"](function () {
|
|
431
405
|
return undefined;
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
return Promise.resolve();
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
TurnWebRtcSession.prototype.onMediaStreamRenewed = function (clientRole, mediaStream) {
|
|
413
|
+
//TODO - Alex: need to implement adding new tracks to peer connection and forcing negotiation
|
|
414
|
+
return Promise.resolve();
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
TurnWebRtcSession.prototype.getRemoteTrackStats = function (mediaTrack) {
|
|
418
|
+
var peerConnectionOfTrack = this.getPeerConnectionByMediaTrack(mediaTrack);
|
|
419
|
+
|
|
420
|
+
if (peerConnectionOfTrack !== null) {
|
|
421
|
+
return peerConnectionOfTrack.getStats(mediaTrack);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return Promise.reject(new Error('Provided track is not remote track'));
|
|
425
|
+
}; //#endregion
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
TurnWebRtcSession.prototype._disconnectInternal = function (reason) {
|
|
429
|
+
var _this = this;
|
|
430
|
+
|
|
431
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
432
|
+
_this._destroyPeerConnection(peerConnection);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
if (this._socket) {
|
|
436
|
+
trace.info('Disconnecting from session', reason);
|
|
437
|
+
this.sessionDisconnect();
|
|
438
|
+
this._socket = null;
|
|
439
|
+
setTimeout(function () {
|
|
440
|
+
return _this._sessionHandlers.onDisconnectedHandler(reason);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return Promise.resolve();
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
TurnWebRtcSession.prototype._createPeerConnection = function (peerId, peerConnectionType, peerConnectionRole) {
|
|
448
|
+
var _this = this;
|
|
449
|
+
|
|
450
|
+
if (this._peerConnections.get(peerId)) {
|
|
451
|
+
throw new Error(this._sessionParams.clientType + " peer connection for " + peerId + " already exists");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
var peerConnection = new RTCPeerConnection(this._configuration);
|
|
455
|
+
peerConnection.peerId = peerId;
|
|
456
|
+
peerConnection.peerType = peerConnectionType;
|
|
457
|
+
peerConnection.remoteMediaTracks = [];
|
|
458
|
+
peerConnection.peerRole = peerConnectionRole;
|
|
459
|
+
peerConnection.connectionTimoutPrt = null;
|
|
460
|
+
|
|
461
|
+
peerConnection.onconnectionstatechange = function () {
|
|
462
|
+
trace.info('onconnectionstatechange', peerConnection);
|
|
432
463
|
};
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if (!peerConnection || !peerConnection.remoteDescription) {
|
|
445
|
-
trace.info('Queueing iceCandidate', candidate);
|
|
446
|
-
this._queueIceCandidate(candidate, peerId);
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
trace.info('Going to add iceCandidate', candidate);
|
|
450
|
-
this._addIceCandidateToPeer(candidate, peerConnection).catch(function () {
|
|
451
|
-
return undefined;
|
|
452
|
-
});
|
|
453
|
-
};
|
|
454
|
-
TurnWebRtcSession.prototype._addIceCandidateToPeer = function (iceCandidate, peerConnection) {
|
|
455
|
-
return peerConnection.addIceCandidate(iceCandidate).then(function () {
|
|
456
|
-
trace.info('ICE Candidate add to peer connection');
|
|
457
|
-
}).catch(function (e) {
|
|
458
|
-
trace.warn('Error adding ICE Candidate to peer connection', e);
|
|
459
|
-
throw e;
|
|
460
|
-
});
|
|
464
|
+
|
|
465
|
+
peerConnection.oniceconnectionstatechange = function (state) {
|
|
466
|
+
trace.info("ICE Connection state for peer " + peerId + " was changed to: " + state.currentTarget.iceConnectionState, state);
|
|
467
|
+
var cnState = state.currentTarget.iceConnectionState;
|
|
468
|
+
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
469
|
+
|
|
470
|
+
if (['closed', 'disconnected', 'failed'].indexOf(cnState) > -1) {
|
|
471
|
+
_this._iceStateDisconnected(peerConnection);
|
|
472
|
+
} else if (cnState === 'connected') {
|
|
473
|
+
_this.registerPeersRemoteTracks(peerConnection);
|
|
474
|
+
}
|
|
461
475
|
};
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
});
|
|
473
|
-
} else {
|
|
474
|
-
trace.info('No pending ICE found for peer', peerId);
|
|
475
|
-
}
|
|
476
|
+
|
|
477
|
+
peerConnection.onicecandidate = function (event) {
|
|
478
|
+
if (event.candidate) {
|
|
479
|
+
trace.info(_this._sessionParams.clientType + " peerConn.onicecandidate", event.candidate);
|
|
480
|
+
|
|
481
|
+
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
482
|
+
sessionId: _this._sessionParams.sessionId,
|
|
483
|
+
peerId: peerId,
|
|
484
|
+
candidate: event.candidate,
|
|
485
|
+
clientType: _this._sessionParams.clientType
|
|
476
486
|
});
|
|
487
|
+
} else {
|
|
488
|
+
trace.info('ICE Candidate is null in peerConnection', event);
|
|
489
|
+
}
|
|
477
490
|
};
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
491
|
+
|
|
492
|
+
peerConnection.ontrack = function (trackEvent) {
|
|
493
|
+
var track = trackEvent.track;
|
|
494
|
+
trace.info("MediaStreamTrack arrived from peerConnection: " + track.kind, track);
|
|
495
|
+
|
|
496
|
+
_this.addRemoteTrackToPeer(peerConnection, track);
|
|
497
|
+
|
|
498
|
+
if (peerConnection.connectionState === 'connected') {
|
|
499
|
+
_this.registerPeersRemoteTracks(peerConnection);
|
|
500
|
+
}
|
|
483
501
|
};
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
502
|
+
|
|
503
|
+
this._peerConnections.set(peerId, peerConnection);
|
|
504
|
+
|
|
505
|
+
trace.info(peerConnectionType + " peerConnection created");
|
|
506
|
+
return peerConnection;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
TurnWebRtcSession.prototype._setPeerConnectionMonitor = function (peerConnection) {
|
|
510
|
+
var _this = this;
|
|
511
|
+
|
|
512
|
+
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
513
|
+
peerConnection.connectionTimoutPrt = setTimeout(function () {
|
|
514
|
+
trace.info('PeerConnection ICE state timeout', peerConnection);
|
|
515
|
+
|
|
516
|
+
_this._handlePeerConnectionTimeout(peerConnection);
|
|
517
|
+
}, this._sessionParams.peerConnectivityTimeoutSeconds * 1000);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
TurnWebRtcSession.prototype._handlePeerConnectionTimeout = function (peerConnection) {
|
|
521
|
+
trace.info('_handlePeerConnectionTimeout disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout);
|
|
522
|
+
|
|
523
|
+
if (peerConnection.peerRole === MediaConstants_1.SessionClientRole.USER) {
|
|
524
|
+
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout)["catch"](function () {
|
|
525
|
+
return undefined;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
TurnWebRtcSession.prototype._destroyPeerConnection = function (peerConnection) {
|
|
531
|
+
trace.info('Destroying PeerConnection', peerConnection.peerType);
|
|
532
|
+
peerConnection.ontrack = null;
|
|
533
|
+
peerConnection.onicecandidate = null;
|
|
534
|
+
peerConnection.onconnectionstatechange = null;
|
|
535
|
+
peerConnection.oniceconnectionstatechange = null;
|
|
536
|
+
peerConnection.onicegatheringstatechange = null;
|
|
537
|
+
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
538
|
+
this.unregisterPeersRemoteMediaTracks(peerConnection)["catch"](function () {
|
|
539
|
+
return undefined;
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
this._peerConnections["delete"](peerConnection.peerId);
|
|
543
|
+
|
|
544
|
+
peerConnection.close();
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
TurnWebRtcSession.prototype._withPeerConnection = function (peerId, callback) {
|
|
548
|
+
if (this._peerConnections.get(peerId)) {
|
|
549
|
+
return callback(this._peerConnections.get(peerId));
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
return undefined;
|
|
553
|
+
}; //#endregion
|
|
554
|
+
//#region ICE Candidates
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
TurnWebRtcSession.prototype._iceCandidateReceivedHandler = function (iceCandidateData) {
|
|
558
|
+
var candidate = iceCandidateData.candidate,
|
|
559
|
+
peerId = iceCandidateData.peerId;
|
|
560
|
+
trace.info('_iceCandidateReceivedHandler', candidate);
|
|
561
|
+
|
|
562
|
+
if (!candidate) {
|
|
563
|
+
trace.info('Unexpected case, iceCandidate message arrived without candidate');
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
var peerConnection = this._peerConnections.get(peerId);
|
|
568
|
+
|
|
569
|
+
if (!peerConnection || !peerConnection.remoteDescription) {
|
|
570
|
+
trace.info('Queueing iceCandidate', candidate);
|
|
571
|
+
|
|
572
|
+
this._queueIceCandidate(candidate, peerId);
|
|
573
|
+
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
trace.info('Going to add iceCandidate', candidate);
|
|
578
|
+
|
|
579
|
+
this._addIceCandidateToPeer(candidate, peerConnection)["catch"](function () {
|
|
580
|
+
return undefined;
|
|
581
|
+
});
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
TurnWebRtcSession.prototype._addIceCandidateToPeer = function (iceCandidate, peerConnection) {
|
|
585
|
+
return peerConnection.addIceCandidate(iceCandidate).then(function () {
|
|
586
|
+
trace.info('ICE Candidate add to peer connection');
|
|
587
|
+
})["catch"](function (e) {
|
|
588
|
+
trace.warn('Error adding ICE Candidate to peer connection', e);
|
|
589
|
+
throw e;
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
TurnWebRtcSession.prototype._processQueuedIceCandidates = function (peerId) {
|
|
594
|
+
var _this = this;
|
|
595
|
+
|
|
596
|
+
this._withPeerConnection(peerId, function (peerConnection) {
|
|
597
|
+
var pendingIces = _this._pendingPeersIce[peerId];
|
|
598
|
+
|
|
599
|
+
if (pendingIces) {
|
|
600
|
+
pendingIces.forEach(function (pendingIce) {
|
|
601
|
+
trace.info('Adding pending ICE to peer connections');
|
|
602
|
+
|
|
603
|
+
_this._addIceCandidateToPeer(pendingIce, peerConnection)["catch"](function () {
|
|
487
604
|
return undefined;
|
|
605
|
+
});
|
|
488
606
|
});
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
607
|
+
} else {
|
|
608
|
+
trace.info('No pending ICE found for peer', peerId);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
TurnWebRtcSession.prototype._queueIceCandidate = function (iceCandidate, peerId) {
|
|
614
|
+
if (!this._pendingPeersIce[peerId]) {
|
|
615
|
+
this._pendingPeersIce[peerId] = [];
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
this._pendingPeersIce[peerId].push(iceCandidate);
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
TurnWebRtcSession.prototype._iceStateDisconnected = function (peerConnection) {
|
|
622
|
+
trace.info('_iceStateDisconnected disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted);
|
|
623
|
+
|
|
624
|
+
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionInterrupted)["catch"](function () {
|
|
625
|
+
return undefined;
|
|
626
|
+
});
|
|
627
|
+
}; //#endregion
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
TurnWebRtcSession.prototype.sessionDisconnect = function () {
|
|
631
|
+
if (this._socket) {
|
|
632
|
+
this._socket.off();
|
|
633
|
+
|
|
634
|
+
this._socket.disconnect();
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
return TurnWebRtcSession;
|
|
498
639
|
}(MediaSessionBase_1.MediaSessionBase);
|
|
499
|
-
exports.TurnWebRtcSession = TurnWebRtcSession;
|
|
500
640
|
|
|
501
|
-
|
|
641
|
+
exports.TurnWebRtcSession = TurnWebRtcSession;
|
|
502
642
|
//# sourceMappingURL=SessionTurn.js.map
|