@techsee/techsee-media-service 0.21.2 → 0.22.0-alphagb2

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 (97) hide show
  1. package/lib/LocalStreamManager.js +435 -317
  2. package/lib/LocalStreamManager.js.map +1 -1
  3. package/lib/MediaConstants.js +72 -44
  4. package/lib/MediaConstants.js.map +1 -1
  5. package/lib/MediaContracts.js +3 -3
  6. package/lib/MediaContracts.js.map +1 -1
  7. package/lib/MediaPublisher.js +45 -35
  8. package/lib/MediaPublisher.js.map +1 -1
  9. package/lib/MediaServiceBase.js +922 -706
  10. package/lib/MediaServiceBase.js.map +1 -1
  11. package/lib/MediaSession/MediaServer.js +512 -379
  12. package/lib/MediaSession/MediaServer.js.map +1 -1
  13. package/lib/MediaSession/MediaSessionBase.js +123 -88
  14. package/lib/MediaSession/MediaSessionBase.js.map +1 -1
  15. package/lib/MediaSession/SessionOpentok.js +499 -384
  16. package/lib/MediaSession/SessionOpentok.js.map +1 -1
  17. package/lib/MediaSession/SessionTurn.js +606 -466
  18. package/lib/MediaSession/SessionTurn.js.map +1 -1
  19. package/lib/MediaSession/TurnConstants.js +30 -30
  20. package/lib/MediaSession/TurnConstants.js.map +1 -1
  21. package/lib/MediaSubscriber.js +235 -192
  22. package/lib/MediaSubscriber.js.map +1 -1
  23. package/lib/MediaUtils/Compatibility.js +127 -90
  24. package/lib/MediaUtils/Compatibility.js.map +1 -1
  25. package/lib/MediaUtils/MediaDomUtils.js +230 -179
  26. package/lib/MediaUtils/MediaDomUtils.js.map +1 -1
  27. package/lib/MediaUtils/MediaTracer.js +8 -4
  28. package/lib/MediaUtils/MediaTracer.js.map +1 -1
  29. package/lib/MultiParty/Contracts.js +3 -3
  30. package/lib/MultiParty/Contracts.js.map +1 -1
  31. package/lib/MultiParty/DetectWebRtcService.js +66 -50
  32. package/lib/MultiParty/DetectWebRtcService.js.map +1 -1
  33. package/lib/MultiParty/MediaCapabilitiesHelper.js +258 -154
  34. package/lib/MultiParty/MediaCapabilitiesHelper.js.map +1 -1
  35. package/lib/MultiParty/MultiParty.d.ts +1 -8
  36. package/lib/MultiParty/MultiParty.d.ts.map +1 -1
  37. package/lib/MultiParty/MultiParty.js +221 -128
  38. package/lib/MultiParty/MultiParty.js.map +1 -1
  39. package/lib/MultiParty/MultipartyFactory.d.ts +1 -2
  40. package/lib/MultiParty/MultipartyFactory.d.ts.map +1 -1
  41. package/lib/MultiParty/MultipartyFactory.js +12 -7
  42. package/lib/MultiParty/MultipartyFactory.js.map +1 -1
  43. package/lib/MultiParty/OpentokMultiparty.js +611 -384
  44. package/lib/MultiParty/OpentokMultiparty.js.map +1 -1
  45. package/lib/TechseeMediaStream.js +58 -53
  46. package/lib/TechseeMediaStream.js.map +1 -1
  47. package/lib/oldCode/constants.js +20 -15
  48. package/lib/oldCode/constants.js.map +1 -1
  49. package/lib/oldCode/event-emitter.js +45 -22
  50. package/lib/oldCode/event-emitter.js.map +1 -1
  51. package/lib/oldCode/index.js +48 -52
  52. package/lib/oldCode/index.js.map +1 -1
  53. package/lib/oldCode/opentok/session.js +261 -236
  54. package/lib/oldCode/opentok/session.js.map +1 -1
  55. package/lib/oldCode/opentok/stream.js +283 -269
  56. package/lib/oldCode/opentok/stream.js.map +1 -1
  57. package/lib/oldCode/publisher.js +96 -71
  58. package/lib/oldCode/publisher.js.map +1 -1
  59. package/lib/oldCode/service.js +294 -272
  60. package/lib/oldCode/service.js.map +1 -1
  61. package/lib/oldCode/session.js +82 -60
  62. package/lib/oldCode/session.js.map +1 -1
  63. package/lib/oldCode/stream.js +153 -125
  64. package/lib/oldCode/stream.js.map +1 -1
  65. package/lib/oldCode/subscriber.js +60 -35
  66. package/lib/oldCode/subscriber.js.map +1 -1
  67. package/lib/oldCode/tracer.js +179 -138
  68. package/lib/oldCode/tracer.js.map +1 -1
  69. package/lib/oldCode/utils/ImageFixer.js +66 -44
  70. package/lib/oldCode/utils/ImageFixer.js.map +1 -1
  71. package/lib/oldCode/webrtc/constants.js +102 -110
  72. package/lib/oldCode/webrtc/constants.js.map +1 -1
  73. package/lib/oldCode/webrtc/helper.js +176 -124
  74. package/lib/oldCode/webrtc/helper.js.map +1 -1
  75. package/lib/oldCode/webrtc/session-kms.js +408 -393
  76. package/lib/oldCode/webrtc/session-kms.js.map +1 -1
  77. package/lib/oldCode/webrtc/session-loopback.js +245 -227
  78. package/lib/oldCode/webrtc/session-loopback.js.map +1 -1
  79. package/lib/oldCode/webrtc/session-turn.js +705 -658
  80. package/lib/oldCode/webrtc/session-turn.js.map +1 -1
  81. package/lib/oldCode/webrtc/session-turn.v2.js +480 -471
  82. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -1
  83. package/lib/oldCode/webrtc/session.js +12 -6
  84. package/lib/oldCode/webrtc/session.js.map +1 -1
  85. package/lib/oldCode/webrtc/stream.js +526 -504
  86. package/lib/oldCode/webrtc/stream.js.map +1 -1
  87. package/lib/oldCode/webrtc/temasys/adapter-loader.js +5 -6
  88. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -1
  89. package/lib/oldCode/webrtc/temasys/adapter.js +5264 -5192
  90. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -1
  91. package/lib/oldCode/webrtc/webrtc-ie-shim.js +3357 -2927
  92. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -1
  93. package/lib/qos/raw-qos.js +348 -274
  94. package/lib/qos/raw-qos.js.map +1 -1
  95. package/lib/webrtc-ie-shim.js +3386 -2985
  96. package/lib/webrtc-ie-shim.js.map +1 -1
  97. package/package.json +12 -15
