@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,583 +1,592 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
exports.TurnWebRtcSessionV2 = undefined;
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.TurnWebRtcSessionV2 = void 0;
|
|
7
9
|
|
|
8
|
-
var _session = require(
|
|
10
|
+
var _session = require("../session");
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var io = _interopRequireWildcard(require("socket.io-client"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _constants = require("./constants");
|
|
13
15
|
|
|
14
|
-
var
|
|
16
|
+
var _stream = require("./stream");
|
|
15
17
|
|
|
16
|
-
var
|
|
18
|
+
var _tracer = require("../tracer");
|
|
17
19
|
|
|
18
|
-
var
|
|
20
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
21
|
|
|
20
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; }
|
|
22
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
23
|
|
|
22
24
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
25
|
|
|
24
|
-
function
|
|
26
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
27
|
|
|
26
|
-
function
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
33
|
|
|
32
|
-
var
|
|
33
|
-
_inherits(TurnWebRtcSessionV2, _TsMediaSession);
|
|
34
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
key: 'id',
|
|
37
|
-
get: function get() {
|
|
38
|
-
return this._credentials.sessionId;
|
|
39
|
-
}
|
|
40
|
-
}]);
|
|
41
|
-
|
|
42
|
-
function TurnWebRtcSessionV2(_ref) {
|
|
43
|
-
var credentials = _ref.credentials,
|
|
44
|
-
constraints = _ref.constraints,
|
|
45
|
-
clientType = _ref.clientType,
|
|
46
|
-
streamFactory = _ref.streamFactory;
|
|
47
|
-
|
|
48
|
-
_classCallCheck(this, TurnWebRtcSessionV2);
|
|
36
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
49
37
|
|
|
50
|
-
|
|
38
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
_this._localPeer = null;
|
|
54
|
-
_this._pendingPeersIce = {};
|
|
55
|
-
_this._peerConnections = new Map();
|
|
40
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
56
41
|
|
|
57
|
-
|
|
58
|
-
_this._constraints = constraints;
|
|
59
|
-
_this._selfClientType = clientType;
|
|
60
|
-
_this._localStreamFactory = streamFactory;
|
|
42
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
61
43
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var iceServers = credentials.ice.map(function (item) {
|
|
65
|
-
return {
|
|
66
|
-
urls: item.url,
|
|
67
|
-
username: item.login,
|
|
68
|
-
credential: item.password
|
|
69
|
-
};
|
|
70
|
-
});
|
|
44
|
+
var tracer = (0, _tracer.getTracer)(); //Currently this version supports subscribing only. Publishing will be implemented as needed.
|
|
71
45
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
iceTransportPolicy: 'relay'
|
|
75
|
-
};
|
|
46
|
+
var TurnWebRtcSessionV2 = /*#__PURE__*/function (_TsMediaSession) {
|
|
47
|
+
_inherits(TurnWebRtcSessionV2, _TsMediaSession);
|
|
76
48
|
|
|
77
|
-
|
|
78
|
-
_this._iceCandidateReceivedHandler = _this._iceCandidateReceivedHandler.bind(_this);
|
|
79
|
-
_this._sendOfferHandler = _this._sendOfferHandler.bind(_this);
|
|
80
|
-
_this._sdpOfferHandler = _this._sdpOfferHandler.bind(_this);
|
|
81
|
-
_this._initiatorReconnectHandler = _this._initiatorReconnectHandler.bind(_this);
|
|
82
|
-
_this._peerDisconnectedHandler = _this._peerDisconnectedHandler.bind(_this);
|
|
49
|
+
var _super = _createSuper(TurnWebRtcSessionV2);
|
|
83
50
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
51
|
+
function TurnWebRtcSessionV2(_ref) {
|
|
52
|
+
var _this;
|
|
87
53
|
|
|
88
|
-
|
|
54
|
+
var credentials = _ref.credentials,
|
|
55
|
+
constraints = _ref.constraints,
|
|
56
|
+
clientType = _ref.clientType,
|
|
57
|
+
streamFactory = _ref.streamFactory;
|
|
89
58
|
|
|
90
|
-
TurnWebRtcSessionV2
|
|
91
|
-
var _this2 = this;
|
|
59
|
+
_classCallCheck(this, TurnWebRtcSessionV2);
|
|
92
60
|
|
|
93
|
-
|
|
61
|
+
_this = _super.call(this);
|
|
62
|
+
_this._socket = null;
|
|
63
|
+
_this._localPeer = null;
|
|
64
|
+
_this._pendingPeersIce = {};
|
|
65
|
+
_this._peerConnections = new Map();
|
|
66
|
+
_this._credentials = credentials;
|
|
67
|
+
_this._constraints = constraints;
|
|
68
|
+
_this._selfClientType = clientType;
|
|
69
|
+
_this._localStreamFactory = streamFactory;
|
|
70
|
+
_this._connectPromise = null;
|
|
71
|
+
var iceServers = credentials.ice.map(function (item) {
|
|
72
|
+
return {
|
|
73
|
+
urls: item.url,
|
|
74
|
+
username: item.login,
|
|
75
|
+
credential: item.password
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
_this._configuration = {
|
|
79
|
+
iceServers: iceServers,
|
|
80
|
+
iceTransportPolicy: 'relay'
|
|
81
|
+
};
|
|
82
|
+
_this._joinResponseHandler = _this._joinResponseHandler.bind(_assertThisInitialized(_this));
|
|
83
|
+
_this._iceCandidateReceivedHandler = _this._iceCandidateReceivedHandler.bind(_assertThisInitialized(_this));
|
|
84
|
+
_this._sendOfferHandler = _this._sendOfferHandler.bind(_assertThisInitialized(_this));
|
|
85
|
+
_this._sdpOfferHandler = _this._sdpOfferHandler.bind(_assertThisInitialized(_this));
|
|
86
|
+
_this._initiatorReconnectHandler = _this._initiatorReconnectHandler.bind(_assertThisInitialized(_this));
|
|
87
|
+
_this._peerDisconnectedHandler = _this._peerDisconnectedHandler.bind(_assertThisInitialized(_this));
|
|
94
88
|
|
|
95
|
-
|
|
96
|
-
tracer.trace('already connecting');
|
|
97
|
-
return this._connectPromise;
|
|
98
|
-
}
|
|
89
|
+
_this._extendPeerConnection();
|
|
99
90
|
|
|
100
|
-
|
|
91
|
+
return _this;
|
|
92
|
+
} //#region Socket Connectivity
|
|
101
93
|
|
|
102
|
-
this._connectPromise = this._connectSocket(this._credentials.url, connectOnly).then(function () {
|
|
103
|
-
tracer.trace('Joining SessionId: ' + _this2._credentials.sessionId);
|
|
104
94
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
_createClass(TurnWebRtcSessionV2, [{
|
|
96
|
+
key: "id",
|
|
97
|
+
get: function get() {
|
|
98
|
+
return this._credentials.sessionId;
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "connect",
|
|
102
|
+
value: function connect() {
|
|
103
|
+
var _this2 = this;
|
|
109
104
|
|
|
110
|
-
|
|
111
|
-
}).catch(function (error) {
|
|
112
|
-
setTimeout(function () {
|
|
113
|
-
return _this2._connectPromise = null;
|
|
114
|
-
});
|
|
115
|
-
_this2.emit(_session.SESSION_EVENTS.EXCEPTION, { source: 'connect', error: error });
|
|
116
|
-
throw error;
|
|
117
|
-
});
|
|
105
|
+
var connectOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
118
106
|
|
|
107
|
+
if (this._connectPromise) {
|
|
108
|
+
tracer.trace('already connecting');
|
|
119
109
|
return this._connectPromise;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
TurnWebRtcSessionV2.prototype.disconnect = function disconnect() {
|
|
123
|
-
var _this3 = this;
|
|
110
|
+
}
|
|
124
111
|
|
|
125
|
-
|
|
112
|
+
tracer.trace('connect');
|
|
113
|
+
this._connectPromise = this._connectSocket(this._credentials.url, connectOnly).then(function () {
|
|
114
|
+
tracer.trace('Joining SessionId: ' + _this2._credentials.sessionId);
|
|
126
115
|
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
_this2._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.JOIN_ROOM, {
|
|
117
|
+
clientType: _this2._selfClientType,
|
|
118
|
+
sessionId: _this2._credentials.sessionId
|
|
129
119
|
});
|
|
130
120
|
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
_this2._connectPromise = null;
|
|
122
|
+
})["catch"](function (error) {
|
|
123
|
+
setTimeout(function () {
|
|
124
|
+
return _this2._connectPromise = null;
|
|
125
|
+
});
|
|
133
126
|
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
_this2.emit(_session.SESSION_EVENTS.EXCEPTION, {
|
|
128
|
+
source: 'connect',
|
|
129
|
+
error: error
|
|
130
|
+
});
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
throw error;
|
|
133
|
+
});
|
|
134
|
+
return this._connectPromise;
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
key: "disconnect",
|
|
138
|
+
value: function disconnect() {
|
|
139
|
+
var _this3 = this;
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
var socket = _this4._socket = io.connect(url, {
|
|
142
|
-
'forceNew': true,
|
|
143
|
-
'reconnectionDelay': _constants.SOCKET_RECONNECTION_DELAY,
|
|
144
|
-
'reconnectionDelayMax': _constants.SOCKET_RECONNECTION_DELAY_MAX,
|
|
145
|
-
'reconnectionAttempts': _constants.SOCKET_RECONNECTION_ATTEMPTS,
|
|
146
|
-
'path': _constants.SOCKET_PATH
|
|
147
|
-
});
|
|
141
|
+
tracer.trace('Disconnecting from media session');
|
|
148
142
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
143
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
144
|
+
_this3._destroyPeerConnection(peerConnection);
|
|
145
|
+
});
|
|
152
146
|
|
|
153
|
-
|
|
154
|
-
return done();
|
|
155
|
-
});
|
|
156
|
-
socket.on(_constants.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
157
|
-
socket.on('connect_error', done);
|
|
158
|
-
socket.on('connect_timeout', done);
|
|
147
|
+
this._socket.off();
|
|
159
148
|
|
|
160
|
-
|
|
161
|
-
tracer.trace('Session Socket reconnect_attempt', args);
|
|
162
|
-
});
|
|
149
|
+
this._socket.disconnect();
|
|
163
150
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
151
|
+
this.emit(_session.SESSION_EVENTS.DISCONNECTED, {
|
|
152
|
+
reason: 'disconnected'
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "_connectSocket",
|
|
157
|
+
value: function _connectSocket(url, connectOnly) {
|
|
158
|
+
var _this4 = this;
|
|
159
|
+
|
|
160
|
+
return new Promise(function (resolve, reject) {
|
|
161
|
+
var socket = _this4._socket = io.connect(url, {
|
|
162
|
+
'forceNew': true,
|
|
163
|
+
'reconnectionDelay': _constants.SOCKET_RECONNECTION_DELAY,
|
|
164
|
+
'reconnectionDelayMax': _constants.SOCKET_RECONNECTION_DELAY_MAX,
|
|
165
|
+
'reconnectionAttempts': _constants.SOCKET_RECONNECTION_ATTEMPTS,
|
|
166
|
+
'path': _constants.SOCKET_PATH
|
|
167
|
+
});
|
|
167
168
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
|
|
172
|
-
//if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
|
|
173
|
-
// the disconnection was initiated by the server or by client, you need to call (connect) manually
|
|
174
|
-
_this4.disconnect();
|
|
175
|
-
//}
|
|
176
|
-
});
|
|
169
|
+
var done = _.once(function (err) {
|
|
170
|
+
err ? reject(err) : resolve();
|
|
171
|
+
});
|
|
177
172
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
socket.once('connect', function () {
|
|
174
|
+
return done();
|
|
175
|
+
});
|
|
176
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.ERROR, done);
|
|
177
|
+
socket.on('connect_error', done);
|
|
178
|
+
socket.on('connect_timeout', done);
|
|
179
|
+
socket.on('reconnect_attempt', function (args) {
|
|
180
|
+
tracer.trace('Session Socket reconnect_attempt', args);
|
|
181
|
+
});
|
|
182
|
+
socket.on('reconnecting', function (args) {
|
|
183
|
+
tracer.trace('Session Socket reconnecting', args);
|
|
184
|
+
});
|
|
185
|
+
socket.on('disconnect', function (reason) {
|
|
186
|
+
tracer.trace('Session Socket disconnected, reason:', reason); // The initial example of differentiating between "forced" disconnect and "network" disconnect is taken from:
|
|
187
|
+
// https://socket.io/docs/client-api/#Event-%E2%80%98disconnect%E2%80%99
|
|
188
|
+
//if (reason !== 'io server disconnect' && reason !== 'io client disconnect') {
|
|
189
|
+
// the disconnection was initiated by the server or by client, you need to call (connect) manually
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
socket.on(_constants.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, _this4._initiatorReconnectHandler);
|
|
191
|
+
_this4.disconnect(); //}
|
|
186
192
|
|
|
187
|
-
socket.on(_constants.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, _this4._iceCandidateReceivedHandler);
|
|
188
|
-
}
|
|
189
193
|
});
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
//#endregion
|
|
193
194
|
|
|
195
|
+
if (!connectOnly) {
|
|
196
|
+
//PUBLISHING NOT SUPPORTED YET
|
|
197
|
+
//socket.on(SOCKET_EVENTS.INCOMING.SEND_OFFER, this._sendOfferHandler);
|
|
198
|
+
//socket.on(SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, this._joinResponseHandler);
|
|
199
|
+
//socket.on(SOCKET_EVENTS.INCOMING.PEER_DISCONNECTED, this._peerDisconnectedHandler);
|
|
200
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.SDP_OFFER, _this4._sdpOfferHandler);
|
|
201
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.PUBLISHER_RECONNECT, _this4._initiatorReconnectHandler);
|
|
202
|
+
socket.on(_constants.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, _this4._iceCandidateReceivedHandler);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
} //#endregion
|
|
194
206
|
//#region WebRTC Initiator - session Initiator (User on mobile device)
|
|
195
|
-
|
|
196
207
|
// Received by Initiator, causing him to emit SDP_OFFER
|
|
197
208
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
_this5.registerStream(peerConnectionStream.id, peerConnectionStream);
|
|
223
|
-
}).then(function () {
|
|
224
|
-
return peerConnection.createOffer(offerParams);
|
|
225
|
-
}).then(function (offerDesc) {
|
|
226
|
-
tracer.trace('Initiator has created sdp offer', { offerDesc: offerDesc });
|
|
227
|
-
|
|
228
|
-
_this5._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
229
|
-
uid: uid,
|
|
230
|
-
peerId: peerId,
|
|
231
|
-
sessionId: _this5._credentials.sessionId,
|
|
232
|
-
sdpOffer: offerDesc.sdp
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
return peerConnection.setLocalDescription(offerDesc).then(function () {
|
|
236
|
-
tracer.trace('Local description was set on');
|
|
237
|
-
});
|
|
238
|
-
}).catch(function (e) {
|
|
239
|
-
tracer.trace('Error', e);
|
|
209
|
+
}, {
|
|
210
|
+
key: "_sendOfferHandler",
|
|
211
|
+
value: function _sendOfferHandler(_ref2) {
|
|
212
|
+
var _this5 = this;
|
|
213
|
+
|
|
214
|
+
var uid = _ref2.uid,
|
|
215
|
+
peerId = _ref2.peerId;
|
|
216
|
+
tracer.trace('_sendOfferHandler');
|
|
217
|
+
|
|
218
|
+
var peerConnection = this._createPeerConnection(peerId, _constants.CLIENT_TYPES.GUEST);
|
|
219
|
+
|
|
220
|
+
var offerParams = {
|
|
221
|
+
offerToReceiveAudio: true,
|
|
222
|
+
offerToReceiveVideo: true
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
this._localStreamFactory(this._constraints).then(function (localStream) {
|
|
226
|
+
tracer.trace('_sendOfferHandler stream and peer created');
|
|
227
|
+
var peerConnectionStream = new _stream.TsWebRTCStream(_this5, localStream.clone(), _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_VIDEO_STREAM, false);
|
|
228
|
+
peerConnectionStream.peerConnection = peerConnection;
|
|
229
|
+
localStream.getTracks().forEach(function (track) {
|
|
230
|
+
tracer.trace('Adding local tracks to peer connection');
|
|
231
|
+
peerConnection.addTrack(track, peerConnectionStream._mediaStream);
|
|
240
232
|
});
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// Received by the Initiator: Indicates that publish should be started
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
TurnWebRtcSessionV2.prototype._joinResponseHandler = function _joinResponseHandler(_ref3) {
|
|
247
|
-
var _this6 = this;
|
|
248
|
-
|
|
249
|
-
var sdpAnswer = _ref3.sdpAnswer,
|
|
250
|
-
uid = _ref3.uid,
|
|
251
|
-
peerId = _ref3.peerId;
|
|
252
|
-
|
|
253
|
-
tracer.trace('joinResponse Received', sdpAnswer);
|
|
254
|
-
|
|
255
|
-
this._withPeerConnection(peerId, function (peerConnection) {
|
|
256
|
-
var answer = new RTCSessionDescription({
|
|
257
|
-
type: 'answer',
|
|
258
|
-
sdp: sdpAnswer
|
|
259
|
-
});
|
|
260
233
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
});
|
|
234
|
+
_this5.registerStream(peerConnectionStream.id, peerConnectionStream);
|
|
235
|
+
}).then(function () {
|
|
236
|
+
return peerConnection.createOffer(offerParams);
|
|
237
|
+
}).then(function (offerDesc) {
|
|
238
|
+
tracer.trace('Initiator has created sdp offer', {
|
|
239
|
+
offerDesc: offerDesc
|
|
268
240
|
});
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// Received by Initiator after a guests socket has been disconnected
|
|
272
|
-
|
|
273
241
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
242
|
+
_this5._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.SDP_OFFER, {
|
|
243
|
+
uid: uid,
|
|
244
|
+
peerId: peerId,
|
|
245
|
+
sessionId: _this5._credentials.sessionId,
|
|
246
|
+
sdpOffer: offerDesc.sdp
|
|
247
|
+
});
|
|
279
248
|
|
|
280
|
-
|
|
249
|
+
return peerConnection.setLocalDescription(offerDesc).then(function () {
|
|
250
|
+
tracer.trace('Local description was set on');
|
|
251
|
+
});
|
|
252
|
+
})["catch"](function (e) {
|
|
253
|
+
tracer.trace('Error', e);
|
|
254
|
+
});
|
|
255
|
+
} // Received by the Initiator: Indicates that publish should be started
|
|
256
|
+
|
|
257
|
+
}, {
|
|
258
|
+
key: "_joinResponseHandler",
|
|
259
|
+
value: function _joinResponseHandler(_ref3) {
|
|
260
|
+
var _this6 = this;
|
|
261
|
+
|
|
262
|
+
var sdpAnswer = _ref3.sdpAnswer,
|
|
263
|
+
uid = _ref3.uid,
|
|
264
|
+
peerId = _ref3.peerId;
|
|
265
|
+
tracer.trace('joinResponse Received', sdpAnswer);
|
|
266
|
+
|
|
267
|
+
this._withPeerConnection(peerId, function (peerConnection) {
|
|
268
|
+
var answer = new RTCSessionDescription({
|
|
269
|
+
type: 'answer',
|
|
270
|
+
sdp: sdpAnswer
|
|
271
|
+
});
|
|
272
|
+
peerConnection.setRemoteDescription(answer).then(function () {
|
|
273
|
+
tracer.trace('Remote description was set', answer);
|
|
281
274
|
|
|
275
|
+
_this6._processQueuedIceCandidates(peerId);
|
|
276
|
+
})["catch"](function (e) {
|
|
277
|
+
tracer.trace('Error', e);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
} // Received by Initiator after a guests socket has been disconnected
|
|
281
|
+
|
|
282
|
+
}, {
|
|
283
|
+
key: "_peerDisconnectedHandler",
|
|
284
|
+
value: function _peerDisconnectedHandler(_ref4) {
|
|
285
|
+
var peerId = _ref4.peerId;
|
|
286
|
+
tracer.trace('_peerDisconnectedHandler');
|
|
287
|
+
} //#endregion WebRTC Initiator - session Initiator (User on mobile device)
|
|
282
288
|
//#region WebRTC Guest - session Guest (Agent on dashboard platform)
|
|
283
|
-
|
|
284
289
|
// Received by Guest, causing him to emit SDP_ANSWER
|
|
285
290
|
|
|
291
|
+
}, {
|
|
292
|
+
key: "_sdpOfferHandler",
|
|
293
|
+
value: function _sdpOfferHandler(_ref5) {
|
|
294
|
+
var _this7 = this;
|
|
286
295
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
tracer.trace('sdpOffer Received', { sdpOffer: sdpOffer });
|
|
295
|
-
|
|
296
|
-
var peerConnection = this._createPeerConnection(peerId, _constants.CLIENT_TYPES.INITIATOR);
|
|
297
|
-
|
|
298
|
-
var subscriberInitChain = Promise.resolve();
|
|
299
|
-
|
|
300
|
-
if (this._constraints.audio) {
|
|
301
|
-
subscriberInitChain = subscriberInitChain.then(function () {
|
|
302
|
-
tracer.trace('Creating agent local streams');
|
|
303
|
-
|
|
304
|
-
return _this7._localStreamFactory(_this7._constraints).then(function (localStream) {
|
|
305
|
-
localStream.getTracks().forEach(function (track) {
|
|
306
|
-
tracer.trace('Adding local tracks to peer connection');
|
|
307
|
-
|
|
308
|
-
if (track.kind === 'audio') {
|
|
296
|
+
var sdpOffer = _ref5.sdpOffer,
|
|
297
|
+
peerId = _ref5.peerId,
|
|
298
|
+
uid = _ref5.uid;
|
|
299
|
+
tracer.trace('sdpOffer Received', {
|
|
300
|
+
sdpOffer: sdpOffer
|
|
301
|
+
});
|
|
309
302
|
|
|
310
|
-
|
|
311
|
-
var streamName = _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM;
|
|
312
|
-
var agentAudioStream = new _stream.TsWebRTCStream(_this7, stream, streamName, false);
|
|
303
|
+
var peerConnection = this._createPeerConnection(peerId, _constants.CLIENT_TYPES.INITIATOR);
|
|
313
304
|
|
|
314
|
-
|
|
315
|
-
peerConnection.addTrack(track, peerConnection.peerLogicalStream);
|
|
305
|
+
var subscriberInitChain = Promise.resolve();
|
|
316
306
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
subscriberInitChain.then(function () {
|
|
325
|
-
var remoteDesc = new RTCSessionDescription({ type: 'offer', sdp: sdpOffer });
|
|
326
|
-
|
|
327
|
-
return peerConnection.setRemoteDescription(remoteDesc).then(function () {
|
|
328
|
-
tracer.trace('Remote description was set', remoteDesc);
|
|
329
|
-
|
|
330
|
-
return peerConnection.createAnswer().then(function (sdpAnswer) {
|
|
331
|
-
tracer.trace('_sdpOfferHandler answer created', sdpAnswer);
|
|
307
|
+
if (this._constraints.audio) {
|
|
308
|
+
subscriberInitChain = subscriberInitChain.then(function () {
|
|
309
|
+
tracer.trace('Creating agent local streams');
|
|
310
|
+
return _this7._localStreamFactory(_this7._constraints).then(function (localStream) {
|
|
311
|
+
localStream.getTracks().forEach(function (track) {
|
|
312
|
+
tracer.trace('Adding local tracks to peer connection');
|
|
332
313
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
sdpAnswer: sdpAnswer.sdp
|
|
338
|
-
});
|
|
314
|
+
if (track.kind === 'audio') {
|
|
315
|
+
var stream = new MediaStream([track]);
|
|
316
|
+
var streamName = _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM;
|
|
317
|
+
var agentAudioStream = new _stream.TsWebRTCStream(_this7, stream, streamName, false);
|
|
339
318
|
|
|
340
|
-
|
|
341
|
-
tracer.trace('_sdpOfferHandler local desc was set');
|
|
319
|
+
_this7.registerStream(agentAudioStream.id, agentAudioStream);
|
|
342
320
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
321
|
+
peerConnection.addTrack(track, peerConnection.peerLogicalStream);
|
|
322
|
+
tracer.trace('Agent audio stream added to peerConnection');
|
|
323
|
+
}
|
|
346
324
|
});
|
|
325
|
+
});
|
|
347
326
|
});
|
|
327
|
+
}
|
|
348
328
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
329
|
+
subscriberInitChain.then(function () {
|
|
330
|
+
var remoteDesc = new RTCSessionDescription({
|
|
331
|
+
type: 'offer',
|
|
332
|
+
sdp: sdpOffer
|
|
352
333
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
334
|
+
return peerConnection.setRemoteDescription(remoteDesc).then(function () {
|
|
335
|
+
tracer.trace('Remote description was set', remoteDesc);
|
|
336
|
+
return peerConnection.createAnswer().then(function (sdpAnswer) {
|
|
337
|
+
tracer.trace('_sdpOfferHandler answer created', sdpAnswer);
|
|
338
|
+
|
|
339
|
+
_this7._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.SDP_ANSWER, {
|
|
340
|
+
uid: uid,
|
|
341
|
+
peerId: peerId,
|
|
342
|
+
sessionId: _this7._credentials.sessionId,
|
|
343
|
+
sdpAnswer: sdpAnswer.sdp
|
|
344
|
+
});
|
|
360
345
|
|
|
361
|
-
|
|
346
|
+
return peerConnection.setLocalDescription(sdpAnswer).then(function () {
|
|
347
|
+
tracer.trace('_sdpOfferHandler local desc was set');
|
|
362
348
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
349
|
+
_this7._processQueuedIceCandidates(peerId);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
return subscriberInitChain["catch"](function (e) {
|
|
355
|
+
tracer.trace('Error in _sdpOfferHandler', e);
|
|
356
|
+
throw e;
|
|
357
|
+
});
|
|
358
|
+
} // Received by Guest after an Initiator reconnects to room
|
|
366
359
|
|
|
367
|
-
|
|
368
|
-
|
|
360
|
+
}, {
|
|
361
|
+
key: "_initiatorReconnectHandler",
|
|
362
|
+
value: function _initiatorReconnectHandler() {
|
|
363
|
+
tracer.trace('_initiatorReconnectHandler');
|
|
369
364
|
|
|
370
|
-
|
|
371
|
-
var peer = this._getPeerConnectionsByType(_constants.CLIENT_TYPES.INITIATOR);
|
|
365
|
+
var initiatorPeer = this._getInitiatorPeer();
|
|
372
366
|
|
|
373
|
-
|
|
374
|
-
|
|
367
|
+
if (initiatorPeer) {
|
|
368
|
+
this._destroyPeerConnection(initiatorPeer);
|
|
369
|
+
}
|
|
375
370
|
|
|
376
|
-
|
|
371
|
+
this.emit(_session.SESSION_EVENTS.RECONNECT_TURN_SERVER);
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
key: "_getInitiatorPeer",
|
|
375
|
+
value: function _getInitiatorPeer() {
|
|
376
|
+
var peer = this._getPeerConnectionsByType(_constants.CLIENT_TYPES.INITIATOR);
|
|
377
377
|
|
|
378
|
+
return peer.length > 0 ? peer[0] : null;
|
|
379
|
+
} //#endregion WebRTC Guest - session Guest (Agent on dashboard platform)
|
|
378
380
|
//#region Peer Connection
|
|
379
381
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
peerConnection.onicecandidate = function (event) {
|
|
412
|
-
if (event.candidate) {
|
|
413
|
-
tracer.trace(_this8._selfClientType + ' peerConn.onicecandidate', event.candidate);
|
|
414
|
-
_this8._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
415
|
-
sessionId: _this8._credentials.sessionId,
|
|
416
|
-
peerId: peerId,
|
|
417
|
-
candidate: event.candidate,
|
|
418
|
-
clientType: _this8._selfClientType
|
|
419
|
-
});
|
|
420
|
-
} else {
|
|
421
|
-
tracer.trace('ICE Candidate is null in peerConnection', event);
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
if (this._selfClientType === _constants.CLIENT_TYPES.GUEST) {
|
|
426
|
-
peerConnection.ontrack = function (trackEvent) {
|
|
427
|
-
var track = trackEvent.track,
|
|
428
|
-
streams = trackEvent.streams;
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
tracer.trace('Stream created from peer connection track: ' + track.kind, track, streams.length > 0 ? streams[0] : 'NO STREAM');
|
|
432
|
-
|
|
433
|
-
var tsStream = new _stream.TsWebRTCStream(_this8, new MediaStream([track]));
|
|
434
|
-
|
|
435
|
-
tsStream.peerConnection = peerConnection;
|
|
436
|
-
tsStream.remote = true;
|
|
437
|
-
|
|
438
|
-
_this8.registerStream(tsStream.id, tsStream);
|
|
439
|
-
|
|
440
|
-
_this8.emit(_session.SESSION_EVENTS.STREAM_CREATED, tsStream);
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
this._peerConnections.set(peerId, peerConnection);
|
|
445
|
-
|
|
446
|
-
tracer.trace(this._selfClientType + ' peerConnection created');
|
|
447
|
-
|
|
448
|
-
return peerConnection;
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
TurnWebRtcSessionV2.prototype._destroyPeerConnection = function _destroyPeerConnection(peerConnection) {
|
|
452
|
-
var _this9 = this;
|
|
453
|
-
|
|
454
|
-
if (this._selfClientType === _constants.CLIENT_TYPES.GUEST) {
|
|
455
|
-
this._getRemoteStreams(peerConnection).forEach(function (stream) {
|
|
456
|
-
_this9.unregisterStream(stream.id);
|
|
457
|
-
_this9.emit(_session.SESSION_EVENTS.STREAM_DESTROYED, { stream: stream });
|
|
458
|
-
});
|
|
382
|
+
}, {
|
|
383
|
+
key: "_createPeerConnection",
|
|
384
|
+
value: function _createPeerConnection(peerId, peerConnectionType) {
|
|
385
|
+
var _this8 = this;
|
|
386
|
+
|
|
387
|
+
if (this._peerConnections.get(peerId)) {
|
|
388
|
+
throw new Error("".concat(this._selfClientType, " peer connection for ").concat(peerId, " already exists"));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
var peerConnection = new RTCPeerConnection(this._configuration);
|
|
392
|
+
peerConnection.peerId = peerId;
|
|
393
|
+
peerConnection.peerType = peerConnectionType;
|
|
394
|
+
peerConnection.peerLogicalStream = new MediaStream();
|
|
395
|
+
|
|
396
|
+
peerConnection.oniceconnectionstatechange = function (state) {
|
|
397
|
+
tracer.trace("ICE Connection state for peer ".concat(peerId, " was changed to: ").concat(state.currentTarget.iceConnectionState), state);
|
|
398
|
+
var cnnState = state.currentTarget.iceConnectionState;
|
|
399
|
+
|
|
400
|
+
if (cnnState === 'disconnected') {//According to https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState
|
|
401
|
+
//Connection can become active again, so we will do nothing.
|
|
402
|
+
// if (peerConnection.peerType === CLIENT_TYPES.INITIATOR) {
|
|
403
|
+
// //this._destroyPeerConnection(peerConnection);
|
|
404
|
+
// this.disconnect();
|
|
405
|
+
// }
|
|
406
|
+
} else if (cnnState === 'failed' || cnnState === 'closed') {
|
|
407
|
+
//According to https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/iceConnectionState
|
|
408
|
+
//When iceConnectionState is failed or closed, the peer connection can be destroyed.
|
|
409
|
+
//In our case, we disconnecting from media session, and when session will be needed again, it will be connected.
|
|
410
|
+
_this8.disconnect();
|
|
459
411
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
peerConnection.onicecandidate = function (event) {
|
|
415
|
+
if (event.candidate) {
|
|
416
|
+
tracer.trace("".concat(_this8._selfClientType, " peerConn.onicecandidate"), event.candidate);
|
|
417
|
+
|
|
418
|
+
_this8._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
|
|
419
|
+
sessionId: _this8._credentials.sessionId,
|
|
420
|
+
peerId: peerId,
|
|
421
|
+
candidate: event.candidate,
|
|
422
|
+
clientType: _this8._selfClientType
|
|
423
|
+
});
|
|
424
|
+
} else {
|
|
425
|
+
tracer.trace('ICE Candidate is null in peerConnection', event);
|
|
463
426
|
}
|
|
427
|
+
};
|
|
464
428
|
|
|
465
|
-
|
|
466
|
-
peerConnection.
|
|
467
|
-
|
|
429
|
+
if (this._selfClientType === _constants.CLIENT_TYPES.GUEST) {
|
|
430
|
+
peerConnection.ontrack = function (trackEvent) {
|
|
431
|
+
var track = trackEvent.track,
|
|
432
|
+
streams = trackEvent.streams;
|
|
433
|
+
tracer.trace("Stream created from peer connection track: ".concat(track.kind), track, streams.length > 0 ? streams[0] : 'NO STREAM');
|
|
434
|
+
var tsStream = new _stream.TsWebRTCStream(_this8, new MediaStream([track]));
|
|
435
|
+
tsStream.peerConnection = peerConnection;
|
|
436
|
+
tsStream.remote = true;
|
|
468
437
|
|
|
469
|
-
|
|
470
|
-
var result = [];
|
|
438
|
+
_this8.registerStream(tsStream.id, tsStream);
|
|
471
439
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
return result;
|
|
479
|
-
};
|
|
440
|
+
_this8.emit(_session.SESSION_EVENTS.STREAM_CREATED, tsStream);
|
|
441
|
+
};
|
|
442
|
+
}
|
|
480
443
|
|
|
481
|
-
|
|
482
|
-
var result = [];
|
|
444
|
+
this._peerConnections.set(peerId, peerConnection);
|
|
483
445
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
446
|
+
tracer.trace("".concat(this._selfClientType, " peerConnection created"));
|
|
447
|
+
return peerConnection;
|
|
448
|
+
}
|
|
449
|
+
}, {
|
|
450
|
+
key: "_destroyPeerConnection",
|
|
451
|
+
value: function _destroyPeerConnection(peerConnection) {
|
|
452
|
+
var _this9 = this;
|
|
453
|
+
|
|
454
|
+
if (this._selfClientType === _constants.CLIENT_TYPES.GUEST) {
|
|
455
|
+
this._getRemoteStreams(peerConnection).forEach(function (stream) {
|
|
456
|
+
_this9.unregisterStream(stream.id);
|
|
457
|
+
|
|
458
|
+
_this9.emit(_session.SESSION_EVENTS.STREAM_DESTROYED, {
|
|
459
|
+
stream: stream
|
|
460
|
+
});
|
|
488
461
|
});
|
|
462
|
+
}
|
|
489
463
|
|
|
490
|
-
|
|
491
|
-
|
|
464
|
+
if (this._selfClientType === _constants.CLIENT_TYPES.INITIATOR && this._peerConnections.size === 0) {//TODO - ALEX: When initiator will be implemented, here we need to destroy local stream (or better raise, event).
|
|
465
|
+
}
|
|
492
466
|
|
|
493
|
-
|
|
494
|
-
if (this._peerConnections.get(peerId)) {
|
|
495
|
-
return callback(this._peerConnections.get(peerId));
|
|
496
|
-
}
|
|
467
|
+
this._peerConnections["delete"](peerConnection.peerId);
|
|
497
468
|
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (!RTCPeerConnection.prototype.peerType) {
|
|
509
|
-
RTCPeerConnection.prototype.peerType = null;
|
|
469
|
+
peerConnection.close();
|
|
470
|
+
}
|
|
471
|
+
}, {
|
|
472
|
+
key: "_getRemoteStreams",
|
|
473
|
+
value: function _getRemoteStreams(peerConnection) {
|
|
474
|
+
var result = [];
|
|
475
|
+
this.streams.forEach(function (stream) {
|
|
476
|
+
if (stream.peerConnection === peerConnection && stream.remote) {
|
|
477
|
+
result.push(stream);
|
|
510
478
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
479
|
+
});
|
|
480
|
+
return result;
|
|
481
|
+
}
|
|
482
|
+
}, {
|
|
483
|
+
key: "_getPeerConnectionsByType",
|
|
484
|
+
value: function _getPeerConnectionsByType(peerType) {
|
|
485
|
+
var result = [];
|
|
486
|
+
|
|
487
|
+
this._peerConnections.forEach(function (peerConnection) {
|
|
488
|
+
if (peerConnection.peerType === peerType) {
|
|
489
|
+
result.push(peerConnection);
|
|
514
490
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
//#endregion
|
|
491
|
+
});
|
|
518
492
|
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
495
|
+
}, {
|
|
496
|
+
key: "_withPeerConnection",
|
|
497
|
+
value: function _withPeerConnection(peerId, callback) {
|
|
498
|
+
if (this._peerConnections.get(peerId)) {
|
|
499
|
+
return callback(this._peerConnections.get(peerId));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}, {
|
|
505
|
+
key: "_extendPeerConnection",
|
|
506
|
+
value: function _extendPeerConnection() {
|
|
507
|
+
//TODO - Alex: Need to modify IE shim, and add these methods inside shim itself
|
|
508
|
+
if (!RTCPeerConnection.prototype.peerId) {
|
|
509
|
+
RTCPeerConnection.prototype.peerId = '';
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (!RTCPeerConnection.prototype.peerType) {
|
|
513
|
+
RTCPeerConnection.prototype.peerType = null;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if (!RTCPeerConnection.prototype.peerLogicalStream) {
|
|
517
|
+
RTCPeerConnection.prototype.peerLogicalStream = null;
|
|
518
|
+
}
|
|
519
|
+
} //#endregion
|
|
519
520
|
//#region ICE Candidates
|
|
520
521
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
tracer.trace('NO iceCandidate');
|
|
528
|
-
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
var peerConnection = this._peerConnections.get(peerId);
|
|
522
|
+
}, {
|
|
523
|
+
key: "_iceCandidateReceivedHandler",
|
|
524
|
+
value: function _iceCandidateReceivedHandler(_ref6) {
|
|
525
|
+
var candidate = _ref6.candidate,
|
|
526
|
+
peerId = _ref6.peerId;
|
|
527
|
+
tracer.trace('_iceCandidateReceivedHandler', candidate);
|
|
533
528
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
529
|
+
if (!candidate) {
|
|
530
|
+
tracer.trace('NO iceCandidate');
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
537
533
|
|
|
538
|
-
|
|
539
|
-
}
|
|
534
|
+
var peerConnection = this._peerConnections.get(peerId);
|
|
540
535
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
};
|
|
536
|
+
if (!peerConnection || !peerConnection.remoteDescription) {
|
|
537
|
+
tracer.trace('Queueing iceCandidate', candidate);
|
|
544
538
|
|
|
545
|
-
|
|
546
|
-
return peerConnection.addIceCandidate(iceCandidate).then(function () {
|
|
547
|
-
tracer.trace('ICE Candidate add to peer connection');
|
|
548
|
-
}).catch(function (e) {
|
|
549
|
-
tracer.trace('Error adding ICE Candidate to peer connection', e);
|
|
550
|
-
});
|
|
551
|
-
};
|
|
539
|
+
this._queueIceCandidate(candidate, peerId);
|
|
552
540
|
|
|
553
|
-
|
|
554
|
-
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
555
543
|
|
|
556
|
-
|
|
557
|
-
var pendingIces = _this10._pendingPeersIce[peerId];
|
|
544
|
+
tracer.trace('Going to add iceCandidate', candidate);
|
|
558
545
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
546
|
+
this._addIceCandidateToPeer(candidate, peerConnection);
|
|
547
|
+
}
|
|
548
|
+
}, {
|
|
549
|
+
key: "_addIceCandidateToPeer",
|
|
550
|
+
value: function _addIceCandidateToPeer(iceCandidate, peerConnection) {
|
|
551
|
+
return peerConnection.addIceCandidate(iceCandidate).then(function () {
|
|
552
|
+
tracer.trace('ICE Candidate add to peer connection');
|
|
553
|
+
})["catch"](function (e) {
|
|
554
|
+
tracer.trace('Error adding ICE Candidate to peer connection', e);
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}, {
|
|
558
|
+
key: "_processQueuedIceCandidates",
|
|
559
|
+
value: function _processQueuedIceCandidates(peerId) {
|
|
560
|
+
var _this10 = this;
|
|
561
|
+
|
|
562
|
+
this._withPeerConnection(peerId, function (peerConnection) {
|
|
563
|
+
var pendingIces = _this10._pendingPeersIce[peerId];
|
|
564
|
+
|
|
565
|
+
if (pendingIces) {
|
|
566
|
+
pendingIces.forEach(function (pendingIce) {
|
|
567
|
+
tracer.trace('Adding pending ICE to peer connections');
|
|
568
|
+
|
|
569
|
+
_this10._addIceCandidateToPeer(pendingIce, peerConnection);
|
|
570
|
+
});
|
|
571
|
+
} else {
|
|
572
|
+
tracer.trace('No pending ICE found for peer', peerId);
|
|
573
573
|
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
}, {
|
|
577
|
+
key: "_queueIceCandidate",
|
|
578
|
+
value: function _queueIceCandidate(iceCandidate, peerId) {
|
|
579
|
+
if (!this._pendingPeersIce[peerId]) {
|
|
580
|
+
this._pendingPeersIce[peerId] = [];
|
|
581
|
+
}
|
|
574
582
|
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
//#endregion
|
|
583
|
+
this._pendingPeersIce[peerId].push(iceCandidate);
|
|
584
|
+
} //#endregion
|
|
579
585
|
|
|
586
|
+
}]);
|
|
580
587
|
|
|
581
|
-
|
|
588
|
+
return TurnWebRtcSessionV2;
|
|
582
589
|
}(_session.TsMediaSession);
|
|
590
|
+
|
|
591
|
+
exports.TurnWebRtcSessionV2 = TurnWebRtcSessionV2;
|
|
583
592
|
//# sourceMappingURL=session-turn.v2.js.map
|