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