@@ -1,310 +1,324 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- exports.__esModule = true;
4
- exports.TsOpenTokStream = 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.TsOpenTokStream = void 0;
7
15
 
8
- var _stream = require('../stream');
16
+ var _stream = require("../stream");
9
17
 
10
- var _subscriber = require('../subscriber');
18
+ var _subscriber = require("../subscriber");
11
19
 
12
- var _publisher = require('../publisher');
20
+ var _publisher = require("../publisher");
13
21
 
14
22
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
23
 
16
- 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; }
24
+ 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); } }
17
25
 
18
- 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; }
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
27
 
20
- exports.EVENTS = _stream.EVENTS;
28
+ 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); }
21
29
 
22
- var TsOpenTokStream = exports.TsOpenTokStream = function (_TsMediaStream) {
23
- _inherits(TsOpenTokStream, _TsMediaStream);
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
24
31
 
25
- function TsOpenTokStream(session, otstream) {
26
- _classCallCheck(this, TsOpenTokStream);
32
+ 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); }; }
27
33
 
28
- var _this = _possibleConstructorReturn(this, _TsMediaStream.call(this, otstream.id, session));
34
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
29
35
 
30
- _this._otstream = otstream;
31
- _this._session = session;
36
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
32
37
 
33
- _this._videoChannelExists = _this._otstream.channel && _this._otstream.channel.filter(function (channel) {
34
- return channel.type === 'video';
35
- }).length > 0;
36
- _this._audioChannelExists = _this._otstream.channel && _this._otstream.channel.filter(function (channel) {
37
- return channel.type === 'audio';
38
- }).length > 0;
39
- return _this;
40
- }
41
-
42
- TsOpenTokStream.prototype.publishAudio = function publishAudio(publish) {
43
- if (this.publisher) {
44
- this.publisher._otpublisher.publishAudio(publish);
45
- }
46
- };
47
-
48
- TsOpenTokStream.prototype.publishVideo = function publishVideo(publish) {
49
- if (this.publisher) {
50
- this.publisher._otpublisher.publishVideo(publish);
51
- }
52
- };
38
+ 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; } }
53
39
 
