@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.
Files changed (150) hide show
  1. package/lib/LocalStreamManager.d.ts +12 -0
  2. package/lib/LocalStreamManager.d.ts.map +1 -1
  3. package/lib/LocalStreamManager.js +440 -283
  4. package/lib/LocalStreamManager.js.map +1 -1
  5. package/lib/MediaConstants.d.ts +14 -4
  6. package/lib/MediaConstants.d.ts.map +1 -1
  7. package/lib/MediaConstants.js +83 -38
  8. package/lib/MediaConstants.js.map +1 -1
  9. package/lib/MediaContracts.d.ts +17 -14
  10. package/lib/MediaContracts.d.ts.map +1 -1
  11. package/lib/MediaContracts.js +3 -3
  12. package/lib/MediaContracts.js.map +1 -1
  13. package/lib/MediaPublisher.d.ts +3 -3
  14. package/lib/MediaPublisher.d.ts.map +1 -1
  15. package/lib/MediaPublisher.js +46 -35
  16. package/lib/MediaPublisher.js.map +1 -1
  17. package/lib/MediaServiceBase.d.ts +21 -7
  18. package/lib/MediaServiceBase.d.ts.map +1 -1
  19. package/lib/MediaServiceBase.js +924 -586
  20. package/lib/MediaServiceBase.js.map +1 -1
  21. package/lib/MediaSession/MediaServer.d.ts +45 -0
  22. package/lib/MediaSession/MediaServer.d.ts.map +1 -0
  23. package/lib/MediaSession/MediaServer.js +538 -0
  24. package/lib/MediaSession/MediaServer.js.map +1 -0
  25. package/lib/MediaSession/MediaSessionBase.d.ts +10 -1
  26. package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -1
  27. package/lib/MediaSession/MediaSessionBase.js +128 -66
  28. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  29. package/lib/MediaSession/SessionOpentok.d.ts +11 -9
  30. package/lib/MediaSession/SessionOpentok.d.ts.map +1 -1
  31. package/lib/MediaSession/SessionOpentok.js +500 -352
  32. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  33. package/lib/MediaSession/SessionTurn.d.ts +4 -1
  34. package/lib/MediaSession/SessionTurn.d.ts.map +1 -1
  35. package/lib/MediaSession/SessionTurn.js +611 -422
  36. package/lib/MediaSession/SessionTurn.js.map +1 -1
  37. package/lib/MediaSession/TurnConstants.js +31 -30
  38. package/lib/MediaSession/TurnConstants.js.map +1 -1
  39. package/lib/MediaSubscriber.d.ts +11 -11
  40. package/lib/MediaSubscriber.d.ts.map +1 -1
  41. package/lib/MediaSubscriber.js +236 -192
  42. package/lib/MediaSubscriber.js.map +1 -1
  43. package/lib/MediaUtils/Compatibility.d.ts +2 -1
  44. package/lib/MediaUtils/Compatibility.d.ts.map +1 -1
  45. package/lib/MediaUtils/Compatibility.js +130 -85
  46. package/lib/MediaUtils/Compatibility.js.map +1 -1
  47. package/lib/MediaUtils/MediaDomUtils.d.ts +3 -2
  48. package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -1
  49. package/lib/MediaUtils/MediaDomUtils.js +235 -174
  50. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  51. package/lib/MediaUtils/MediaTracer.js +9 -4
  52. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  53. package/lib/MediaUtils/index.d.ts +1 -0
  54. package/lib/MediaUtils/index.d.ts.map +1 -0
  55. package/lib/MediaUtils/index.js +16 -0
  56. package/lib/MediaUtils/index.js.map +1 -0
  57. package/lib/MultiParty/Contracts.d.ts +16 -0
  58. package/lib/MultiParty/Contracts.d.ts.map +1 -0
  59. package/lib/MultiParty/Contracts.js +6 -0
  60. package/lib/MultiParty/Contracts.js.map +1 -0
  61. package/lib/MultiParty/DetectWebRtcService.d.ts +16 -0
  62. package/lib/MultiParty/DetectWebRtcService.d.ts.map +1 -0
  63. package/lib/MultiParty/DetectWebRtcService.js +79 -0
  64. package/lib/MultiParty/DetectWebRtcService.js.map +1 -0
  65. package/lib/MultiParty/MediaCapabilitiesService.d.ts +23 -0
  66. package/lib/MultiParty/MediaCapabilitiesService.d.ts.map +1 -0
  67. package/lib/MultiParty/MediaCapabilitiesService.js +369 -0
  68. package/lib/MultiParty/MediaCapabilitiesService.js.map +1 -0
  69. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts +5 -0
  70. package/lib/MultiParty/MediaCapabilitiesUtils.d.ts.map +1 -0
  71. package/lib/MultiParty/MediaCapabilitiesUtils.js +305 -0
  72. package/lib/MultiParty/MediaCapabilitiesUtils.js.map +1 -0
  73. package/lib/MultiParty/MultiPartyService.d.ts +41 -0
  74. package/lib/MultiParty/MultiPartyService.d.ts.map +1 -0
  75. package/lib/MultiParty/MultiPartyService.js +72 -0
  76. package/lib/MultiParty/MultiPartyService.js.map +1 -0
  77. package/lib/MultiParty/MultiPartyServiceFactory.d.ts +3 -0
  78. package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -0
  79. package/lib/MultiParty/MultiPartyServiceFactory.js +21 -0
  80. package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -0
  81. package/lib/MultiParty/OpentokMultiPartyService.d.ts +29 -0
  82. package/lib/MultiParty/OpentokMultiPartyService.d.ts.map +1 -0
  83. package/lib/MultiParty/OpentokMultiPartyService.js +888 -0
  84. package/lib/MultiParty/OpentokMultiPartyService.js.map +1 -0
  85. package/lib/MultiParty/VideoLayoutType.d.ts +4 -0
  86. package/lib/MultiParty/VideoLayoutType.d.ts.map +1 -0
  87. package/lib/MultiParty/VideoLayoutType.js +13 -0
  88. package/lib/MultiParty/VideoLayoutType.js.map +1 -0
  89. package/lib/MultiParty/index.d.ts +4 -0
  90. package/lib/MultiParty/index.d.ts.map +1 -0
  91. package/lib/MultiParty/index.js +61 -0
  92. package/lib/MultiParty/index.js.map +1 -0
  93. package/lib/MultiParty/opentok.d.ts +503 -0
  94. package/lib/TechseeMediaStream.d.ts +6 -6
  95. package/lib/TechseeMediaStream.d.ts.map +1 -1
  96. package/lib/TechseeMediaStream.js +59 -53
  97. package/lib/TechseeMediaStream.js.map +1 -1
  98. package/lib/oldCode/constants.js +20 -15
  99. package/lib/oldCode/constants.js.map +1 -1
  100. package/lib/oldCode/event-emitter.js +45 -22
  101. package/lib/oldCode/event-emitter.js.map +1 -1
  102. package/lib/oldCode/index.js +48 -52
  103. package/lib/oldCode/index.js.map +1 -1
  104. package/lib/oldCode/opentok/session.js +261 -236
  105. package/lib/oldCode/opentok/session.js.map +1 -1
  106. package/lib/oldCode/opentok/stream.js +283 -269
  107. package/lib/oldCode/opentok/stream.js.map +1 -1
  108. package/lib/oldCode/publisher.js +96 -71
  109. package/lib/oldCode/publisher.js.map +1 -1
  110. package/lib/oldCode/service.js +294 -272
  111. package/lib/oldCode/service.js.map +1 -1
  112. package/lib/oldCode/session.js +82 -60
  113. package/lib/oldCode/session.js.map +1 -1
  114. package/lib/oldCode/stream.js +153 -125
  115. package/lib/oldCode/stream.js.map +1 -1
  116. package/lib/oldCode/subscriber.js +60 -35
  117. package/lib/oldCode/subscriber.js.map +1 -1
  118. package/lib/oldCode/tracer.d.ts +3 -2
  119. package/lib/oldCode/tracer.d.ts.map +1 -1
  120. package/lib/oldCode/tracer.js +181 -130
  121. package/lib/oldCode/tracer.js.map +1 -1
  122. package/lib/oldCode/utils/ImageFixer.js +67 -44
  123. package/lib/oldCode/utils/ImageFixer.js.map +1 -1
  124. package/lib/oldCode/webrtc/constants.js +102 -110
  125. package/lib/oldCode/webrtc/constants.js.map +1 -1
  126. package/lib/oldCode/webrtc/helper.js +176 -124
  127. package/lib/oldCode/webrtc/helper.js.map +1 -1
  128. package/lib/oldCode/webrtc/session-kms.js +408 -393
  129. package/lib/oldCode/webrtc/session-kms.js.map +1 -1
  130. package/lib/oldCode/webrtc/session-loopback.js +245 -227
  131. package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
  132. package/lib/oldCode/webrtc/session-turn.js +705 -658
  133. package/lib/oldCode/webrtc/session-turn.js.map +1 -1
  134. package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
  135. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
  136. package/lib/oldCode/webrtc/session.js +12 -6
  137. package/lib/oldCode/webrtc/session.js.map +1 -1
  138. package/lib/oldCode/webrtc/stream.js +526 -504
  139. package/lib/oldCode/webrtc/stream.js.map +1 -1
  140. package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
  141. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
  142. package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
  143. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
  144. package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
  145. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
  146. package/lib/qos/raw-qos.js +348 -273
  147. package/lib/qos/raw-qos.js.map +1 -1
  148. package/lib/webrtc-ie-shim.js +3386 -2985
  149. package/lib/webrtc-ie-shim.js.map +1 -1
  150. package/package.json +54 -42
