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