54
- TsOpenTokStream.prototype.subscribe = function subscribe(target, params) {
55
- var _this2 = this;
40
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
56
41
 
57
- if (!params) {
58
- params = target;
59
- target = null;
60
- }
61
-
62
- return this._session.createSubscriber(this, target, params).then(function (subscriber) {
63
- subscriber.stream = _this2;
64
- _this2.subscriber = subscriber;
65
-
66
- subscriber._otsubscriber.on('destroyed', function (e) {
67
- subscriber.emit(_subscriber.EVENTS.DESTROYED, e);
68
- });
42
+ var TsOpenTokStream = /*#__PURE__*/function (_TsMediaStream) {
43
+ _inherits(TsOpenTokStream, _TsMediaStream);
69
44
 
70
- subscriber._otsubscriber.on('disconnected', function (e) {
71
- subscriber.emit(_subscriber.EVENTS.DISCONNECTED, e);
72
- });
45
+ var _super = _createSuper(TsOpenTokStream);
73
46
 
74
- var video = _this2.getVideoElement(subscriber._otsubscriber.element)[0];
75
-
76
- if (!_this2._environment.isIE11()) {
77
- // Hack to override behavior introduced by Chrome v71 that unmuted video elements can't auto play
78
- video.setAttribute('muted', '');
79
- video.play();
80
- }
47
+ function TsOpenTokStream(session, otstream) {
48
+ var _this;
81
49
 
82
- _this2.setupDimensionsListener(video, subscriber);
50
+ _classCallCheck(this, TsOpenTokStream);
83
51
 
84
- subscriber.id = subscriber._otsubscriber.id;
52
+ _this = _super.call(this, otstream.id, session);
53
+ _this._otstream = otstream;
54
+ _this._session = session;
55
+ _this._videoChannelExists = _this._otstream.channel && _this._otstream.channel.filter(function (channel) {
56
+ return channel.type === 'video';
57
+ }).length > 0;
58
+ _this._audioChannelExists = _this._otstream.channel && _this._otstream.channel.filter(function (channel) {
59
+ return channel.type === 'audio';
60
+ }).length > 0;
61
+ return _this;
62
+ }
85
63
 
86
- return subscriber;
64
+ _createClass(TsOpenTokStream, [{
65
+ key: "id",
66
+ get: function get() {
67
+ return this._otstream.streamId;
68
+ }
69
+ }, {
70
+ key: "name",
71
+ get: function get() {
72
+ return this._otstream.name;
73
+ }
74
+ /**
75
+ * Whether the stream has video. This property can change if the publisher turns on or off video
76
+ * (by calling Publisher.publishVideo()). When this occurs, the Session object dispatches a streamPropertyChanged
77
+ * event (see StreamPropertyChangedEvent).
78
+ */
79
+
80
+ }, {
81
+ key: "hasVideo",
82
+ get: function get() {
83
+ return this._otstream.hasVideo;
84
+ }
85
+ /**
86
+ * Whether the stream has audio. This property can change if the publisher turns on or off audio
87
+ * (by calling Publisher.publishAudio()). When this occurs, the Session object dispatches a streamPropertyChanged
88
+ * event (see StreamPropertyChangedEvent).
89
+ */
90
+
91
+ }, {
92
+ key: "hasAudio",
93
+ get: function get() {
94
+ return this._otstream.hasAudio;
95
+ }
96
+ /**
97
+ * Indicates if video channel exists in the stream.
98
+ */
99
+
100
+ }, {
101
+ key: "videoChannelExists",
102
+ get: function get() {
103
+ return this._videoChannelExists;
104
+ }
105
+ /**
106
+ * Indicates if audio channel exists in the stream.
107
+ */
108
+
109
+ }, {
110
+ key: "audioChannelExists",
111
+ get: function get() {
112
+ return this._audioChannelExists;
113
+ }
114
+ }, {
115
+ key: "publishAudio",
116
+ value: function publishAudio(publish) {
117
+ if (this.publisher) {
118
+ this.publisher._otpublisher.publishAudio(publish);
119
+ }
120
+ }
121
+ }, {
122
+ key: "publishVideo",
123
+ value: function publishVideo(publish) {
124
+ if (this.publisher) {
125
+ this.publisher._otpublisher.publishVideo(publish);
126
+ }
127
+ }
128
+ }, {
129
+ key: "subscribe",
130
+ value: function subscribe(target, params) {
131
+ var _this2 = this;
132
+
133
+ if (!params) {
134
+ params = target;
135
+ target = null;
136
+ }
137
+
138
+ return this._session.createSubscriber(this, target, params).then(function (subscriber) {
139
+ subscriber.stream = _this2;
140
+ _this2.subscriber = subscriber;
141
+
142
+ subscriber._otsubscriber.on('destroyed', function (e) {
143
+ subscriber.emit(_subscriber.EVENTS.DESTROYED, e);
87
144
  });
88
- };
89
-
90
- TsOpenTokStream.prototype.getVideoElement = function getVideoElement(container) {
91
- var element = $(container).find('.OT_video-element');
92
-
93
- return element.length > 0 ? element : $(container).find('.OT_video-container > video');
94
- };
95
-
96
- TsOpenTokStream.prototype.destroySubscriber = function destroySubscriber(subscriber) {
97
- return this._session.destroySubscriber(subscriber);
98
- };
99
-
100
- TsOpenTokStream.prototype.getSnapshot = function getSnapshot(tsMediaElement) {
101
- var _this3 = this;
102
-
103
- var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
104
-
105
- var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
106
- _ref$format = _ref.format,
107
- format = _ref$format === undefined ? 'image/png' : _ref$format,
108
- _ref$quality = _ref.quality,
109
- quality = _ref$quality === undefined ? 0.92 : _ref$quality,
110
- x = _ref.x,
111
- y = _ref.y,
112
- w = _ref.w,
113
- h = _ref.h;
114
-
115
- return new Promise(function (resolve) {
116
- var otElement = tsMediaElement[tsMediaElement instanceof _publisher.TsMediaPublisher ? '_otpublisher' : '_otsubscriber'];
117
- var crop = !_.isUndefined(x) && !_.isUndefined(y) && !_.isUndefined(w) && !_.isUndefined(h);
118
- var resize = !crop && (!_.isUndefined(w) || !_.isUndefined(h));
119
-
120
- if (!_this3._environment.isIE11() && format.toLowerCase() === 'image/png' && !crop && !resize) {
121
- return resolve('data:image/png;base64,' + otElement.getImgData());
122
- }
123
-
124
- var videoElement = _this3.getVideoElement(otElement.element);
125
-
126
- if (!_this3._environment.isIE11()) {
127
- var videoElem = videoElement[0];
128
- var canvas = document.createElement('canvas');
129
- var ctx = canvas.getContext('2d');
130
-
131
- if (crop) {
132
- canvas.width = w;
133
- canvas.height = h;
134
-
135
- ctx.drawImage(videoElem, x, y, w, h, 0, 0, w, h);
136
- } else if (resize) {
137
- if (!h) {
138
- h = w * (videoElem.videoHeight / videoElem.videoWidth);
139
- } else if (!w) {
140
- w = h * (videoElem.videoWidth / videoElem.videoHeight);
141
- }
142
-
143
- canvas.width = w;
144
- canvas.height = h;
145
-
146
- ctx.drawImage(videoElem, 0, 0, w, h);
147
- } else {
148
- canvas.width = videoElem.videoWidth;
149
- canvas.height = videoElem.videoHeight;
150
-
151
- ctx.drawImage(videoElem, 0, 0);
152
- }
153
-
154
- return resolve(canvas.toDataURL(format, quality));
155
- }
156
145
 
157
- var currentWidth = videoElement.width();
158
- var currentHeight = videoElement.height();
159
- var currentPosition = videoElement.position();
160
- var _videoDimensions = _this3.videoDimensions,
161
- videoWidth = _videoDimensions.width,
162
- videoHeight = _videoDimensions.height;
163
-
164
- var ratio = Math.max(videoWidth / currentWidth, videoHeight / currentHeight);
165
-
166
- videoElement.width(videoWidth / ratio);
167
- videoElement.height(videoHeight / ratio);
168
-
169
- videoElement.css({
170
- left: currentPosition.left + Math.max(0, (currentWidth - videoWidth / ratio) / 2) + 'px',
171
-
172
- top: currentPosition.top + Math.max(0, (currentHeight - videoHeight / ratio) / 2) + 'px'
173
- });
174
-
175
- setTimeout(function () {
176
- var pngDataURL = 'data:image/png;base64,' + otElement.getImgData();
177
-
178
- if (format.toLowerCase() === 'image/png' && !crop && !resize) {
179
- resolve(pngDataURL);
180
- } else {
181
- var img = new Image(),
182
- _canvas = document.createElement('canvas'),
183
- _ctx = _canvas.getContext('2d');
184
-
185
- img.onload = function () {
186
- if (crop) {
187
- var widthRatio = img.width / videoWidth;
188
- var heightRatio = img.height / videoHeight;
189
-
190
- x = x && x * widthRatio;
191
- y = y && y * heightRatio;
192
- w = w && w * widthRatio;
193
- h = h && h * heightRatio;
194
-
195
- _canvas.width = w;
196
- _canvas.height = h;
197
-
198
- _ctx.drawImage(img, x, y, w, h, 0, 0, w, h);
199
- } else if (resize) {
200
- if (!h) {
201
- h = w * (videoHeight / videoWidth);
202
- } else if (!w) {
203
- w = h * (videoWidth / videoHeight);
204
- }
205
-
206
- _canvas.width = w;
207
- _canvas.height = h;
208
-
209
- _ctx.drawImage(img, 0, 0, w, h);
210
- } else {
211
- _canvas.width = img.width;
212
- _canvas.height = img.height;
213
-
214
- _ctx.drawImage(img);
215
- }
216
-
217
- return resolve(_canvas.toDataURL(format, quality));
218
- };
219
-
220
- img.src = pngDataURL;
221
- }
222
-
223
- videoElement.width(currentWidth);
224
- videoElement.height(currentHeight);
225
-
226
- videoElement.css({
227
- left: currentPosition.left + 'px',
228
- top: currentPosition.top + 'px'
229
- });
230
- }, timeout * 1000);
231
- }).then(function (imgData) {
232
- if (!imgData || imgData.length < 10) {
233
- return Promise.reject('Failed to get a snapshot');
234
- }
235
-
236
- return imgData;
146
+ subscriber._otsubscriber.on('disconnected', function (e) {
147
+ subscriber.emit(_subscriber.EVENTS.DISCONNECTED, e);
237
148
  });
238
- };
239
149
 
240
- TsOpenTokStream.prototype.getStats = function getStats(subscriber) {
241
- return new Promise(function (resolve, reject) {
242
- subscriber._otsubscriber.getStats(function (err, stats) {
243
- if (err) {
244
- return reject(err);
245
- }
150
+ var video = _this2.getVideoElement(subscriber._otsubscriber.element)[0];
246
151
 
247
- return resolve(stats);
248
- });
249
- });
250
- };
251
-
252
- _createClass(TsOpenTokStream, [{
253
- key: 'id',
254
- get: function get() {
255
- return this._otstream.streamId;
256
- }
257
- }, {
258
- key: 'name',
259
- get: function get() {
260
- return this._otstream.name;
152
+ if (!_this2._environment.isIE11()) {
153
+ // Hack to override behavior introduced by Chrome v71 that unmuted video elements can't auto play
154
+ video.setAttribute('muted', '');
155
+ video.play();
261
156
  }
262
157
 
263
- /**
264
- * Whether the stream has video. This property can change if the publisher turns on or off video
265
- * (by calling Publisher.publishVideo()). When this occurs, the Session object dispatches a streamPropertyChanged
266
- * event (see StreamPropertyChangedEvent).
267
- */
158
+ _this2.setupDimensionsListener(video, subscriber);
268
159
 
269
- }, {
270
- key: 'hasVideo',
271
- get: function get() {
272
- return this._otstream.hasVideo;
160
+ subscriber.id = subscriber._otsubscriber.id;
161
+ return subscriber;
162
+ });
163
+ }
164
+ }, {
165
+ key: "getVideoElement",
166
+ value: function getVideoElement(container) {
167
+ var element = $(container).find('.OT_video-element');
168
+ return element.length > 0 ? element : $(container).find('.OT_video-container > video');
169
+ }
170
+ }, {
171
+ key: "destroySubscriber",
172
+ value: function destroySubscriber(subscriber) {
173
+ return this._session.destroySubscriber(subscriber);
174
+ }
175
+ }, {
176
+ key: "getSnapshot",
177
+ value: function getSnapshot(tsMediaElement) {
178
+ var _this3 = this;
179
+
180
+ var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
181
+
182
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
183
+ _ref$format = _ref.format,
184
+ format = _ref$format === void 0 ? 'image/png' : _ref$format,
185
+ _ref$quality = _ref.quality,
186
+ quality = _ref$quality === void 0 ? 0.92 : _ref$quality,
187
+ x = _ref.x,
188
+ y = _ref.y,
189
+ w = _ref.w,
190
+ h = _ref.h;
191
+
192
+ return new Promise(function (resolve) {
193
+ var otElement = tsMediaElement[tsMediaElement instanceof _publisher.TsMediaPublisher ? '_otpublisher' : '_otsubscriber'];
194
+ var crop = !_.isUndefined(x) && !_.isUndefined(y) && !_.isUndefined(w) && !_.isUndefined(h);
195
+ var resize = !crop && (!_.isUndefined(w) || !_.isUndefined(h));
196
+
197
+ if (!_this3._environment.isIE11() && format.toLowerCase() === 'image/png' && !crop && !resize) {
198
+ return resolve("data:image/png;base64,".concat(otElement.getImgData()));
273
199
  }
274
200
 
275
- /**
276
- * Whether the stream has audio. This property can change if the publisher turns on or off audio
277
- * (by calling Publisher.publishAudio()). When this occurs, the Session object dispatches a streamPropertyChanged
278
- * event (see StreamPropertyChangedEvent).
279
- */
280
-
281
- }, {
282
- key: 'hasAudio',
283
- get: function get() {
284
- return this._otstream.hasAudio;
285
- }
201
+ var videoElement = _this3.getVideoElement(otElement.element);
202
+
203
+ if (!_this3._environment.isIE11()) {
204
+ var videoElem = videoElement[0];
205
+ var canvas = document.createElement('canvas');
206
+ var ctx = canvas.getContext('2d');
207
+
208
+ if (crop) {
209
+ canvas.width = w;
210
+ canvas.height = h;
211
+ ctx.drawImage(videoElem, x, y, w, h, 0, 0, w, h);
212
+ } else if (resize) {
213
+ if (!h) {
214
+ h = w * (videoElem.videoHeight / videoElem.videoWidth);
215
+ } else if (!w) {
216
+ w = h * (videoElem.videoWidth / videoElem.videoHeight);
217
+ }
286
218
 
287
- /**
288
- * Indicates if video channel exists in the stream.
289
- */
219
+ canvas.width = w;
220
+ canvas.height = h;
221
+ ctx.drawImage(videoElem, 0, 0, w, h);
222
+ } else {
223
+ canvas.width = videoElem.videoWidth;
224
+ canvas.height = videoElem.videoHeight;
225
+ ctx.drawImage(videoElem, 0, 0);
226
+ }
290
227
 
291
- }, {
292
- key: 'videoChannelExists',
293
- get: function get() {
294
- return this._videoChannelExists;
228
+ return resolve(canvas.toDataURL(format, quality));
295
229
  }
296
230
 
297
- /**
298
- * Indicates if audio channel exists in the stream.
299
- */
231
+ var currentWidth = videoElement.width();
232
+ var currentHeight = videoElement.height();
233
+ var currentPosition = videoElement.position();
234
+ var _this3$videoDimension = _this3.videoDimensions,
235
+ videoWidth = _this3$videoDimension.width,
236
+ videoHeight = _this3$videoDimension.height;
237
+ var ratio = Math.max(videoWidth / currentWidth, videoHeight / currentHeight);
238
+ videoElement.width(videoWidth / ratio);
239
+ videoElement.height(videoHeight / ratio);
240
+ videoElement.css({
241
+ left: currentPosition.left + Math.max(0, (currentWidth - videoWidth / ratio) / 2) + 'px',
242
+ top: currentPosition.top + Math.max(0, (currentHeight - videoHeight / ratio) / 2) + 'px'
243
+ });
244
+ setTimeout(function () {
245
+ var pngDataURL = "data:image/png;base64,".concat(otElement.getImgData());
246
+
247
+ if (format.toLowerCase() === 'image/png' && !crop && !resize) {
248
+ resolve(pngDataURL);
249
+ } else {
250
+ var img = new Image(),
251
+ _canvas = document.createElement('canvas'),
252
+ _ctx = _canvas.getContext('2d');
253
+
254
+ img.onload = function () {
255
+ if (crop) {
256
+ var widthRatio = img.width / videoWidth;
257
+ var heightRatio = img.height / videoHeight;
258
+ x = x && x * widthRatio;
259
+ y = y && y * heightRatio;
260
+ w = w && w * widthRatio;
261
+ h = h && h * heightRatio;
262
+ _canvas.width = w;
263
+ _canvas.height = h;
264
+
265
+ _ctx.drawImage(img, x, y, w, h, 0, 0, w, h);
266
+ } else if (resize) {
267
+ if (!h) {
268
+ h = w * (videoHeight / videoWidth);
269
+ } else if (!w) {
270
+ w = h * (videoWidth / videoHeight);
271
+ }
300
272
 
301
- }, {
302
- key: 'audioChannelExists',
303
- get: function get() {
304
- return this._audioChannelExists;
273
+ _canvas.width = w;
274
+ _canvas.height = h;
275
+
276
+ _ctx.drawImage(img, 0, 0, w, h);
277
+ } else {
278
+ _canvas.width = img.width;
279
+ _canvas.height = img.height;
280
+
281
+ _ctx.drawImage(img);
282
+ }
283
+
284
+ return resolve(_canvas.toDataURL(format, quality));
285
+ };
286
+
287
+ img.src = pngDataURL;
288
+ }
289
+
290
+ videoElement.width(currentWidth);
291
+ videoElement.height(currentHeight);
292
+ videoElement.css({
293
+ left: currentPosition.left + 'px',
294
+ top: currentPosition.top + 'px'
295
+ });
296
+ }, timeout * 1000);
297
+ }).then(function (imgData) {
298
+ if (!imgData || imgData.length < 10) {
299
+ return Promise.reject('Failed to get a snapshot');
305
300
  }
306
- }]);
307
301
 
308
- return TsOpenTokStream;
302
+ return imgData;
303
+ });
304
+ }
305
+ }, {
306
+ key: "getStats",
307
+ value: function getStats(subscriber) {
308
+ return new Promise(function (resolve, reject) {
309
+ subscriber._otsubscriber.getStats(function (err, stats) {
310
+ if (err) {
311
+ return reject(err);
312
+ }
313
+
314
+ return resolve(stats);
315
+ });
316
+ });
317
+ }
318
+ }]);
319
+
320
+ return TsOpenTokStream;
309
321
  }(_stream.TsMediaStream);
322
+
323
+ exports.TsOpenTokStream = TsOpenTokStream;
310
324
  //# sourceMappingURL=stream.js.map