@@ -1,39 +1,53 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- exports.__esModule = true;
4
- exports.KMSWebRTCSession = 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
- var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.KMSWebRTCSession = void 0;
7
9
 
8
- var _session = require('../session');
10
+ var _session = require("../session");
9
11
 
10
- var _publisher = require('../publisher');
12
+ var _publisher = require("../publisher");
11
13
 
12
- var _stream = require('./stream');
14
+ var _stream = require("./stream");
13
15
 
14
- var _socket = require('socket.io-client');
16
+ var io = _interopRequireWildcard(require("socket.io-client"));
15
17
 
16
- var io = _interopRequireWildcard(_socket);
18
+ var _jsCookie = _interopRequireDefault(require("js-cookie"));
17
19
 
18
- var _jsCookie = require('js-cookie');
20
+ var _tsEnvironmentDetect = require("@techsee/techsee-common/lib/helpers/ts-environment-detect");
19
21
 
20
- var _jsCookie2 = _interopRequireDefault(_jsCookie);
22
+ var _constants = require("./constants");
21
23
 
22
- var _tsEnvironmentDetect = require('@techsee/techsee-common/lib/helpers/ts-environment-detect');
24
+ var _helper = require("./helper");
23
25
 
24
- var _constants = require('./constants');
26
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
27
 
