@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,38 +1,55 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- exports.__esModule = true;
4
- exports.TsWebRTCStream = exports.EVENTS = 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
+ Object.defineProperty(exports, "EVENTS", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _stream.EVENTS;
12
+ }
13
+ });
14
+ exports.TsWebRTCStream = void 0;
7
15
 
8
- var _stream = require('../stream');
16
+ var _stream = require("../stream");
9
17
 
10
- var _session = require('../session');
18
+ var _session = require("../session");
11
19
 
12
- var _subscriber = require('../subscriber');
20
+ var _subscriber = require("../subscriber");
13
21
 
14
- var _constants = require('./constants');
22
+ var _constants = require("./constants");
15
23
 
16
- var _tsEnvironmentDetect = require('@techsee/techsee-common/lib/helpers/ts-environment-detect');
24
+ var _tsEnvironmentDetect = require("@techsee/techsee-common/lib/helpers/ts-environment-detect");
17
25
 
18
- var _retryWithTimeout = require('@techsee/techsee-common/lib/core/retry-with-timeout');
26
+ var _retryWithTimeout = require("@techsee/techsee-common/lib/core/retry-with-timeout");
19
27
 
20
- var _tracer = require('../tracer');
28
+ var _tracer = require("../tracer");
21
29
 
22
30
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
31
 
24
- 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; }
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); } }
25
33
 
26
- 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; }
34
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
27
35
 
28
- exports.EVENTS = _stream.EVENTS;
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); }
29
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); }
30
49
 
31
50
  var TORCH_DELAY = 1500;
32
51
  var isIE11 = new _tsEnvironmentDetect.TsEnvironmentDetect().isIE11();
33
-
34
52
  var tracer = (0, _tracer.getTracer)();
35
-
36
53
  /**
37
54
  * WebRTC-specific implementation of TsMediaStream.
38
55
  *
@@ -45,87 +62,137 @@ var tracer = (0, _tracer.getTracer)();
45
62
  * @see TsMediaStream
46
63
  */
47
64
 
