@techsee/techsee-media-service 999.0.2-switch → 999.0.3-alpha2
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 +12 -0
- package/lib/LocalStreamManager.d.ts.map +1 -1
- package/lib/LocalStreamManager.js +440 -283
- package/lib/LocalStreamManager.js.map +1 -1
- package/lib/MediaConstants.d.ts +14 -4
- package/lib/MediaConstants.d.ts.map +1 -1
- package/lib/MediaConstants.js +83 -38
- package/lib/MediaConstants.js.map +1 -1
- package/lib/MediaContracts.d.ts +17 -14
- package/lib/MediaContracts.d.ts.map +1 -1
- package/lib/MediaContracts.js +3 -3
- package/lib/MediaContracts.js.map +1 -1
- package/lib/MediaPublisher.d.ts +3 -3
- package/lib/MediaPublisher.d.ts.map +1 -1
- package/lib/MediaPublisher.js +46 -35
- package/lib/MediaPublisher.js.map +1 -1
- package/lib/MediaServiceBase.d.ts +21 -7
- package/lib/MediaServiceBase.d.ts.map +1 -1
- package/lib/MediaServiceBase.js +924 -586
- package/lib/MediaServiceBase.js.map +1 -1
- package/lib/MediaSession/MediaServer.d.ts +45 -0
- package/lib/MediaSession/MediaServer.d.ts.map +1 -0
- package/lib/MediaSession/MediaServer.js +538 -0
- package/lib/MediaSession/MediaServer.js.map +1 -0
- package/lib/MediaSession/MediaSessionBase.d.ts +10 -1
- package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
- package/lib/MediaSession/MediaSessionBase.js +128 -66
- package/lib/MediaSession/MediaSessionBase.js.map +1 -1
- package/lib/MediaSession/SessionOpentok.d.ts +11 -9
- package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
- package/lib/MediaSession/SessionOpentok.js +500 -352
- package/lib/MediaSession/SessionOpentok.js.map +1 -1
- package/lib/MediaSession/SessionTurn.d.ts +4 -1
- package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
- package/lib/MediaSession/SessionTurn.js +611 -422
- package/lib/MediaSession/SessionTurn.js.map +1 -1
- package/lib/MediaSession/TurnConstants.js +31 -30
- package/lib/MediaSession/TurnConstants.js.map +1 -1
- package/lib/MediaSubscriber.d.ts +11 -11
- package/lib/MediaSubscriber.d.ts.map +1 -1
- package/lib/MediaSubscriber.js +236 -192
- package/lib/MediaSubscriber.js.map +1 -1
- package/lib/MediaUtils/Compatibility.d.ts +2 -1
- package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
- package/lib/MediaUtils/Compatibility.js +130 -85
- package/lib/MediaUtils/Compatibility.js.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.d.ts +3 -2
- package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
- package/lib/MediaUtils/MediaDomUtils.js +235 -174
- package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
- package/lib/MediaUtils/MediaTracer.js +9 -4
- package/lib/MediaUtils/MediaTracer.js.map +1 -1
- package/lib/MediaUtils/index.d.ts +1 -0
- package/lib/MediaUtils/index.d.ts.map +1 -0
- package/lib/MediaUtils/index.js +16 -0
- package/lib/MediaUtils/index.js.map +1 -0
- package/lib/MultiParty/Contracts.d.ts +16 -0
- package/lib/MultiParty/Contracts.d.ts.map +1 -0
- package/lib/MultiParty/Contracts.js +6 -0
- package/lib/MultiParty/Contracts.js.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts +16 -0
- package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -0
- package/lib/MultiParty/DetectWebRtcService.js +79 -0
- package/lib/MultiParty/DetectWebRtcService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts +23 -0
- package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesService.js +369 -0
- package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +5 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js +305 -0
- package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -0
- package/lib/MultiParty/MultiPartyService.d.ts +40 -0
- package/lib/MultiParty/MultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyService.js +70 -0
- package/lib/MultiParty/MultiPartyService.js.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts +3 -0
- package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js +21 -0
- package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -0
- package/lib/MultiParty/OpentokMultiPartyService.d.ts +29 -0
- package/lib/MultiParty/OpentokMultiPartyService.d.ts.map +1 -0
- package/lib/MultiParty/OpentokMultiPartyService.js +888 -0
- package/lib/MultiParty/OpentokMultiPartyService.js.map +1 -0
- package/lib/MultiParty/VideoLayoutType.d.ts +4 -0
- package/lib/MultiParty/VideoLayoutType.d.ts.map +1 -0
- package/lib/MultiParty/VideoLayoutType.js +13 -0
- package/lib/MultiParty/VideoLayoutType.js.map +1 -0
- package/lib/MultiParty/index.d.ts +4 -0
- package/lib/MultiParty/index.d.ts.map +1 -0
- package/lib/MultiParty/index.js +61 -0
- package/lib/MultiParty/index.js.map +1 -0
- package/lib/MultiParty/opentok.d.ts +503 -0
- package/lib/TechseeMediaStream.d.ts +6 -6
- package/lib/TechseeMediaStream.d.ts.map +1 -1
- package/lib/TechseeMediaStream.js +59 -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.d.ts +3 -2
- package/lib/oldCode/tracer.d.ts.map +1 -1
- package/lib/oldCode/tracer.js +181 -130
- package/lib/oldCode/tracer.js.map +1 -1
- package/lib/oldCode/utils/ImageFixer.js +67 -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 -273
- 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 +54 -42
|
@@ -1,453 +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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
+
});
|
|
37
|
+
} : function (o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
});
|
|
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
|
+
});
|
|
47
|
+
} : function (o, v) {
|
|
48
|
+
o["default"] = v;
|
|
49
|
+
});
|
|
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;
|
|
29
61
|
};
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
|
|
63
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
64
|
+
return mod && mod.__esModule ? mod : {
|
|
65
|
+
"default": mod
|
|
66
|
+
};
|
|
32
67
|
};
|
|
33
|
-
|
|
68
|
+
|
|
69
|
+
Object.defineProperty(exports, "__esModule", {
|
|
70
|
+
value: true
|
|
71
|
+
});
|
|
72
|
+
exports.TurnWebRtcSession = void 0;
|
|
73
|
+
|
|
34
74
|
var io = __importStar(require("socket.io-client"));
|
|
75
|
+
|
|
35
76
|
var once_1 = __importDefault(require("lodash/once"));
|
|
77
|
+
|
|
36
78
|
var MediaConstants_1 = require("../MediaConstants");
|
|
79
|
+
|
|
37
80
|
var TurnConstants_1 = require("./TurnConstants");
|
|
81
|
+
|
|
38
82
|
var MediaTracer_1 = require("../MediaUtils/MediaTracer");
|
|
83
|
+
|
|
39
84
|
var MediaSessionBase_1 = require("./MediaSessionBase");
|
|
40
|
-
|
|
41
|
-
//Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_this._joinResponseHandler = _this._joinResponseHandler.bind(_this);
|
|
61
|
-
_this._iceCandidateReceivedHandler = _this._iceCandidateReceivedHandler.bind(_this);
|
|
62
|
-
_this._sendOfferHandler = _this._sendOfferHandler.bind(_this);
|
|
63
|
-
_this._sdpOfferHandler = _this._sdpOfferHandler.bind(_this);
|
|
64
|
-
_this._initiatorPeerReconnectHandler = _this._initiatorPeerReconnectHandler.bind(_this);
|
|
65
|
-
_this._peerDisconnectedHandler = _this._peerDisconnectedHandler.bind(_this);
|
|
66
|
-
_this._onSocketDisconnectedHandler = _this._onSocketDisconnectedHandler.bind(_this);
|
|
67
|
-
return _this;
|
|
68
|
-
}
|
|
69
|
-
Object.defineProperty(TurnWebRtcSession.prototype, "id", {
|
|
70
|
-
get: function get() {
|
|
71
|
-
return this._sessionParams.sessionId;
|
|
72
|
-
},
|
|
73
|
-
enumerable: true,
|
|
74
|
-
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
|
+
};
|
|
75
105
|
});
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (connectOnly === void 0) {
|
|
80
|
-
connectOnly = false;
|
|
81
|
-
}
|
|
82
|
-
trace.info('Connect to session');
|
|
83
|
-
return this._connectSocket(this._sessionParams.credentials.url, connectOnly).then(function () {
|
|
84
|
-
trace.info('Joining SessionId: ' + _this._sessionParams.sessionId);
|
|
85
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
|
|
86
|
-
clientType: _this._sessionParams.clientType,
|
|
87
|
-
sessionId: _this._sessionParams.sessionId
|
|
88
|
-
});
|
|
89
|
-
}).catch(function (error) {
|
|
90
|
-
throw error;
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
TurnWebRtcSession.prototype.disconnect = function () {
|
|
94
|
-
trace.info('disconnect - call disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
95
|
-
return this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.ForcedByConsumer);
|
|
96
|
-
};
|
|
97
|
-
TurnWebRtcSession.prototype._connectSocket = function (url, connectOnly) {
|
|
98
|
-
var _this = this;
|
|
99
|
-
return new Promise(function (resolve, reject) {
|
|
100
|
-
var socket = _this._socket = io.connect(url, {
|
|
101
|
-
'forceNew': true,
|
|
102
|
-
'reconnectionDelay': TurnConstants_1.SOCKET_RECONNECTION_DELAY,
|
|
103
|
-
'reconnectionDelayMax': TurnConstants_1.SOCKET_RECONNECTION_DELAY_MAX,
|
|
104
|
-
'reconnectionAttempts': TurnConstants_1.SOCKET_RECONNECTION_ATTEMPTS,
|
|
105
|
-
'path': TurnConstants_1.SOCKET_PATH
|
|
106
|
-
});
|
|
107
|
-
var done = once_1.default(function (err) {
|
|
108
|
-
err ? reject(err) : resolve();
|
|
109
|
-
});
|
|
110
|
-
socket.once('connect', function () {
|
|
111
|
-
return done();
|
|
112
|
-
});
|
|
113
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
114
|
-
socket.on('connect_error', done);
|
|
115
|
-
socket.on('connect_timeout', done);
|
|
116
|
-
socket.on('disconnect', _this._onSocketDisconnectedHandler);
|
|
117
|
-
if (!connectOnly) {
|
|
118
|
-
trace.info('Subscribing socket events');
|
|
119
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SEND_OFFER, _this._sendOfferHandler);
|
|
120
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, _this._joinResponseHandler);
|
|
121
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED, _this._peerDisconnectedHandler);
|
|
122
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.SDP_OFFER, _this._sdpOfferHandler);
|
|
123
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, _this._initiatorPeerReconnectHandler);
|
|
124
|
-
socket.on(TurnConstants_1.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, _this._iceCandidateReceivedHandler);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
TurnWebRtcSession.prototype._onSocketDisconnectedHandler = function (reason) {
|
|
129
|
-
if (this._socket) {
|
|
130
|
-
// The initial example of differentiating between "forced" disconnect and "network" disconnect is taken from:
|
|
131
|
-
// https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
|
|
132
|
-
if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
|
|
133
|
-
trace.info('_onSocketDisconnectedHandler disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect);
|
|
134
|
-
// the disconnection was initiated by the server or by client, you need to call (connect) manually
|
|
135
|
-
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.SignalingChannelDisconnect).catch(function () {
|
|
136
|
-
return undefined;
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
//#endregion
|
|
142
|
-
//#region WebRTC Initiator - session Initiator (User on mobile device)
|
|
143
|
-
// Received by Initiator, causing him to emit SDP_OFFER
|
|
144
|
-
TurnWebRtcSession.prototype._sendOfferHandler = function (sendOfferEventData) {
|
|
145
|
-
var _this = this;
|
|
146
|
-
var uid = sendOfferEventData.uid,
|
|
147
|
-
peerId = sendOfferEventData.peerId;
|
|
148
|
-
trace.info('_sendOfferHandler');
|
|
149
|
-
//Currently we not support of passing role through signaling, so we assume every connection is "AGENT" like
|
|
150
|
-
var peerConnection = this._createPeerConnection(peerId, MediaConstants_1.SessionClientType.GUEST, MediaConstants_1.SessionClientRole.AGENT);
|
|
151
|
-
var offerParams = { offerToReceiveAudio: true, offerToReceiveVideo: true };
|
|
152
|
-
//TODO - Alex: Currently we not sending "role" through signaling, and by default we assume that the one who asks fot offer, is agent.
|
|
153
|
-
//On later stages we can send or the client "role" or the list of "streams" that peer is interested in.
|
|
154
|
-
this._sessionStreamsManager.getMediaStreamForRole(MediaConstants_1.SessionClientRole.AGENT).then(function (mediaStream) {
|
|
155
|
-
trace.info('_sendOfferHandler stream and peer created');
|
|
156
|
-
if (mediaStream) {
|
|
157
|
-
trace.info('Adding local tracks to peer connection for sending offer');
|
|
158
|
-
mediaStream.getTracks().forEach(function (track) {
|
|
159
|
-
peerConnection.addTrack(track, mediaStream);
|
|
160
|
-
trace.info("Local " + track.kind + " " + track.id + " track added to peer connection");
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
trace.info('No media stream was found for publishing');
|
|
164
|
-
}
|
|
165
|
-
}).then(function () {
|
|
166
|
-
return peerConnection.createOffer(offerParams);
|
|
167
|
-
}).then(function (offerDesc) {
|
|
168
|
-
trace.info('Initiator has created sdp offer', { offerDesc: offerDesc });
|
|
169
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
170
|
-
uid: uid,
|
|
171
|
-
peerId: peerId,
|
|
172
|
-
sessionId: _this._sessionParams.sessionId,
|
|
173
|
-
sdpOffer: offerDesc.sdp
|
|
174
|
-
});
|
|
175
|
-
return peerConnection.setLocalDescription(offerDesc).then(function () {
|
|
176
|
-
trace.info('Local description was set on peerConnection', peerConnection);
|
|
177
|
-
_this._setPeerConnectionMonitor(peerConnection);
|
|
178
|
-
});
|
|
179
|
-
}).catch(function (e) {
|
|
180
|
-
trace.warn('Error', e);
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
// Received by the Initiator: Indicates that publish should be started
|
|
184
|
-
TurnWebRtcSession.prototype._joinResponseHandler = function (joinResponseData) {
|
|
185
|
-
var _this = this;
|
|
186
|
-
var sdpAnswer = joinResponseData.sdpAnswer,
|
|
187
|
-
uid = joinResponseData.uid,
|
|
188
|
-
peerId = joinResponseData.peerId;
|
|
189
|
-
trace.info('joinResponse Received', { sdpAnswer: sdpAnswer });
|
|
190
|
-
this._withPeerConnection(peerId, function (peerConnection) {
|
|
191
|
-
var answer = new RTCSessionDescription({
|
|
192
|
-
type: 'answer',
|
|
193
|
-
sdp: sdpAnswer
|
|
194
|
-
});
|
|
195
|
-
peerConnection.setRemoteDescription(answer).then(function () {
|
|
196
|
-
trace.info('Remote description was set', answer);
|
|
197
|
-
_this._processQueuedIceCandidates(peerId);
|
|
198
|
-
}).catch(function (e) {
|
|
199
|
-
trace.warn('Error', e);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
// Received by Initiator after a guests socket has been disconnected
|
|
204
|
-
TurnWebRtcSession.prototype._peerDisconnectedHandler = function (peerDisconnectedEvent) {
|
|
205
|
-
var _this = this;
|
|
206
|
-
var peerId = peerDisconnectedEvent.peerId;
|
|
207
|
-
trace.info('_peerDisconnectedHandler');
|
|
208
|
-
this._withPeerConnection(peerId, function (peerConnection) {
|
|
209
|
-
_this._destroyPeerConnection(peerConnection);
|
|
210
|
-
//this._disconnectInternal(MediaSessionDisconnectReason.PeerDisconnected).catch(() => undefined);
|
|
211
|
-
});
|
|
106
|
+
_this._configuration = {
|
|
107
|
+
iceServers: iceServers,
|
|
108
|
+
iceTransportPolicy: 'relay'
|
|
212
109
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
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;
|
|
255
196
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
}
|
|
262
218
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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");
|
|
275
254
|
});
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
+
});
|
|
286
282
|
}
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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");
|
|
294
349
|
});
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
var cnState = state.currentTarget.iceConnectionState;
|
|
323
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
324
|
-
if (['closed', 'disconnected', 'failed'].indexOf(cnState) > -1) {
|
|
325
|
-
_this._iceStateDisconnected(peerConnection);
|
|
326
|
-
} else if (cnState === 'connected') {
|
|
327
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
peerConnection.onicecandidate = function (event) {
|
|
331
|
-
if (event.candidate) {
|
|
332
|
-
trace.info(_this._sessionParams.clientType + " peerConn.onicecandidate", event.candidate);
|
|
333
|
-
_this._socket.emit(TurnConstants_1.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
334
|
-
sessionId: _this._sessionParams.sessionId,
|
|
335
|
-
peerId: peerId,
|
|
336
|
-
candidate: event.candidate,
|
|
337
|
-
clientType: _this._sessionParams.clientType
|
|
338
|
-
});
|
|
339
|
-
} else {
|
|
340
|
-
trace.info('ICE Candidate is null in peerConnection', event);
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
peerConnection.ontrack = function (trackEvent) {
|
|
344
|
-
var track = trackEvent.track;
|
|
345
|
-
trace.info("MediaStreamTrack arrived from peerConnection: " + track.kind, track);
|
|
346
|
-
_this.addRemoteTrackToPeer(peerConnection, track);
|
|
347
|
-
if (peerConnection.connectionState === 'connected') {
|
|
348
|
-
_this.registerPeersRemoteTracks(peerConnection);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
this._peerConnections.set(peerId, peerConnection);
|
|
352
|
-
trace.info(peerConnectionType + " peerConnection created");
|
|
353
|
-
return peerConnection;
|
|
354
|
-
};
|
|
355
|
-
TurnWebRtcSession.prototype._setPeerConnectionMonitor = function (peerConnection) {
|
|
356
|
-
var _this = this;
|
|
357
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
358
|
-
peerConnection.connectionTimoutPrt = setTimeout(function () {
|
|
359
|
-
trace.info('PeerConnection ICE state timeout', peerConnection);
|
|
360
|
-
_this._handlePeerConnectionTimeout(peerConnection);
|
|
361
|
-
}, this._sessionParams.peerConnectivityTimeoutSeconds * 1000);
|
|
362
|
-
};
|
|
363
|
-
TurnWebRtcSession.prototype._handlePeerConnectionTimeout = function (peerConnection) {
|
|
364
|
-
trace.info('_handlePeerConnectionTimeout disconnect from session', MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout);
|
|
365
|
-
if (peerConnection.peerRole === MediaConstants_1.SessionClientRole.USER) {
|
|
366
|
-
this._disconnectInternal(MediaConstants_1.MediaSessionDisconnectReason.PeerConnectionStateChangeTimeout).catch(function () {
|
|
367
|
-
return undefined;
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
TurnWebRtcSession.prototype._destroyPeerConnection = function (peerConnection) {
|
|
372
|
-
trace.info('Destroying PeerConnection', peerConnection.peerType);
|
|
373
|
-
peerConnection.ontrack = null;
|
|
374
|
-
peerConnection.onicecandidate = null;
|
|
375
|
-
peerConnection.onconnectionstatechange = null;
|
|
376
|
-
peerConnection.oniceconnectionstatechange = null;
|
|
377
|
-
peerConnection.onicegatheringstatechange = null;
|
|
378
|
-
clearTimeout(peerConnection.connectionTimoutPrt);
|
|
379
|
-
this.unregisterPeersRemoteMediaTracks(peerConnection).catch(function () {
|
|
380
|
-
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
|
+
});
|
|
381
377
|
});
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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 () {
|
|
389
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);
|
|
390
463
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (!peerConnection || !peerConnection.remoteDescription) {
|
|
403
|
-
trace.info('Queueing iceCandidate', candidate);
|
|
404
|
-
this._queueIceCandidate(candidate, peerId);
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
trace.info('Going to add iceCandidate', candidate);
|
|
408
|
-
this._addIceCandidateToPeer(candidate, peerConnection).catch(function () {
|
|
409
|
-
return undefined;
|
|
410
|
-
});
|
|
411
|
-
};
|
|
412
|
-
TurnWebRtcSession.prototype._addIceCandidateToPeer = function (iceCandidate, peerConnection) {
|
|
413
|
-
return peerConnection.addIceCandidate(iceCandidate).then(function () {
|
|
414
|
-
trace.info('ICE Candidate add to peer connection');
|
|
415
|
-
}).catch(function (e) {
|
|
416
|
-
trace.warn('Error adding ICE Candidate to peer connection', e);
|
|
417
|
-
throw e;
|
|
418
|
-
});
|
|
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
|
+
}
|
|
419
475
|
};
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
});
|
|
431
|
-
} else {
|
|
432
|
-
trace.info('No pending ICE found for peer', peerId);
|
|
433
|
-
}
|
|
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
|
|
434
486
|
});
|
|
487
|
+
} else {
|
|
488
|
+
trace.info('ICE Candidate is null in peerConnection', event);
|
|
489
|
+
}
|
|
435
490
|
};
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
+
}
|
|
441
501
|
};
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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 () {
|
|
445
604
|
return undefined;
|
|
605
|
+
});
|
|
446
606
|
});
|
|
447
|
-
|
|
448
|
-
|
|
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;
|
|
449
639
|
}(MediaSessionBase_1.MediaSessionBase);
|
|
450
|
-
exports.TurnWebRtcSession = TurnWebRtcSession;
|
|
451
640
|
|
|
452
|
-
|
|
641
|
+
exports.TurnWebRtcSession = TurnWebRtcSession;
|
|
453
642
|
//# sourceMappingURL=SessionTurn.js.map
|