26
- var _helper = require('./helper');
28
+ 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); }
27
29
 
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
30
+ 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; }
31
31
 
32
32
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
33
 
34
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
34
+ 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); } }
35
+
36
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
37
+
38
+ 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); }
39
+
40
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
41
+
42
+ 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); }; }
43
+
44
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
45
+
46
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
47
 
36
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
48
+ 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; } }
49
+
50
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
37
51
 
38
52
  var isIE11 = new _tsEnvironmentDetect.TsEnvironmentDetect().isIE11();
39
53
 
@@ -51,217 +65,238 @@ var _require = require('kurento-utils'),
51
65
  *
52
66
  * @see TsMediaSession
53
67
  */
54
- var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
55
- _inherits(KMSWebRTCSession, _TsMediaSession);
56
-
57
- function KMSWebRTCSession(_ref) {
58
- var credentials = _ref.credentials,
59
- isMobile = _ref.isMobile,
60
- resolution = _ref.resolution,
61
- deviceOpts = _ref.deviceOpts;
62
-
63
- _classCallCheck(this, KMSWebRTCSession);
64
-
65
- var _this = _possibleConstructorReturn(this, _TsMediaSession.call(this));
66
-
67
- _this._credentials = credentials;
68
- _this._isMobile = isMobile;
69
- _this._resolution = resolution;
70
- _this._deviceOpts = deviceOpts;
71
-
72
- var iceServers = credentials.ice.map(function (item) {
73
- return {
74
- urls: item.url,
75
- username: item.login,
76
- credential: item.password
77
- };
78
- });
79
-
80
- _this._configuration = {
81
- iceServers: iceServers,
68
+ var KMSWebRTCSession = /*#__PURE__*/function (_TsMediaSession) {
69
+ _inherits(KMSWebRTCSession, _TsMediaSession);
70
+
71
+ var _super = _createSuper(KMSWebRTCSession);
72
+
73
+ function KMSWebRTCSession(_ref) {
74
+ var _this;
75
+
76
+ var credentials = _ref.credentials,
77
+ isMobile = _ref.isMobile,
78
+ resolution = _ref.resolution,
79
+ deviceOpts = _ref.deviceOpts;
80
+
81
+ _classCallCheck(this, KMSWebRTCSession);
82
+
83
+ _this = _super.call(this);
84
+ _this._credentials = credentials;
85
+ _this._isMobile = isMobile;
86
+ _this._resolution = resolution;
87
+ _this._deviceOpts = deviceOpts;
88
+ var iceServers = credentials.ice.map(function (item) {
89
+ return {
90
+ urls: item.url,
91
+ username: item.login,
92
+ credential: item.password
93
+ };
94
+ });
95
+ _this._configuration = {
96
+ iceServers: iceServers,
97
+ iceTransportPolicy: 'relay'
98
+ };
99
+ /**
100
+ * Socket.io connection to the signaling server
101
+ *
102
+ * @private
103
+ * @member { Object }
104
+ */
82
105
 
83
- iceTransportPolicy: 'relay'
84
- };
106
+ _this._socket = null;
107
+ /**
108
+ * RTCPeerConnection to the media server.
109
+ *
110
+ * For now kurento-utils is used for connection establishment.
111
+ *
112
+ * @private
113
+ * @member { Object }
114
+ */
85
115
 
86
- /**
87
- * Socket.io connection to the signaling server
88
- *
89
- * @private
90
- * @member { Object }
91
- */
92
- _this._socket = null;
93
-
94
- /**
95
- * RTCPeerConnection to the media server.
96
- *
97
- * For now kurento-utils is used for connection establishment.
98
- *
99
- * @private
100
- * @member { Object }
101
- */
102
- _this._pc = null;
103
- return _this;
116
+ _this._pc = null;
117
+ return _this;
118
+ }
119
+ /**
120
+ * Id of the session.
121
+ *
122
+ * @member { String }
123
+ *
124
+ * @type { String }
125
+ */
126
+
127
+
128
+ _createClass(KMSWebRTCSession, [{
129
+ key: "id",
130
+ get: function get() {
131
+ return this._credentials.sessionId;
104
132
  }
105
-
106
133
  /**
107
- * Id of the session.
134
+ * PipelineType of the session.
108
135
  *
109
136
  * @member { String }
110
137
  *
111
138
  * @type { String }
112
139
  */
113
140
 
114
-
115
- KMSWebRTCSession.prototype._connectSocket = function _connectSocket(url) {
116
- var _this2 = this;
117
-
118
- return new Promise(function (resolve, reject) {
119
- var socket = io.connect(url, { forceNew: true });
120
-
121
- var done = _.once(function (err) {
122
- err ? reject(err) : resolve();
123
- });
124
-
125
- //
126
- // When connection is established
127
- //
128
- socket.once('connect', function () {
129
- return done();
130
- });
131
- //
132
- // errorOccured is ts-media-client signal
133
- //
134
- socket.on(_constants.SOCKET_EVENTS.INCOMING.ERROR, done);
135
- //
136
- // And these 2 are socket.io connection failed events
137
- //
138
- socket.on('connect_error', done);
139
- socket.on('connect_timeout', done);
140
-
141
- _this2._socket = socket;
141
+ }, {
142
+ key: "pipelineType",
143
+ get: function get() {
144
+ return this._credentials.pipelineType || _constants.PIPELINE_TYPES.AUDIO_VIDEO_TO_SUBSCRIBERS;
145
+ }
146
+ }, {
147
+ key: "_connectSocket",
148
+ value: function _connectSocket(url) {
149
+ var _this2 = this;
150
+
151
+ return new Promise(function (resolve, reject) {
152
+ var socket = io.connect(url, {
153
+ forceNew: true
142
154
  });
143
- };
144
155
 
145
- KMSWebRTCSession.prototype._setupConnection = function _setupConnection(pc, sessionId) {
146
- var _this3 = this;
156
+ var done = _.once(function (err) {
157
+ err ? reject(err) : resolve();
158
+ }); //
159
+ // When connection is established
160
+ //
147
161
 
148
- var uid = _jsCookie2.default.get(_constants.COOKIES.UID);
149
- var clientType = this._isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER;
150
162
 
151
- return new Promise(function (resolve, reject) {
152
- _this3._socket.on(_constants.SOCKET_EVENTS.INCOMING.PIPELINE_DESTROYED, function () {
153
- _this3.destroyed = true;
163
+ socket.once('connect', function () {
164
+ return done();
165
+ }); //
166
+ // errorOccured is ts-media-client signal
167
+ //
154
168
 
155
- _this3._socket.off();
156
- _this3._socket.disconnect();
169
+ socket.on(_constants.SOCKET_EVENTS.INCOMING.ERROR, done); //
170
+ // And these 2 are socket.io connection failed events
171
+ //
157
172
 
158
- _this3.emit(_session.EVENTS.DISCONNECTED, {
159
- reason: 'Client disconnected'
160
- });
161
- });
173
+ socket.on('connect_error', done);
174
+ socket.on('connect_timeout', done);
175
+ _this2._socket = socket;
176
+ });
177
+ }
178
+ }, {
179
+ key: "_setupConnection",
180
+ value: function _setupConnection(pc, sessionId) {
181
+ var _this3 = this;
162
182
 
163
- pc.generateOffer(function (error, offer) {
164
- if (error) {
165
- return reject(error);
166
- }
183
+ var uid = _jsCookie["default"].get(_constants.COOKIES.UID);
167
184
 
168
- _this3._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.JOIN_PIPELINE, {
169
- uid: uid,
170
- sessionId: sessionId,
171
- clientType: clientType,
185
+ var clientType = this._isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER;
186
+ return new Promise(function (resolve, reject) {
187
+ _this3._socket.on(_constants.SOCKET_EVENTS.INCOMING.PIPELINE_DESTROYED, function () {
188
+ _this3.destroyed = true;
172
189
 
173
- pipelineType: _this3.pipelineType,
174
- sdpOffer: offer
175
- });
190
+ _this3._socket.off();
176
191
 
177
- resolve();
178
- });
192
+ _this3._socket.disconnect();
193
+
194
+ _this3.emit(_session.EVENTS.DISCONNECTED, {
195
+ reason: 'Client disconnected'
196
+ });
179
197
  });
180
- };
181
198
 
182
- KMSWebRTCSession.prototype._getPeerType = function _getPeerType(constraints, isMobile) {
183
- if (isMobile || constraints.audio) {
184
- return _constants.PEER_CONNECTION_TYPES.SEND_RECV;
185
- }
199
+ pc.generateOffer(function (error, offer) {
200
+ if (error) {
201
+ return reject(error);
202
+ }
186
203
 
187
- return _constants.PEER_CONNECTION_TYPES.RECV_ONLY;
188
- };
204
+ _this3._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.JOIN_PIPELINE, {
205
+ uid: uid,
206
+ sessionId: sessionId,
207
+ clientType: clientType,
208
+ pipelineType: _this3.pipelineType,
209
+ sdpOffer: offer
210
+ });
189
211
 
190
- KMSWebRTCSession.prototype._connectRTCPeer = function _connectRTCPeer(_ref2) {
191
- var _this4 = this;
212
+ resolve();
213
+ });
214
+ });
215
+ }
216
+ }, {
217
+ key: "_getPeerType",
218
+ value: function _getPeerType(constraints, isMobile) {
219
+ if (isMobile || constraints.audio) {
220
+ return _constants.PEER_CONNECTION_TYPES.SEND_RECV;
221
+ }
222
+
223
+ return _constants.PEER_CONNECTION_TYPES.RECV_ONLY;
224
+ }
225
+ }, {
226
+ key: "_connectRTCPeer",
227
+ value: function _connectRTCPeer(_ref2) {
228
+ var _this4 = this;
229
+
230
+ var constraints = _ref2.constraints,
231
+ configuration = _ref2.configuration,
232
+ sessionId = _ref2.sessionId,
233
+ isMobile = _ref2.isMobile;
234
+ return new Promise(function (resolve, reject) {
235
+ var done = _.once(function (err) {
236
+ err ? reject(err) : resolve();
237
+ });
192
238
 
193
- var constraints = _ref2.constraints,
194
- configuration = _ref2.configuration,
195
- sessionId = _ref2.sessionId,
196
- isMobile = _ref2.isMobile;
239
+ var peerConnectionType = _this4._getPeerType(constraints, isMobile);
197
240
 
198
- return new Promise(function (resolve, reject) {
199
- var done = _.once(function (err) {
200
- err ? reject(err) : resolve();
241
+ var pc = WebRtcPeer[peerConnectionType]({
242
+ configuration: configuration,
243
+ mediaConstraints: constraints,
244
+ onicecandidate: function onicecandidate(candidate) {
245
+ _this4._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
246
+ sessionId: sessionId,
247
+ candidate: candidate,
248
+ clientType: isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER
249
+ });
250
+ }
251
+ }, function (error) {
252
+ if (error) {
253
+ return done(error);
254
+ }
255
+
256
+ _this4._socket.on(_constants.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, function (_ref3) {
257
+ var sdpAnswer = _ref3.sdpAnswer,
258
+ uid = _ref3.uid;
259
+
260
+ _jsCookie["default"].set(_constants.COOKIES.UID, uid);
261
+
262
+ pc.processAnswer(sdpAnswer, function (error) {
263
+ if (error) {
264
+ return done(error);
265
+ }
201
266
  });
202
- var peerConnectionType = _this4._getPeerType(constraints, isMobile);
203
-
204
- var pc = WebRtcPeer[peerConnectionType]({
205
- configuration: configuration,
206
-
207
- mediaConstraints: constraints,
208
- onicecandidate: function onicecandidate(candidate) {
209
- _this4._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.ICE_CANDIDATE, {
210
- sessionId: sessionId,
211
-
212
- candidate: candidate,
213
- clientType: isMobile ? _constants.CLIENT_TYPES.PUBLISHER : _constants.CLIENT_TYPES.SUBSCRIBER
214
- });
215
- }
216
- }, function (error) {
217
- if (error) {
218
- return done(error);
219
- }
220
-
221
- _this4._socket.on(_constants.SOCKET_EVENTS.INCOMING.JOIN_RESPONSE, function (_ref3) {
222
- var sdpAnswer = _ref3.sdpAnswer,
223
- uid = _ref3.uid;
224
-
225
- _jsCookie2.default.set(_constants.COOKIES.UID, uid);
226
267
 
227
- pc.processAnswer(sdpAnswer, function (error) {
228
- if (error) {
229
- return done(error);
230
- }
231
- });
268
+ _this4.emit(_session.EVENTS.CONNECTED);
232
269
 
233
- _this4.emit(_session.EVENTS.CONNECTED);
270
+ _this4._socket.off(_constants.SOCKET_EVENTS.INCOMING.ERROR);
234
271
 
235
- _this4._socket.off(_constants.SOCKET_EVENTS.INCOMING.ERROR);
236
- _this4._socket.off('connect_error');
237
- _this4._socket.off('connect_timeout');
272
+ _this4._socket.off('connect_error');
238
273
 
239
- return done();
240
- });
274
+ _this4._socket.off('connect_timeout');
241
275
 
242
- _this4._socket.on(_constants.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, function (_ref4) {
243
- var candidate = _ref4.candidate;
276
+ return done();
277
+ });
244
278
 
245
- pc.addIceCandidate(candidate);
246
- });
279
+ _this4._socket.on(_constants.SOCKET_EVENTS.INCOMING.ICE_CANDIDATE, function (_ref4) {
280
+ var candidate = _ref4.candidate;
281
+ pc.addIceCandidate(candidate);
282
+ });
247
283
 
248
- _this4._setupConnection(pc, sessionId).then(done).catch(done);
249
- });
250
-
251
- _this4._pc = pc;
284
+ _this4._setupConnection(pc, sessionId).then(done)["catch"](done);
252
285
  });
253
- };
254
-
255
- KMSWebRTCSession.prototype._setTrackStateTo = function _setTrackStateTo(state) {
256
- return function (track) {
257
- if (track.setEnabled) {
258
- track.setEnabled(state);
259
- } else {
260
- track.enabled = state;
261
- }
262
- };
263
- };
264
-
286
+ _this4._pc = pc;
287
+ });
288
+ }
289
+ }, {
290
+ key: "_setTrackStateTo",
291
+ value: function _setTrackStateTo(state) {
292
+ return function (track) {
293
+ if (track.setEnabled) {
294
+ track.setEnabled(state);
295
+ } else {
296
+ track.enabled = state;
297
+ }
298
+ };
299
+ }
265
300
  /**
266
301
  * Establish socket and peer connection to the media server.
267
302
  *
@@ -271,44 +306,42 @@ var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
271
306
  * @fires SESSION_EVENTS#CONNECTED
272
307
  */
273
308
 
309
+ }, {
310
+ key: "connect",
311
+ value: function connect() {
312
+ var _this5 = this;
274
313
 
275
- KMSWebRTCSession.prototype.connect = function connect() {
276
- var _this5 = this;
277
-
278
- return this._connectSocket(this._credentials.url).then(function () {
279
- return (0, _helper.getMediaConstraints)({
280
- resolution: _this5._resolution,
281
- deviceOpts: _this5._deviceOpts
282
- });
283
- }).then(function (constraints) {
284
- // streaming from dashboard is not supported and we
285
- // don't want to access the camera without a reason
286
- if (!_this5._isMobile && constraints.video) {
287
- delete constraints.video;
288
- }
289
-
290
- return _this5._connectRTCPeer({
291
- constraints: constraints,
292
-
293
- configuration: _this5._configuration,
294
- sessionId: _this5._credentials.sessionId,
295
- isMobile: _this5._isMobile
296
- });
297
- }).then(function () {
298
- _this5._pc.peerConnection.getLocalStreams().forEach(function (stream) {
299
- stream.getTracks().forEach(_this5._setTrackStateTo(false));
300
- });
301
-
302
- _this5._pc.peerConnection.onaddstream = function (_ref5) {
303
- var stream = _ref5.stream;
304
-
305
- var tsStream = new _stream.TsWebRTCStream(_this5, stream);
314
+ return this._connectSocket(this._credentials.url).then(function () {
315
+ return (0, _helper.getMediaConstraints)({
316
+ resolution: _this5._resolution,
317
+ deviceOpts: _this5._deviceOpts
318
+ });
319
+ }).then(function (constraints) {
320
+ // streaming from dashboard is not supported and we
321
+ // don't want to access the camera without a reason
322
+ if (!_this5._isMobile && constraints.video) {
323
+ delete constraints.video;
324
+ }
306
325
 
307
- _this5.emit(_session.EVENTS.STREAM_CREATED, tsStream);
308
- };
326
+ return _this5._connectRTCPeer({
327
+ constraints: constraints,
328
+ configuration: _this5._configuration,
329
+ sessionId: _this5._credentials.sessionId,
330
+ isMobile: _this5._isMobile
331
+ });
332
+ }).then(function () {
333
+ _this5._pc.peerConnection.getLocalStreams().forEach(function (stream) {
334
+ stream.getTracks().forEach(_this5._setTrackStateTo(false));
309
335
  });
310
- };
311
336
 
337
+ _this5._pc.peerConnection.onaddstream = function (_ref5) {
338
+ var stream = _ref5.stream;
339
+ var tsStream = new _stream.TsWebRTCStream(_this5, stream);
340
+
341
+ _this5.emit(_session.EVENTS.STREAM_CREATED, tsStream);
342
+ };
343
+ });
344
+ }
312
345
  /**
313
346
  * Close all media streams, disconnect RTCPeerConnection and socket.io
314
347
  *
@@ -318,30 +351,33 @@ var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
318
351
  * @fires SESSION_EVENTS#DISCONNECTED
319
352
  */
320
353
 
354
+ }, {
355
+ key: "disconnect",
356
+ value: function disconnect() {
357
+ var _this6 = this;
321
358
 
322
- KMSWebRTCSession.prototype.disconnect = function disconnect() {
323
- var _this6 = this;
324
-
325
- return Promise.resolve().then(function () {
326
- if (_this6.destroyed) {
327
- return null;
328
- }
359
+ return Promise.resolve().then(function () {
360
+ if (_this6.destroyed) {
361
+ return null;
362
+ }
329
363
 
330
- _this6._pc.peerConnection.close();
364
+ _this6._pc.peerConnection.close();
331
365
 
332
- _this6._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.DESTROY_PIPELINE, {
333
- sessionId: _this6._credentials.sessionId
334
- });
335
- _this6._socket.disconnect();
366
+ _this6._socket.emit(_constants.SOCKET_EVENTS.OUTGOING.DESTROY_PIPELINE, {
367
+ sessionId: _this6._credentials.sessionId
368
+ });
336
369
 
337
- var event = { reason: 'disconnected' };
370
+ _this6._socket.disconnect();
338
371
 
339
- _this6.emit(_session.EVENTS.DISCONNECTED, event);
372
+ var event = {
373
+ reason: 'disconnected'
374
+ };
340
375
 
341
- return event;
342
- });
343
- };
376
+ _this6.emit(_session.EVENTS.DISCONNECTED, event);
344
377
 
378
+ return event;
379
+ });
380
+ }
345
381
  /**
346
382
  * Create new TsMediaPublisher instance
347
383
  *
@@ -362,54 +398,48 @@ var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
362
398
  * @see TsMediaPublisher
363
399
  */
364
400
 
365
-
366
- KMSWebRTCSession.prototype.createPublisher = function createPublisher(target, params) {
367
- var _this7 = this;
368
-
369
- if (!params) {
370
- params = target;
371
- target = null;
372
- }
373
-
374
- return Promise.resolve().then(function () {
375
- //
376
- // Get media streams that were created on session initialization
377
- //
378
- var mediaStream = _this7._pc.peerConnection.getLocalStreams()[0];
379
- //
380
- // Get tracks that are related to the publisher (audio or video)
381
- //
382
- var tracks = _this7._pc.peerConnection.getLocalStreams().reduce(function (result, mediaStream) {
383
- mediaStream.getTracks().filter(function (track) {
384
- return track.kind === 'video' && params.videoDevice || track.kind === 'audio' && params.audioDevice;
385
- }).forEach(function (track) {
386
- return result.push(track);
387
- });
388
-
389
- return result;
390
- }, []);
391
-
392
- var tsstream = new _stream.TsWebRTCStream(_this7, mediaStream, params.name);
393
-
394
- tsstream.remote = false;
395
-
396
- var publisher = new _publisher.TsMediaPublisher(_this7, {
397
- stream: tsstream,
398
- tracks: tracks,
399
- videoParams: params.videoParams,
400
-
401
- videoHeight: tsstream.videoDimensions.height,
402
- videoWidth: tsstream.videoDimensions.width,
403
-
404
- _target: target
405
- });
406
-
407
- tsstream.publisher = publisher;
408
-
409
- return publisher;
401
+ }, {
402
+ key: "createPublisher",
403
+ value: function createPublisher(target, params) {
404
+ var _this7 = this;
405
+
406
+ if (!params) {
407
+ params = target;
408
+ target = null;
409
+ }
410
+
411
+ return Promise.resolve().then(function () {
412
+ //
413
+ // Get media streams that were created on session initialization
414
+ //
415
+ var mediaStream = _this7._pc.peerConnection.getLocalStreams()[0]; //
416
+ // Get tracks that are related to the publisher (audio or video)
417
+ //
418
+
419
+
420
+ var tracks = _this7._pc.peerConnection.getLocalStreams().reduce(function (result, mediaStream) {
421
+ mediaStream.getTracks().filter(function (track) {
422
+ return track.kind === 'video' && params.videoDevice || track.kind === 'audio' && params.audioDevice;
423
+ }).forEach(function (track) {
424
+ return result.push(track);
425
+ });
426
+ return result;
427
+ }, []);
428
+
429
+ var tsstream = new _stream.TsWebRTCStream(_this7, mediaStream, params.name);
430
+ tsstream.remote = false;
431
+ var publisher = new _publisher.TsMediaPublisher(_this7, {
432
+ stream: tsstream,
433
+ tracks: tracks,
434
+ videoParams: params.videoParams,
435
+ videoHeight: tsstream.videoDimensions.height,
436
+ videoWidth: tsstream.videoDimensions.width,
437
+ _target: target
410
438
  });
411
- };
412
-
439
+ tsstream.publisher = publisher;
440
+ return publisher;
441
+ });
442
+ }
413
443
  /**
414
444
  * Publish stream from previously create TsMediaPublisher instance.
415
445
  *
@@ -428,77 +458,80 @@ var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
428
458
  * @see TsMediaPublisher#publish
429
459
  */
430
460
 
461
+ }, {
462
+ key: "publish",
463
+ value: function publish(publisher) {
464
+ var _this8 = this;
431
465
 
432
- KMSWebRTCSession.prototype.publish = function publish(publisher) {
433
- var _this8 = this;
466
+ return Promise.resolve().then(function () {
467
+ publisher.emit(_publisher.EVENTS.STREAM_CREATED, publisher.stream);
434
468
 
435
- return Promise.resolve().then(function () {
436
- publisher.emit(_publisher.EVENTS.STREAM_CREATED, publisher.stream);
437
- _this8.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
438
- stream: publisher.stream,
439
- property: 'hasVideo',
440
- value: publisher.stream.hasVideo
441
- });
442
- _this8.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
443
- stream: publisher.stream,
444
- property: 'hasAudio',
445
- value: publisher.stream.hasAudio
446
- });
469
+ _this8.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
470
+ stream: publisher.stream,
471
+ property: 'hasVideo',
472
+ value: publisher.stream.hasVideo
473
+ });
447
474
 
448
- if (publisher._target) {
449
- //
450
- // New video element where publishing video stream will be rendered
451
- //
452
- var video = document.createElement('video');
453
-
454
- if (!isIE11) {
455
- video.src = URL.createObjectURL(publisher.stream._mediaStream);
456
- }
457
-
458
- video.playsInline = true;
459
- video.autoplay = true;
460
-
461
- if (isIE11) {
462
- publisher._target.appendChild(video);
463
- publisher._element = attachMediaStream(video, publisher.stream._mediaStream);
464
- }
465
-
466
- var params = _.assign({}, {
467
- fitMode: 'contain',
468
- insertMode: 'append',
469
- mirror: false,
470
- resolution: '480x640',
471
- width: '100%',
472
- height: '100%'
473
- }, publisher.videoParams);
474
-
475
- var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
476
- var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
477
-
478
- _.assign((isIE11 ? publisher._element : video).style, {
479
- height: elementHeight,
480
- width: elementWidth,
481
-
482
- position: 'relative',
483
- 'object-fit': params.fitMode
484
- });
485
-
486
- if (!isIE11) {
487
- publisher._target.appendChild(video);
488
- publisher._element = video;
489
- }
490
-
491
- publisher.stream.setupDimensionsListener(video);
492
- }
493
-
494
- //
495
- // Enable (unpause) all media tracks related to publisher.
496
- // They are sending data to the server from this moment.
497
- //
498
- publisher.tracks.forEach(_this8._setTrackStateTo(true));
475
+ _this8.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
476
+ stream: publisher.stream,
477
+ property: 'hasAudio',
478
+ value: publisher.stream.hasAudio
499
479
  });
500
- };
501
480
 
481
+ if (publisher._target) {
482
+ //
483
+ // New video element where publishing video stream will be rendered
484
+ //
485
+ var video = document.createElement('video');
486
+
487
+ if (!isIE11) {
488
+ video.src = URL.createObjectURL(publisher.stream._mediaStream);
489
+ }
490
+
491
+ video.playsInline = true;
492
+ video.autoplay = true;
493
+
494
+ if (isIE11) {
495
+ publisher._target.appendChild(video);
496
+
497
+ publisher._element = attachMediaStream(video, publisher.stream._mediaStream);
498
+ }
499
+
500
+ var params = _.assign({}, {
501
+ fitMode: 'contain',
502
+ insertMode: 'append',
503
+ mirror: false,
504
+ resolution: '480x640',
505
+ width: '100%',
506
+ height: '100%'
507
+ }, publisher.videoParams);
508
+
509
+ var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
510
+ var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
511
+
512
+ _.assign((isIE11 ? publisher._element : video).style, {
513
+ height: elementHeight,
514
+ width: elementWidth,
515
+ position: 'relative',
516
+ 'object-fit': params.fitMode
517
+ });
518
+
519
+ if (!isIE11) {
520
+ publisher._target.appendChild(video);
521
+
522
+ publisher._element = video;
523
+ }
524
+
525
+ publisher.stream.setupDimensionsListener(video);
526
+ } //
527
+ // Enable (unpause) all media tracks related to publisher.
528
+ // They are sending data to the server from this moment.
529
+ //
530
+
531
+
532
+ publisher.tracks.forEach(_this8._setTrackStateTo(true));
533
+ });
534
+ }
502
535
  /**
503
536
  * Unpublish stream and destroy publisher's view.
504
537
  *
@@ -515,44 +548,26 @@ var KMSWebRTCSession = exports.KMSWebRTCSession = function (_TsMediaSession) {
515
548
  * @see TsMediaPublisher#destroy
516
549
  */
517
550
 
551
+ }, {
552
+ key: "destroyPublisher",
553
+ value: function destroyPublisher(publisher) {
554
+ var _this9 = this;
518
555
 
519
- KMSWebRTCSession.prototype.destroyPublisher = function destroyPublisher(publisher) {
520
- var _this9 = this;
521
-
522
- return new Promise(function (resolve) {
523
- publisher.tracks.forEach(_this9._setTrackStateTo(false));
524
-
525
- if (publisher._element) {
526
- publisher._element.remove();
527
- }
556
+ return new Promise(function (resolve) {
557
+ publisher.tracks.forEach(_this9._setTrackStateTo(false));
528
558
 
529
- publisher.emit(_publisher.EVENTS.DESTROYED);
530
-
531
- return resolve();
532
- });
533
- };
534
-
535
- _createClass(KMSWebRTCSession, [{
536
- key: 'id',
537
- get: function get() {
538
- return this._credentials.sessionId;
559
+ if (publisher._element) {
560
+ publisher._element.remove();
539
561
  }
540
562
 
541
- /**
542
- * PipelineType of the session.
543
- *
544
- * @member { String }
545
- *
546
- * @type { String }
547
- */
548
-
549
- }, {
550
- key: 'pipelineType',
551
- get: function get() {
552
- return this._credentials.pipelineType || _constants.PIPELINE_TYPES.AUDIO_VIDEO_TO_SUBSCRIBERS;
553
- }
554
- }]);
563
+ publisher.emit(_publisher.EVENTS.DESTROYED);
564
+ return resolve();
565
+ });
566
+ }
567
+ }]);
555
568
 
556
- return KMSWebRTCSession;
569
+ return KMSWebRTCSession;
557
570
  }(_session.TsMediaSession);
571
+
572
+ exports.KMSWebRTCSession = KMSWebRTCSession;
558
573
  //# sourceMappingURL=session-kms.js.map