48
- var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
49
- _inherits(TsWebRTCStream, _TsMediaStream);
50
-
51
- function TsWebRTCStream(session, mediaStream, name, isRemote, videoTrackSettings) {
52
- _classCallCheck(this, TsWebRTCStream);
53
-
54
- //In TurnWebRtcSessionV2, we keep connection on instance of stream.
55
- var _this = _possibleConstructorReturn(this, _TsMediaStream.call(this, mediaStream.id, session, isRemote, videoTrackSettings));
56
-
57
- _this.peerConnection = null;
58
-
59
- _this._torchDelayTimeOut = null;
60
- _this._torchOffTimeOut = null;
61
-
62
- /**
63
- * Browser's native media stream
64
- *
65
- * @public
66
- * @member { Object }
67
- *
68
- * {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream API}
69
- */
70
- _this._mediaStream = mediaStream;
71
-
72
- /**
73
- * Instance of TsWebRTCSession
74
- *
75
- * @private
76
- * @member { Object }
77
- *
78
- * @see TsWebRTCSession
79
- */
80
- _this._session = session;
81
-
82
- _this._name = name;
83
-
84
- if (!_this._name) {
85
- if (_this.hasVideo) {
86
- if (!_this._session._isMobile) {
87
- _this._name = _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_VIDEO_STREAM;
88
- }
89
- } else if (_this.hasAudio) {
90
- if (_this._session._isMobile) {
91
- _this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM;
92
- } else {
93
- _this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM;
94
- }
95
- }
96
- }
65
+ var TsWebRTCStream = /*#__PURE__*/function (_TsMediaStream) {
66
+ _inherits(TsWebRTCStream, _TsMediaStream);
97
67
 
98
- if (!_this._name) {
99
- _this._name = Math.random().toString();
100
- }
68
+ var _super = _createSuper(TsWebRTCStream);
101
69
 
102
- // TODO I think this will never be emitted, as both app/mobile call session.off() before they call session.disconnect(). And we call the destroy elsewhere
103
- // TODO Need to make sure that it's always the case, especially for IOS
104
- session.on(_session.EVENTS.DISCONNECTED, function () {
105
- if (_this.publisher) {
106
- _this.publisher.destroy();
107
- }
70
+ function TsWebRTCStream(session, mediaStream, name, isRemote, videoTrackSettings) {
71
+ var _this;
108
72
 
109
- if (_this.subscriber) {
110
- _this.subscriber.destroy();
111
- }
112
- });
113
- return _this;
73
+ _classCallCheck(this, TsWebRTCStream);
74
+
75
+ _this = _super.call(this, mediaStream.id, session, isRemote, videoTrackSettings); //In TurnWebRtcSessionV2, we keep connection on instance of stream.
76
+
77
+ _this.peerConnection = null;
78
+ _this._torchDelayTimeOut = null;
79
+ _this._torchOffTimeOut = null;
80
+ /**
81
+ * Browser's native media stream
82
+ *
83
+ * @public
84
+ * @member { Object }
85
+ *
86
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream API}
87
+ */
88
+
89
+ _this._mediaStream = mediaStream;
90
+ /**
91
+ * Instance of TsWebRTCSession
92
+ *
93
+ * @private
94
+ * @member { Object }
95
+ *
96
+ * @see TsWebRTCSession
97
+ */
98
+
99
+ _this._session = session;
100
+ _this._name = name;
101
+
102
+ if (!_this._name) {
103
+ if (_this.hasVideo) {
104
+ if (!_this._session._isMobile) {
105
+ _this._name = _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_VIDEO_STREAM;
106
+ }
107
+ } else if (_this.hasAudio) {
108
+ if (_this._session._isMobile) {
109
+ _this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM;
110
+ } else {
111
+ _this._name = _this.remote ? _constants.DEFAULT_STREAM_NAMES.MOBILE_CLIENT_AUDIO_STREAM : _constants.DEFAULT_STREAM_NAMES.DASHBOARD_AUDIO_STREAM;
112
+ }
113
+ }
114
114
  }
115
115
 
116
+ if (!_this._name) {
117
+ _this._name = Math.random().toString();
118
+ } // TODO I think this will never be emitted, as both app/mobile call session.off() before they call session.disconnect(). And we call the destroy elsewhere
119
+ // TODO Need to make sure that it's always the case, especially for IOS
120
+
121
+
122
+ session.on(_session.EVENTS.DISCONNECTED, function () {
123
+ if (_this.publisher) {
124
+ _this.publisher.destroy();
125
+ }
126
+
127
+ if (_this.subscriber) {
128
+ _this.subscriber.destroy();
129
+ }
130
+ });
131
+ return _this;
132
+ }
133
+ /**
134
+ * Unique id of the stream
135
+ *
136
+ * @member { String }
137
+ * @type { String }
138
+ */
139
+
140
+
141
+ _createClass(TsWebRTCStream, [{
142
+ key: "id",
143
+ get: function get() {
144
+ return this._mediaStream.id;
145
+ }
116
146
  /**
117
- * Unique id of the stream
147
+ * Unique name of the stream
118
148
  *
119
149
  * @member { String }
120
150
  * @type { String }
121
151
  */
122
152
 
153
+ }, {
154
+ key: "name",
155
+ get: function get() {
156
+ return this._name;
157
+ }
158
+ /**
159
+ * Whether or not stream has enabled video tracks
160
+ *
161
+ * @member { Boolean }
162
+ * @type { Boolean }
163
+ */
164
+
165
+ }, {
166
+ key: "hasVideo",
167
+ get: function get() {
168
+ var enabledVideoTracks = this._mediaStream.getVideoTracks().filter(function (track) {
169
+ return track.enabled;
170
+ });
171
+
172
+ return enabledVideoTracks.length > 0;
173
+ }
174
+ /**
175
+ * Whether or not stream has enabled audio tracks
176
+ *
177
+ * @member { Boolean }
178
+ * @type { Boolean }
179
+ */
123
180
 
124
- TsWebRTCStream.prototype._getPeerConnection = function _getPeerConnection() {
125
- // KMS store the peer connection as _pc, TURN store it as _lastPc
126
- return this.peerConnection || _.get(this._session, '_lastPc.peerConnection') || _.get(this._session, '_pc.peerConnection');
127
- };
181
+ }, {
182
+ key: "hasAudio",
183
+ get: function get() {
184
+ var enabledAudioTracks = this._mediaStream.getAudioTracks().filter(function (track) {
185
+ return track.enabled;
186
+ });
128
187
 
188
+ return enabledAudioTracks.length > 0;
189
+ }
190
+ }, {
191
+ key: "_getPeerConnection",
192
+ value: function _getPeerConnection() {
193
+ // KMS store the peer connection as _pc, TURN store it as _lastPc
194
+ return this.peerConnection || _.get(this._session, '_lastPc.peerConnection') || _.get(this._session, '_pc.peerConnection');
195
+ }
129
196
  /**
130
197
  * Publish or unpublish audio tracks.
131
198
  *
@@ -139,31 +206,31 @@ var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
139
206
  * @fires STREAM_EVENTS.PROPERTY_CHANGED
140
207
  */
141
208
 
142
-
143
- TsWebRTCStream.prototype.publishAudio = function publishAudio(publish) {
144
- this._mediaStream.getTracks().forEach(function (track) {
145
- if (track.kind === 'audio') {
146
- if (track.setEnabled) {
147
- track.setEnabled(publish);
148
- } else {
149
- track.enabled = publish;
150
- }
151
- }
152
- });
153
-
154
- this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
155
- stream: this,
156
- property: 'hasAudio',
157
- value: publish
158
- });
159
-
160
- this.emit(_stream.EVENTS.PROPERTY_CHANGED, {
161
- stream: this,
162
- property: 'hasAudio',
163
- value: publish
164
- });
165
- };
166
-
209
+ }, {
210
+ key: "publishAudio",
211
+ value: function publishAudio(publish) {
212
+ this._mediaStream.getTracks().forEach(function (track) {
213
+ if (track.kind === 'audio') {
214
+ if (track.setEnabled) {
215
+ track.setEnabled(publish);
216
+ } else {
217
+ track.enabled = publish;
218
+ }
219
+ }
220
+ });
221
+
222
+ this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
223
+ stream: this,
224
+ property: 'hasAudio',
225
+ value: publish
226
+ });
227
+
228
+ this.emit(_stream.EVENTS.PROPERTY_CHANGED, {
229
+ stream: this,
230
+ property: 'hasAudio',
231
+ value: publish
232
+ });
233
+ }
167
234
  /**
168
235
  * Publish or unpublish video tracks.
169
236
  *
@@ -176,25 +243,25 @@ var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
176
243
  * @fires SESSION_EVENTS.STREAM_PROPERTY_CHANGED
177
244
  */
178
245
 
246
+ }, {
247
+ key: "publishVideo",
248
+ value: function publishVideo(publish) {
249
+ this._mediaStream.getTracks().forEach(function (track) {
250
+ if (track.kind === 'video') {
251
+ if (track.setEnabled) {
252
+ track.setEnabled(publish);
253
+ } else {
254
+ track.enabled = publish;
255
+ }
256
+ }
257
+ });
179
258
 
180
- TsWebRTCStream.prototype.publishVideo = function publishVideo(publish) {
181
- this._mediaStream.getTracks().forEach(function (track) {
182
- if (track.kind === 'video') {
183
- if (track.setEnabled) {
184
- track.setEnabled(publish);
185
- } else {
186
- track.enabled = publish;
187
- }
188
- }
189
- });
190
-
191
- this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
192
- stream: this,
193
- property: 'hasVideo',
194
- value: publish
195
- });
196
- };
197
-
259
+ this._session.emit(_session.EVENTS.STREAM_PROPERTY_CHANGED, {
260
+ stream: this,
261
+ property: 'hasVideo',
262
+ value: publish
263
+ });
264
+ }
198
265
  /**
199
266
  * Subscribe to a remote stream.
200
267
  *
@@ -215,114 +282,119 @@ var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
215
282
  * @see TsMediaStream
216
283
  */
217
284
 
285
+ }, {
286
+ key: "subscribe",
287
+ value: function subscribe(target) {
288
+ var _this2 = this;
218
289
 
219
- TsWebRTCStream.prototype.subscribe = function subscribe(target) {
220
- var _this2 = this;
290
+ var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
291
+ height: '100%',
292
+ width: '100%',
293
+ fitMode: 'contain',
294
+ insertMode: 'append'
295
+ };
221
296
 
222
- var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
223
- height: '100%',
224
- width: '100%',
225
- fitMode: 'contain',
226
- insertMode: 'append'
227
- };
297
+ if (!params) {
298
+ params = target;
299
+ target = null;
300
+ }
228
301
 
229
- if (!params) {
230
- params = target;
231
- target = null;
232
- }
302
+ var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
303
+ var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
233
304
 
234
- var elementHeight = typeof params.height === 'string' ? params.height : params.height + 'px';
235
- var elementWidth = typeof params.width === 'string' ? params.width : params.width + 'px';
236
-
237
- var bindVideoStreamToElement = function bindVideoStreamToElement(stream, target) {
238
- return new Promise(function (resolve, reject) {
239
- var doResolve = function doResolve(videoEl) {
240
- tracer.trace('Video element created successfully');
241
- resolve(videoEl);
242
- };
243
-
244
- var videoEl = document.createElement('video');
245
- videoEl.muted = true;
246
- videoEl.playsInline = true;
247
-
248
- if (isIE11 && window.WebRTCAdapter) {
249
- target.appendChild(videoEl);
250
- window.WebRTCAdapter.bindVideoElement(videoEl);
251
- }
252
-
253
- videoEl.srcObject = stream;
254
-
255
- if (!isIE11) {
256
- // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play
257
- videoEl.setAttribute('muted', '');
258
- }
259
-
260
- try {
261
- var playRes = videoEl.play();
262
- if (playRes && playRes.then) {
263
- playRes.then(function () {
264
- tracer.trace('Video element play success');
265
- });
266
- }
267
-
268
- if (playRes && playRes.catch) {
269
- playRes.catch(function (error) {
270
- tracer.trace('Reject while executing play method on video element', error);
271
- });
272
- }
273
- } catch (error) {
274
- tracer.trace('Error while executing play method on video element', error);
275
- }
276
-
277
- if (isIE11) {
278
- var handleComplete = function handleComplete() {
279
- return videoEl.parentElement.tagName !== 'OBJECT';
280
- };
281
-
282
- var waitForObjectSettings = { intervalInMs: 30, timeoutInMs: 200 };
283
-
284
- (0, _retryWithTimeout.repeatWithTimeout)(handleComplete, waitForObjectSettings).then(function () {
285
- //We will wait, until video is played, then we resolve
286
- var isVideoPlaying = function isVideoPlaying() {
287
- return videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0;
288
- };
289
- var waitForVideoSettings = { intervalInMs: 50, timeoutInMs: 10000 };
290
- (0, _retryWithTimeout.repeatWithTimeout)(isVideoPlaying, waitForVideoSettings).then(function () {
291
- return doResolve(videoEl.parentElement);
292
- }).catch(function () {
293
- return reject(new Error('Timeout while waiting for video to play'));
294
- });
295
- });
296
- } else {
297
- target.appendChild(videoEl);
298
- doResolve(videoEl);
299
- }
300
- });
301
- };
305
+ var bindVideoStreamToElement = function bindVideoStreamToElement(stream, target) {
306
+ return new Promise(function (resolve, reject) {
307
+ var doResolve = function doResolve(videoEl) {
308
+ tracer.trace('Video element created successfully');
309
+ resolve(videoEl);
310
+ };
311
+
312
+ var videoEl = document.createElement('video');
313
+ videoEl.muted = true;
314
+ videoEl.playsInline = true;
315
+
316
+ if (isIE11 && window.WebRTCAdapter) {
317
+ target.appendChild(videoEl);
318
+ window.WebRTCAdapter.bindVideoElement(videoEl);
319
+ }
320
+
321
+ videoEl.srcObject = stream;
322
+
323
+ if (!isIE11) {
324
+ // Hack to override behavior introduced by Chrome/FF that unmuted video elements can't auto play
325
+ videoEl.setAttribute('muted', '');
326
+ }
327
+
328
+ try {
329
+ var playRes = videoEl.play();
330
+
331
+ if (playRes && playRes.then) {
332
+ playRes.then(function () {
333
+ tracer.trace('Video element play success');
334
+ });
335
+ }
302
336
 
303
- return bindVideoStreamToElement(this._mediaStream, target).then(function (videoEl) {
304
- _.assign(videoEl.style, {
305
- height: elementHeight,
306
- width: elementWidth,
337
+ if (playRes && playRes["catch"]) {
338
+ playRes["catch"](function (error) {
339
+ tracer.trace('Reject while executing play method on video element', error);
340
+ });
341
+ }
342
+ } catch (error) {
343
+ tracer.trace('Error while executing play method on video element', error);
344
+ }
307
345
 
308
- 'object-fit': params.fitMode
309
- });
346
+ if (isIE11) {
347
+ var handleComplete = function handleComplete() {
348
+ return videoEl.parentElement.tagName !== 'OBJECT';
349
+ };
310
350
 
311
- var subscriber = new _subscriber.TsMediaSubscriber({
312
- target: target,
313
- _session: _this2._session,
314
- stream: _this2,
315
- _element: videoEl
351
+ var waitForObjectSettings = {
352
+ intervalInMs: 30,
353
+ timeoutInMs: 200
354
+ };
355
+ (0, _retryWithTimeout.repeatWithTimeout)(handleComplete, waitForObjectSettings).then(function () {
356
+ //We will wait, until video is played, then we resolve
357
+ var isVideoPlaying = function isVideoPlaying() {
358
+ return videoEl.videoHeight <= 0 || videoEl.videoWidth <= 0;
359
+ };
360
+
361
+ var waitForVideoSettings = {
362
+ intervalInMs: 50,
363
+ timeoutInMs: 10000
364
+ };
365
+ (0, _retryWithTimeout.repeatWithTimeout)(isVideoPlaying, waitForVideoSettings).then(function () {
366
+ return doResolve(videoEl.parentElement);
367
+ })["catch"](function () {
368
+ return reject(new Error('Timeout while waiting for video to play'));
369
+ });
316
370
  });
371
+ } else {
372
+ target.appendChild(videoEl);
373
+ doResolve(videoEl);
374
+ }
375
+ });
376
+ };
317
377
 
318
- _this2.setupDimensionsListener(videoEl, subscriber);
319
-
320
- _this2.subscriber = subscriber;
378
+ return bindVideoStreamToElement(this._mediaStream, target).then(function (videoEl) {
379
+ _.assign(videoEl.style, {
380
+ height: elementHeight,
381
+ width: elementWidth,
382
+ 'object-fit': params.fitMode
383
+ });
321
384
 
322
- return subscriber;
385
+ var subscriber = new _subscriber.TsMediaSubscriber({
386
+ target: target,
387
+ _session: _this2._session,
388
+ stream: _this2,
389
+ _element: videoEl
323
390
  });
324
- };
325
391
 
392
+ _this2.setupDimensionsListener(videoEl, subscriber);
393
+
394
+ _this2.subscriber = subscriber;
395
+ return subscriber;
396
+ });
397
+ }
326
398
  /**
327
399
  * Unsubscribe from the stream and destroy subscriber's view.
328
400
  *
@@ -339,130 +411,130 @@ var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
339
411
  * @see TsMediaSubscriber#destroy
340
412
  */
341
413
 
414
+ }, {
415
+ key: "destroySubscriber",
416
+ value: function destroySubscriber(subscriber) {
417
+ return new Promise(function (resolve) {
418
+ var doResolve = function doResolve() {
419
+ subscriber.emit(_subscriber.EVENTS.DESTROYED);
420
+ resolve();
421
+ };
342
422
 
343
- TsWebRTCStream.prototype.destroySubscriber = function destroySubscriber(subscriber) {
344
- return new Promise(function (resolve) {
345
- var doResolve = function doResolve() {
346
- subscriber.emit(_subscriber.EVENTS.DESTROYED);
347
- resolve();
348
- };
349
-
350
- if (isIE11 && window.WebRTCAdapter) {
351
- var videoEl = subscriber._element.firstChild;
352
- window.WebRTCAdapter.unBindVideoElement(videoEl);
353
- if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {
354
- videoEl.parentNode.removeChild(videoEl);
355
- tracer.trace('Video element removed successfully');
356
- } else {
357
- tracer.trace('Video element not removed', videoEl, videoEl.parentNode);
358
- }
359
- doResolve();
360
- } else {
361
- subscriber._element.remove();
362
- doResolve();
363
- }
364
- });
365
- };
366
-
367
- /* eslint-disable no-unused-vars */
368
-
369
-
370
- TsWebRTCStream.prototype.getSnapshot = function getSnapshot(tsMediaElement) {
371
- var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
423
+ if (isIE11 && window.WebRTCAdapter) {
424
+ var videoEl = subscriber._element.firstChild;
425
+ window.WebRTCAdapter.unBindVideoElement(videoEl);
372
426
 
373
- var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
374
- _ref$format = _ref.format,
375
- format = _ref$format === undefined ? 'image/png' : _ref$format,
376
- _ref$quality = _ref.quality,
377
- quality = _ref$quality === undefined ? 0.92 : _ref$quality,
378
- x = _ref.x,
379
- y = _ref.y,
380
- w = _ref.w,
381
- h = _ref.h;
427
+ if (videoEl && videoEl.parentNode && videoEl.parentNode.removeChild) {
428
+ videoEl.parentNode.removeChild(videoEl);
429
+ tracer.trace('Video element removed successfully');
430
+ } else {
431
+ tracer.trace('Video element not removed', videoEl, videoEl.parentNode);
432
+ }
382
433
 
383
- var videoElement = tsMediaElement._element;
384
- var videoWidth = videoElement.videoWidth,
385
- videoHeight = videoElement.videoHeight;
434
+ doResolve();
435
+ } else {
436
+ subscriber._element.remove();
386
437
 
387
- var crop = !_.isUndefined(x) && !_.isUndefined(y) && !_.isUndefined(w) && !_.isUndefined(h);
388
- var resize = !crop && (!_.isUndefined(w) || !_.isUndefined(h));
438
+ doResolve();
439
+ }
440
+ });
441
+ }
442
+ /* eslint-disable no-unused-vars */
389
443
 
390
- if (resize) {
391
- if (!h) {
392
- h = w * (videoHeight / videoWidth);
393
- } else if (!w) {
394
- w = h * (videoWidth / videoHeight);
395
- }
444
+ }, {
445
+ key: "getSnapshot",
446
+ value: function getSnapshot(tsMediaElement) {
447
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
448
+
449
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
450
+ _ref$format = _ref.format,
451
+ format = _ref$format === void 0 ? 'image/png' : _ref$format,
452
+ _ref$quality = _ref.quality,
453
+ quality = _ref$quality === void 0 ? 0.92 : _ref$quality,
454
+ x = _ref.x,
455
+ y = _ref.y,
456
+ w = _ref.w,
457
+ h = _ref.h;
458
+
459
+ var videoElement = tsMediaElement._element;
460
+ var videoWidth = videoElement.videoWidth,
461
+ videoHeight = videoElement.videoHeight;
462
+ var crop = !_.isUndefined(x) && !_.isUndefined(y) && !_.isUndefined(w) && !_.isUndefined(h);
463
+ var resize = !crop && (!_.isUndefined(w) || !_.isUndefined(h));
464
+
465
+ if (resize) {
466
+ if (!h) {
467
+ h = w * (videoHeight / videoWidth);
468
+ } else if (!w) {
469
+ w = h * (videoWidth / videoHeight);
470
+ }
471
+ }
472
+
473
+ function getImgData() {
474
+ var canvas = document.createElement('canvas');
475
+ var ctx = canvas.getContext('2d');
476
+
477
+ if (crop) {
478
+ canvas.width = w;
479
+ canvas.height = h;
480
+ ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);
481
+ } else if (resize) {
482
+ canvas.width = w;
483
+ canvas.height = h;
484
+ ctx.drawImage(videoElement, 0, 0, w, h);
485
+ } else {
486
+ canvas.height = videoHeight;
487
+ canvas.width = videoWidth;
488
+ ctx.drawImage(videoElement, 0, 0);
396
489
  }
397
490
 
398
- function getImgData() {
399
- var canvas = document.createElement('canvas');
400
- var ctx = canvas.getContext('2d');
491
+ return canvas.toDataURL(format, quality);
492
+ }
401
493
 
494
+ function getImgDataIE11() {
495
+ return new Promise(function (resolve) {
496
+ var canvas = document.createElement('canvas');
497
+ var ctx = canvas.getContext('2d');
498
+
499
+ if (crop || resize) {
500
+ canvas.width = w;
501
+ canvas.height = h;
502
+ } else {
503
+ canvas.height = videoHeight;
504
+ canvas.width = videoWidth;
505
+ }
506
+
507
+ function _drawAndRemove(image) {
402
508
  if (crop) {
403
- canvas.width = w;
404
- canvas.height = h;
405
-
406
- ctx.drawImage(videoElement, x, y, w, h, 0, 0, w, h);
509
+ ctx.drawImage(image, x, y, w, h, 0, 0, w, h);
407
510
  } else if (resize) {
408
- canvas.width = w;
409
- canvas.height = h;
410
-
411
- ctx.drawImage(videoElement, 0, 0, w, h);
511
+ ctx.drawImage(image, 0, 0, w, h);
412
512
  } else {
413
- canvas.height = videoHeight;
414
- canvas.width = videoWidth;
415
-
416
- ctx.drawImage(videoElement, 0, 0);
513
+ ctx.drawImage(image, 0, 0, videoWidth, videoHeight);
417
514
  }
418
515
 
419
516
  return canvas.toDataURL(format, quality);
420
- }
517
+ }
421
518
 
422
- function getImgDataIE11() {
423
- return new Promise(function (resolve) {
424
- var canvas = document.createElement('canvas');
425
- var ctx = canvas.getContext('2d');
426
-
427
- if (crop || resize) {
428
- canvas.width = w;
429
- canvas.height = h;
430
- } else {
431
- canvas.height = videoHeight;
432
- canvas.width = videoWidth;
433
- }
434
-
435
- function _drawAndRemove(image) {
436
- if (crop) {
437
- ctx.drawImage(image, x, y, w, h, 0, 0, w, h);
438
- } else if (resize) {
439
- ctx.drawImage(image, 0, 0, w, h);
440
- } else {
441
- ctx.drawImage(image, 0, 0, videoWidth, videoHeight);
442
- }
443
-
444
- return canvas.toDataURL(format, quality);
445
- }
446
-
447
- var base64 = videoElement.getFrame();
448
- var image = new Image();
449
-
450
- image.onload = function () {
451
- return resolve(_drawAndRemove(image));
452
- };
453
- image.setAttribute('src', 'data:image/bmp;base64,' + base64);
454
- });
455
- }
519
+ var base64 = videoElement.getFrame();
520
+ var image = new Image();
456
521
 
457
- return Promise.resolve(isIE11 ? getImgDataIE11() : getImgData()).then(function (imgData) {
458
- if (!imgData || imgData.length < 10) {
459
- return Promise.reject('Failed to get a snapshot');
460
- }
522
+ image.onload = function () {
523
+ return resolve(_drawAndRemove(image));
524
+ };
461
525
 
462
- return imgData;
526
+ image.setAttribute('src', 'data:image/bmp;base64,' + base64);
463
527
  });
464
- };
528
+ }
529
+
530
+ return Promise.resolve(isIE11 ? getImgDataIE11() : getImgData()).then(function (imgData) {
531
+ if (!imgData || imgData.length < 10) {
532
+ return Promise.reject('Failed to get a snapshot');
533
+ }
465
534
 
535
+ return imgData;
536
+ });
537
+ }
466
538
  /**
467
539
  * Get statistics of the media subscription like bytes received.
468
540
  *
@@ -477,198 +549,148 @@ var TsWebRTCStream = exports.TsWebRTCStream = function (_TsMediaStream) {
477
549
  * @see TsMediaSubscriber#getStats
478
550
  */
479
551
 
480
-
481
- TsWebRTCStream.prototype.getStats = function getStats(subscriber) {
482
- var _this3 = this;
483
-
484
- return new Promise(function (resolve) {
485
- try {
486
- var pc = _this3._getPeerConnection();
487
-
488
- if (isIE11 || !pc) {
489
- return resolve();
490
- }
491
-
492
- pc.getStats(_this3._mediaStream.getVideoTracks()[0]).then(function (reports) {
493
- var matches = [];
494
-
495
- reports.forEach(function (report) {
496
- if (_.includes(['inbound-rtp', 'ssrc'], report.type)) {
497
- matches.push(report);
498
- }
499
- });
500
-
501
- return resolve({
502
- video: _.head(matches)
503
- });
504
- });
505
- } catch (e) {
506
- // when this fails, it's most likely due ot no support for the getStats
507
- // functionality, so we don't want to log this as a recurring error
508
- resolve();
509
- }
510
- });
511
- };
512
-
552
+ }, {
553
+ key: "getStats",
554
+ value: function getStats(subscriber) {
555
+ var _this3 = this;
556
+
557
+ return new Promise(function (resolve) {
558
+ try {
559
+ var pc = _this3._getPeerConnection();
560
+
561
+ if (isIE11 || !pc) {
562
+ return resolve();
563
+ }
564
+
565
+ pc.getStats(_this3._mediaStream.getVideoTracks()[0]).then(function (reports) {
566
+ var matches = [];
567
+ reports.forEach(function (report) {
568
+ if (_.includes(['inbound-rtp', 'ssrc'], report.type)) {
569
+ matches.push(report);
570
+ }
571
+ });
572
+ return resolve({
573
+ video: _.head(matches)
574
+ });
575
+ });
576
+ } catch (e) {
577
+ // when this fails, it's most likely due ot no support for the getStats
578
+ // functionality, so we don't want to log this as a recurring error
579
+ resolve();
580
+ }
581
+ });
582
+ }
513
583
  /* eslint-enable no-unused-vars */
514
584
 
515
- TsWebRTCStream.prototype.getFullVideoStats = function getFullVideoStats() {
516
- var _this4 = this;
517
-
518
- return new Promise(function (resolve, reject) {
519
- try {
520
- var pc = _this4._getPeerConnection();
521
-
522
- if (!pc) {
523
- return reject('NO_PEER_CONNECTION');
524
- }
525
-
526
- return resolve(pc.getStats(_this4._mediaStream.getVideoTracks()[0]));
527
- } catch (e) {
528
- reject(e);
529
- }
530
- });
531
- };
532
-
533
- TsWebRTCStream.prototype.turnFlashlight = function turnFlashlight() {
534
- var _this5 = this;
535
-
536
- var isTorchOn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
537
-
538
- return new Promise(function (resolve, reject) {
539
- if (_this5._torchDelayTimeOut) {
540
- return reject('No tourch delay');
541
- }
542
-
543
- if (!navigator || !navigator.mediaDevices) {
544
- return reject('No mediaDevices');
545
- }
546
-
547
- var track = _this5._mediaStream.getVideoTracks()[0];
548
-
549
- if (!track) {
550
- return reject('No track');
551
- }
552
- if (_this5._torchOffTimeOut) {
553
- clearInterval(_this5._torchOffTimeOut);
554
- _this5._torchOffTimeOut = null;
555
- }
556
-
557
- _this5._torchDelayTimeOut = setTimeout(function () {
558
- var capatibilitiesAfter = {};
559
-
560
- try {
561
- capatibilitiesAfter = track.getCapabilities();
562
- } catch (e) {
563
- return reject('No capabilities');
564
- }
565
-
566
- if (!capatibilitiesAfter.torch) {
567
- return reject('No tourch capabilities');
568
- }
569
-
570
- return track.applyConstraints({
571
- advanced: [{
572
- torch: isTorchOn
573
- }]
574
- }).then(function () {
575
- _this5._torchDelayTimeOut = null;
576
- resolve(true);
577
- }).catch(function (e) {
578
- _this5._torchDelayTimeOut = null;
579
- console.error(e);
580
- reject('Can\'t turn on the light, please try later!');
581
- });
582
- }, TORCH_DELAY);
583
- });
584
- };
585
+ }, {
586
+ key: "getFullVideoStats",
587
+ value: function getFullVideoStats() {
588
+ var _this4 = this;
585
589
 
586
- TsWebRTCStream.prototype.setAutoLightOffTimer = function setAutoLightOffTimer(flashlightTimeout) {
587
- var _this6 = this;
590
+ return new Promise(function (resolve, reject) {
591
+ try {
592
+ var pc = _this4._getPeerConnection();
588
593
 
589
- return new Promise(function (resolve) {
590
- if (!flashlightTimeout) {
591
- return reject('No timeout');
592
- }
594
+ if (!pc) {
595
+ return reject('NO_PEER_CONNECTION');
596
+ }
593
597
 
594
- var track = _this6._mediaStream.getVideoTracks()[0];
598
+ return resolve(pc.getStats(_this4._mediaStream.getVideoTracks()[0]));
599
+ } catch (e) {
600
+ reject(e);
601
+ }
602
+ });
603
+ }
604
+ }, {
605
+ key: "turnFlashlight",
606
+ value: function turnFlashlight() {
607
+ var _this5 = this;
608
+
609
+ var isTorchOn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
610
+ return new Promise(function (resolve, reject) {
611
+ if (_this5._torchDelayTimeOut) {
612
+ return reject('No tourch delay');
613
+ }
595
614
 
596
- if (!track) {
597
- return reject('No track');
598
- }
615
+ if (!navigator || !navigator.mediaDevices) {
616
+ return reject('No mediaDevices');
617
+ }
599
618
 
600
- _this6._torchOffTimeOut = setTimeout(function () {
601
-
602
- if (!track) {
603
- return reject('No track');
604
- }
605
-
606
- track.applyConstraints({
607
- advanced: [{
608
- torch: false
609
- }]
610
- }).then(function () {
611
- _this6._torchOffTimeOut = null;
612
- resolve();
613
- });
614
- }, flashlightTimeout);
615
- });
616
- };
619
+ var track = _this5._mediaStream.getVideoTracks()[0];
617
620
 
618
- _createClass(TsWebRTCStream, [{
619
- key: 'id',
620
- get: function get() {
621
- return this._mediaStream.id;
621
+ if (!track) {
622
+ return reject('No track');
622
623
  }
623
624
 
624
- /**
625
- * Unique name of the stream
626
- *
627
- * @member { String }
628
- * @type { String }
629
- */
630
-
631
- }, {
632
- key: 'name',
633
- get: function get() {
634
- return this._name;
625
+ if (_this5._torchOffTimeOut) {
626
+ clearInterval(_this5._torchOffTimeOut);
627
+ _this5._torchOffTimeOut = null;
635
628
  }
636
629
 
637
- /**
638
- * Whether or not stream has enabled video tracks
639
- *
640
- * @member { Boolean }
641
- * @type { Boolean }
642
- */
643
-
644
- }, {
645
- key: 'hasVideo',
646
- get: function get() {
647
- var enabledVideoTracks = this._mediaStream.getVideoTracks().filter(function (track) {
648
- return track.enabled;
649
- });
650
-
651
- return enabledVideoTracks.length > 0;
630
+ _this5._torchDelayTimeOut = setTimeout(function () {
631
+ var capatibilitiesAfter = {};
632
+
633
+ try {
634
+ capatibilitiesAfter = track.getCapabilities();
635
+ } catch (e) {
636
+ return reject('No capabilities');
637
+ }
638
+
639
+ if (!capatibilitiesAfter.torch) {
640
+ return reject('No tourch capabilities');
641
+ }
642
+
643
+ return track.applyConstraints({
644
+ advanced: [{
645
+ torch: isTorchOn
646
+ }]
647
+ }).then(function () {
648
+ _this5._torchDelayTimeOut = null;
649
+ resolve(true);
650
+ })["catch"](function (e) {
651
+ _this5._torchDelayTimeOut = null;
652
+ console.error(e);
653
+ reject('Can\'t turn on the light, please try later!');
654
+ });
655
+ }, TORCH_DELAY);
656
+ });
657
+ }
658
+ }, {
659
+ key: "setAutoLightOffTimer",
660
+ value: function setAutoLightOffTimer(flashlightTimeout) {
661
+ var _this6 = this;
662
+
663
+ return new Promise(function (resolve) {
664
+ if (!flashlightTimeout) {
665
+ return reject('No timeout');
652
666
  }
653
667
 
654
- /**
655
- * Whether or not stream has enabled audio tracks
656
- *
657
- * @member { Boolean }
658
- * @type { Boolean }
659
- */
660
-
661
- }, {
662
- key: 'hasAudio',
663
- get: function get() {
664
- var enabledAudioTracks = this._mediaStream.getAudioTracks().filter(function (track) {
665
- return track.enabled;
666
- });
668
+ var track = _this6._mediaStream.getVideoTracks()[0];
667
669
 
668
- return enabledAudioTracks.length > 0;
670
+ if (!track) {
671
+ return reject('No track');
669
672
  }
670
- }]);
671
673
 
672
- return TsWebRTCStream;
674
+ _this6._torchOffTimeOut = setTimeout(function () {
675
+ if (!track) {
676
+ return reject('No track');
677
+ }
678
+
679
+ track.applyConstraints({
680
+ advanced: [{
681
+ torch: false
682
+ }]
683
+ }).then(function () {
684
+ _this6._torchOffTimeOut = null;
685
+ resolve();
686
+ });
687
+ }, flashlightTimeout);
688
+ });
689
+ }
690
+ }]);
691
+
692
+ return TsWebRTCStream;
673
693
  }(_stream.TsMediaStream);
694
+
695
+ exports.TsWebRTCStream = TsWebRTCStream;
674
696
  //# sourceMappingURL=stream.js.map