@techsee/techsee-media-service 0.7.0-alpha.2 → 0.7.0

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 (149) hide show
  1. package/lib/LocalStreamManager.d.ts +21 -0
  2. package/lib/LocalStreamManager.d.ts.map +1 -0
  3. package/lib/LocalStreamManager.js +268 -0
  4. package/lib/LocalStreamManager.js.map +1 -0
  5. package/lib/MediaConstants.d.ts +52 -0
  6. package/lib/MediaConstants.d.ts.map +1 -0
  7. package/lib/MediaConstants.js +68 -0
  8. package/lib/MediaConstants.js.map +1 -0
  9. package/lib/MediaContracts.d.ts +122 -0
  10. package/lib/MediaContracts.d.ts.map +1 -0
  11. package/lib/MediaContracts.js +6 -0
  12. package/lib/MediaContracts.js.map +1 -0
  13. package/lib/MediaPublisher.d.ts +14 -0
  14. package/lib/MediaPublisher.d.ts.map +1 -0
  15. package/lib/MediaPublisher.js +43 -0
  16. package/lib/MediaPublisher.js.map +1 -0
  17. package/lib/MediaServiceBase.d.ts +64 -0
  18. package/lib/MediaServiceBase.d.ts.map +1 -0
  19. package/lib/MediaServiceBase.js +591 -0
  20. package/lib/MediaServiceBase.js.map +1 -0
  21. package/lib/MediaSession/MediaSessionBase.d.ts +23 -0
  22. package/lib/MediaSession/MediaSessionBase.d.ts.map +1 -0
  23. package/lib/MediaSession/MediaSessionBase.js +63 -0
  24. package/lib/MediaSession/MediaSessionBase.js.map +1 -0
  25. package/lib/MediaSession/SessionOpentok.d.ts +49 -0
  26. package/lib/MediaSession/SessionOpentok.d.ts.map +1 -0
  27. package/lib/MediaSession/SessionOpentok.js +379 -0
  28. package/lib/MediaSession/SessionOpentok.js.map +1 -0
  29. package/lib/MediaSession/SessionTurn.d.ts +32 -0
  30. package/lib/MediaSession/SessionTurn.d.ts.map +1 -0
  31. package/lib/MediaSession/SessionTurn.js +439 -0
  32. package/lib/MediaSession/SessionTurn.js.map +1 -0
  33. package/lib/MediaSession/TurnConstants.d.ts +18 -0
  34. package/lib/MediaSession/TurnConstants.d.ts.map +1 -0
  35. package/lib/MediaSession/TurnConstants.js +36 -0
  36. package/lib/MediaSession/TurnConstants.js.map +1 -0
  37. package/lib/MediaSubscriber.d.ts +36 -0
  38. package/lib/MediaSubscriber.d.ts.map +1 -0
  39. package/lib/MediaSubscriber.js +208 -0
  40. package/lib/MediaSubscriber.js.map +1 -0
  41. package/lib/MediaUtils/Compatibility.d.ts +11 -0
  42. package/lib/MediaUtils/Compatibility.d.ts.map +1 -0
  43. package/lib/MediaUtils/Compatibility.js +71 -0
  44. package/lib/MediaUtils/Compatibility.js.map +1 -0
  45. package/lib/MediaUtils/MediaDomUtils.d.ts +4 -0
  46. package/lib/MediaUtils/MediaDomUtils.d.ts.map +1 -0
  47. package/lib/MediaUtils/MediaDomUtils.js +200 -0
  48. package/lib/MediaUtils/MediaDomUtils.js.map +1 -0
  49. package/lib/MediaUtils/MediaTracer.d.ts +3 -0
  50. package/lib/MediaUtils/MediaTracer.d.ts.map +1 -0
  51. package/lib/MediaUtils/MediaTracer.js +12 -0
  52. package/lib/MediaUtils/MediaTracer.js.map +1 -0
  53. package/lib/TechseeMediaStream.d.ts +14 -0
  54. package/lib/TechseeMediaStream.d.ts.map +1 -0
  55. package/lib/TechseeMediaStream.js +58 -0
  56. package/lib/TechseeMediaStream.js.map +1 -0
  57. package/lib/oldCode/constants.js.map +1 -0
  58. package/lib/oldCode/event-emitter.js.map +1 -0
  59. package/lib/{index.js → oldCode/index.js} +1 -1
  60. package/lib/oldCode/index.js.map +1 -0
  61. package/lib/{opentok → oldCode/opentok}/session.js +6 -0
  62. package/lib/oldCode/opentok/session.js.map +1 -0
  63. package/lib/oldCode/opentok/stream.js.map +1 -0
  64. package/lib/oldCode/publisher.js.map +1 -0
  65. package/lib/{service.js → oldCode/service.js} +4 -6
  66. package/lib/oldCode/service.js.map +1 -0
  67. package/lib/oldCode/session.js.map +1 -0
  68. package/lib/oldCode/stream.js.map +1 -0
  69. package/lib/oldCode/subscriber.js.map +1 -0
  70. package/lib/oldCode/tracer.d.ts +35 -0
  71. package/lib/oldCode/tracer.d.ts.map +1 -0
  72. package/lib/oldCode/tracer.js +151 -0
  73. package/lib/oldCode/tracer.js.map +1 -0
  74. package/lib/oldCode/utils/ImageFixer.d.ts +1 -0
  75. package/lib/oldCode/utils/ImageFixer.d.ts.map +1 -0
  76. package/lib/oldCode/utils/ImageFixer.js +58 -0
  77. package/lib/oldCode/utils/ImageFixer.js.map +1 -0
  78. package/lib/oldCode/webrtc/constants.js.map +1 -0
  79. package/lib/{webrtc → oldCode/webrtc}/helper.js +2 -4
  80. package/lib/oldCode/webrtc/helper.js.map +1 -0
  81. package/lib/oldCode/webrtc/session-kms.js.map +1 -0
  82. package/lib/oldCode/webrtc/session-loopback.js.map +1 -0
  83. package/lib/{webrtc → oldCode/webrtc}/session-turn.js +47 -41
  84. package/lib/oldCode/webrtc/session-turn.js.map +1 -0
  85. package/lib/{webrtc → oldCode/webrtc}/session-turn.v2.js +85 -48
  86. package/lib/oldCode/webrtc/session-turn.v2.js.map +1 -0
  87. package/lib/oldCode/webrtc/session.js.map +1 -0
  88. package/lib/{webrtc → oldCode/webrtc}/stream.js +7 -9
  89. package/lib/oldCode/webrtc/stream.js.map +1 -0
  90. package/lib/oldCode/webrtc/temasys/adapter-loader.js.map +1 -0
  91. package/lib/oldCode/webrtc/temasys/adapter.js.map +1 -0
  92. package/lib/oldCode/webrtc/webrtc-ie-shim.js.map +1 -0
  93. package/lib/qos/raw-qos.js.map +1 -1
  94. package/lib/webrtc-ie-shim.js +3218 -0
  95. package/lib/webrtc-ie-shim.js.map +1 -0
  96. package/package.json +7 -5
  97. package/lib/constants.js.map +0 -1
  98. package/lib/event-emitter.js.map +0 -1
  99. package/lib/index.js.map +0 -1
  100. package/lib/opentok/session.js.map +0 -1
  101. package/lib/opentok/stream.js.map +0 -1
  102. package/lib/publisher.js.map +0 -1
  103. package/lib/service.js.map +0 -1
  104. package/lib/session.js.map +0 -1
  105. package/lib/stream.js.map +0 -1
  106. package/lib/subscriber.js.map +0 -1
  107. package/lib/tracer.js +0 -22
  108. package/lib/tracer.js.map +0 -1
  109. package/lib/v2/Contracts.d.ts +0 -41
  110. package/lib/v2/Contracts.d.ts.map +0 -1
  111. package/lib/v2/Contracts.js +0 -31
  112. package/lib/v2/Contracts.js.map +0 -1
  113. package/lib/v2/LocalStreamManager.d.ts +0 -8
  114. package/lib/v2/LocalStreamManager.d.ts.map +0 -1
  115. package/lib/v2/LocalStreamManager.js +0 -94
  116. package/lib/v2/LocalStreamManager.js.map +0 -1
  117. package/lib/v2/MediaServiceBase.d.ts +0 -24
  118. package/lib/v2/MediaServiceBase.d.ts.map +0 -1
  119. package/lib/v2/MediaServiceBase.js +0 -85
  120. package/lib/v2/MediaServiceBase.js.map +0 -1
  121. package/lib/v2/MediaSubscriber.d.ts +0 -8
  122. package/lib/v2/MediaSubscriber.d.ts.map +0 -1
  123. package/lib/v2/MediaSubscriber.js +0 -17
  124. package/lib/v2/MediaSubscriber.js.map +0 -1
  125. package/lib/webrtc/constants.js.map +0 -1
  126. package/lib/webrtc/helper.js.map +0 -1
  127. package/lib/webrtc/session-kms.js.map +0 -1
  128. package/lib/webrtc/session-loopback.js.map +0 -1
  129. package/lib/webrtc/session-turn.js.map +0 -1
  130. package/lib/webrtc/session-turn.v2.js.map +0 -1
  131. package/lib/webrtc/session.js.map +0 -1
  132. package/lib/webrtc/stream.js.map +0 -1
  133. package/lib/webrtc/temasys/adapter-loader.js.map +0 -1
  134. package/lib/webrtc/temasys/adapter.js.map +0 -1
  135. package/lib/webrtc/webrtc-ie-shim.js.map +0 -1
  136. /package/lib/{constants.js → oldCode/constants.js} +0 -0
  137. /package/lib/{event-emitter.js → oldCode/event-emitter.js} +0 -0
  138. /package/lib/{opentok → oldCode/opentok}/stream.js +0 -0
  139. /package/lib/{publisher.js → oldCode/publisher.js} +0 -0
  140. /package/lib/{session.js → oldCode/session.js} +0 -0
  141. /package/lib/{stream.js → oldCode/stream.js} +0 -0
  142. /package/lib/{subscriber.js → oldCode/subscriber.js} +0 -0
  143. /package/lib/{webrtc → oldCode/webrtc}/constants.js +0 -0
  144. /package/lib/{webrtc → oldCode/webrtc}/session-kms.js +0 -0
  145. /package/lib/{webrtc → oldCode/webrtc}/session-loopback.js +0 -0
  146. /package/lib/{webrtc → oldCode/webrtc}/session.js +0 -0
  147. /package/lib/{webrtc → oldCode/webrtc}/temasys/adapter-loader.js +0 -0
  148. /package/lib/{webrtc → oldCode/webrtc}/temasys/adapter.js +0 -0
  149. /package/lib/{webrtc → oldCode/webrtc}/webrtc-ie-shim.js +0 -0
@@ -0,0 +1,3218 @@
1
+ 'use strict';
2
+
3
+ var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
+
5
+ (function (f) {
6
+ if ((typeof exports === 'undefined' ? 'undefined' : _typeof2(exports)) === 'object' && typeof module !== 'undefined') {
7
+ module.exports = f();
8
+ } else if (typeof define === 'function' && define.amd) {
9
+ define([], f);
10
+ } else {
11
+ var g;
12
+
13
+ if (typeof window !== 'undefined') {
14
+ g = window;
15
+ } else if (typeof global !== 'undefined') {
16
+ g = global;
17
+ } else if (typeof self !== 'undefined') {
18
+ g = self;
19
+ } else {
20
+ g = this;
21
+ }g.webrtcIeShim = f();
22
+ }
23
+ })(function () {
24
+ var define, module, exports;
25
+
26
+ return function () {
27
+ function r(e, n, t) {
28
+ function o(i, f) {
29
+ if (!n[i]) {
30
+ if (!e[i]) {
31
+ var c = typeof require === 'function' && require;
32
+
33
+ if (!f && c) {
34
+ return c(i, !0);
35
+ }if (u) {
36
+ return u(i, !0);
37
+ }var a = new Error('Cannot find module \'' + i + '\'');
38
+
39
+ throw a.code = 'MODULE_NOT_FOUND', a;
40
+ }var p = n[i] = { exports: {} };
41
+
42
+ e[i][0].call(p.exports, function (r) {
43
+ var n = e[i][1][r];
44
+
45
+ return o(n || r);
46
+ }, p, p.exports, r, e, n, t);
47
+ }
48
+
49
+ return n[i].exports;
50
+ }for (var u = typeof require === 'function' && require, i = 0; i < t.length; i++) {
51
+ o(t[i]);
52
+ }
53
+
54
+ return o;
55
+ }
56
+
57
+ return r;
58
+ }()({ 1: [function (require, module, exports) {
59
+ exports.endianness = function () {
60
+ return 'LE';
61
+ };
62
+
63
+ exports.hostname = function () {
64
+ if (typeof location !== 'undefined') {
65
+ return location.hostname;
66
+ }
67
+
68
+ return '';
69
+ };
70
+
71
+ exports.loadavg = function () {
72
+ return [];
73
+ };
74
+
75
+ exports.uptime = function () {
76
+ return 0;
77
+ };
78
+
79
+ exports.freemem = function () {
80
+ return Number.MAX_VALUE;
81
+ };
82
+
83
+ exports.totalmem = function () {
84
+ return Number.MAX_VALUE;
85
+ };
86
+
87
+ exports.cpus = function () {
88
+ return [];
89
+ };
90
+
91
+ exports.type = function () {
92
+ return 'Browser';
93
+ };
94
+
95
+ exports.release = function () {
96
+ if (typeof navigator !== 'undefined') {
97
+ return navigator.appVersion;
98
+ }
99
+
100
+ return '';
101
+ };
102
+
103
+ exports.networkInterfaces = exports.getNetworkInterfaces = function () {
104
+ return {};
105
+ };
106
+
107
+ exports.arch = function () {
108
+ return 'javascript';
109
+ };
110
+
111
+ exports.platform = function () {
112
+ return 'browser';
113
+ };
114
+
115
+ exports.tmpdir = exports.tmpDir = function () {
116
+ return '/tmp';
117
+ };
118
+
119
+ exports.EOL = '\n';
120
+
121
+ exports.homedir = function () {
122
+ return '/';
123
+ };
124
+ }, {}], 2: [function (require, module, exports) {
125
+ // shim for using process in browser
126
+ var process = module.exports = {};
127
+
128
+ // cached from whatever global is present so that test runners that stub it
129
+ // don't break things. But we need to wrap it in a try catch in case it is
130
+ // wrapped in strict mode code which doesn't define any globals. It's inside a
131
+ // function because try/catches deoptimize in certain engines.
132
+
133
+ var cachedSetTimeout;
134
+ var cachedClearTimeout;
135
+
136
+ function defaultSetTimout() {
137
+ throw new Error('setTimeout has not been defined');
138
+ }
139
+ function defaultClearTimeout() {
140
+ throw new Error('clearTimeout has not been defined');
141
+ }
142
+ (function () {
143
+ try {
144
+ if (typeof setTimeout === 'function') {
145
+ cachedSetTimeout = setTimeout;
146
+ } else {
147
+ cachedSetTimeout = defaultSetTimout;
148
+ }
149
+ } catch (e) {
150
+ cachedSetTimeout = defaultSetTimout;
151
+ }
152
+ try {
153
+ if (typeof clearTimeout === 'function') {
154
+ cachedClearTimeout = clearTimeout;
155
+ } else {
156
+ cachedClearTimeout = defaultClearTimeout;
157
+ }
158
+ } catch (e) {
159
+ cachedClearTimeout = defaultClearTimeout;
160
+ }
161
+ })();
162
+ function runTimeout(fun) {
163
+ if (cachedSetTimeout === setTimeout) {
164
+ //normal enviroments in sane situations
165
+ return setTimeout(fun, 0);
166
+ }
167
+ // if setTimeout wasn't available but was latter defined
168
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
169
+ cachedSetTimeout = setTimeout;
170
+
171
+ return setTimeout(fun, 0);
172
+ }
173
+ try {
174
+ // when when somebody has screwed with setTimeout but no I.E. maddness
175
+ return cachedSetTimeout(fun, 0);
176
+ } catch (e) {
177
+ try {
178
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
179
+ return cachedSetTimeout.call(null, fun, 0);
180
+ } catch (e) {
181
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
182
+ return cachedSetTimeout.call(this, fun, 0);
183
+ }
184
+ }
185
+ }
186
+ function runClearTimeout(marker) {
187
+ if (cachedClearTimeout === clearTimeout) {
188
+ //normal enviroments in sane situations
189
+ return clearTimeout(marker);
190
+ }
191
+ // if clearTimeout wasn't available but was latter defined
192
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
193
+ cachedClearTimeout = clearTimeout;
194
+
195
+ return clearTimeout(marker);
196
+ }
197
+ try {
198
+ // when when somebody has screwed with setTimeout but no I.E. maddness
199
+ return cachedClearTimeout(marker);
200
+ } catch (e) {
201
+ try {
202
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
203
+ return cachedClearTimeout.call(null, marker);
204
+ } catch (e) {
205
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
206
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
207
+ return cachedClearTimeout.call(this, marker);
208
+ }
209
+ }
210
+ }
211
+ var queue = [];
212
+ var draining = false;
213
+ var currentQueue;
214
+ var queueIndex = -1;
215
+
216
+ function cleanUpNextTick() {
217
+ if (!draining || !currentQueue) {
218
+ return;
219
+ }
220
+ draining = false;
221
+ if (currentQueue.length) {
222
+ queue = currentQueue.concat(queue);
223
+ } else {
224
+ queueIndex = -1;
225
+ }
226
+ if (queue.length) {
227
+ drainQueue();
228
+ }
229
+ }
230
+
231
+ function drainQueue() {
232
+ if (draining) {
233
+ return;
234
+ }
235
+ var timeout = runTimeout(cleanUpNextTick);
236
+
237
+ draining = true;
238
+
239
+ var len = queue.length;
240
+
241
+ while (len) {
242
+ currentQueue = queue;
243
+ queue = [];
244
+ while (++queueIndex < len) {
245
+ if (currentQueue) {
246
+ currentQueue[queueIndex].run();
247
+ }
248
+ }
249
+ queueIndex = -1;
250
+ len = queue.length;
251
+ }
252
+ currentQueue = null;
253
+ draining = false;
254
+ runClearTimeout(timeout);
255
+ }
256
+
257
+ process.nextTick = function (fun) {
258
+ var args = new Array(arguments.length - 1);
259
+
260
+ if (arguments.length > 1) {
261
+ for (var i = 1; i < arguments.length; i++) {
262
+ args[i - 1] = arguments[i];
263
+ }
264
+ }
265
+ queue.push(new Item(fun, args));
266
+ if (queue.length === 1 && !draining) {
267
+ runTimeout(drainQueue);
268
+ }
269
+ };
270
+
271
+ // v8 likes predictible objects
272
+ function Item(fun, array) {
273
+ this.fun = fun;
274
+ this.array = array;
275
+ }
276
+ Item.prototype.run = function () {
277
+ this.fun.apply(null, this.array);
278
+ };
279
+ process.title = 'browser';
280
+ process.browser = true;
281
+ process.env = {};
282
+ process.argv = [];
283
+ process.version = ''; // empty string to avoid regexp issues
284
+ process.versions = {};
285
+
286
+ function noop() {}
287
+
288
+ process.on = noop;
289
+ process.addListener = noop;
290
+ process.once = noop;
291
+ process.off = noop;
292
+ process.removeListener = noop;
293
+ process.removeAllListeners = noop;
294
+ process.emit = noop;
295
+ process.prependListener = noop;
296
+ process.prependOnceListener = noop;
297
+
298
+ process.listeners = function (name) {
299
+ return [];
300
+ };
301
+
302
+ process.binding = function (name) {
303
+ throw new Error('process.binding is not supported');
304
+ };
305
+
306
+ process.cwd = function () {
307
+ return '/';
308
+ };
309
+ process.chdir = function (dir) {
310
+ throw new Error('process.chdir is not supported');
311
+ };
312
+ process.umask = function () {
313
+ return 0;
314
+ };
315
+ }, {}], 3: [function (require, module, exports) {
316
+ 'use strict';
317
+
318
+ var browser = require('detect-browser').detect();
319
+
320
+ var WebRTCProxy = require('./lib/WebRTCProxy.js');
321
+
322
+ //If it is not internet exploer, do nothign
323
+ if (browser.name === 'ie' && WebRTCProxy) {
324
+
325
+ //Helper functions to check video nodes
326
+ var checkNewNode = function checkNewNode(node) {
327
+ //If it is a video element
328
+ if (node.nodeName.match(/video/i))
329
+ // Observe changes in the video element
330
+ {
331
+ return VideoRenderer.handle(node);
332
+ }
333
+ //Look in childs
334
+ for (var j = 0; j < node.childNodes.length; j++) {
335
+ checkNewNode(node.childNodes.item(j));
336
+ }
337
+ };
338
+
339
+ var checkRemovedNode = function checkRemovedNode(node) {
340
+ //If it is a video element
341
+ if (node.nodeName.match(/video/i)) {
342
+ return VideoRenderer.unhandle(node);
343
+ }
344
+ //Look in childs
345
+ for (var j = 0; j < node.childNodes.length; j++) {
346
+ checkRemovedNode(node.childNodes.item(j));
347
+ }
348
+ };
349
+
350
+ var makeInterface = function makeInterface(Base) {
351
+ //Interface with no constructor
352
+ var Interface = function Interface() {
353
+ throw new TypeError();
354
+ };
355
+ //Set name
356
+
357
+ Object.defineProperty(Interface, 'name', {
358
+ enumerable: false,
359
+ configurable: true,
360
+ writable: false,
361
+ value: Base.name
362
+ });
363
+ //Create constructor and reset protocol chain
364
+ Interface.prototype = Object.create(Base.prototype, {
365
+ constructor: {
366
+ value: Interface,
367
+ configurable: true,
368
+ writable: false
369
+ }
370
+ });
371
+ //Fix protocol chain
372
+ Interface.__proto__ = Base.__proto__;
373
+ //Make prototype read only
374
+ Object.defineProperty(Interface, 'prototype', { writable: false });
375
+ //Ok
376
+ return Interface;
377
+ };
378
+
379
+ var defineGlobalProperty = function defineGlobalProperty(name, value) {
380
+ Object.defineProperty(window, name, {
381
+ enumerable: false,
382
+ configurable: true,
383
+ writable: true,
384
+ value: value
385
+ });
386
+ };
387
+
388
+ // Add objects to global
389
+ var MediaDevices = require('./lib/MediaDevices.js');
390
+ var VideoRenderer = require('./lib/VideoRenderer.js');
391
+
392
+ navigator.mediaDevices = new MediaDevices();
393
+
394
+ var RTCPeerConnection = require('./lib/RTCPeerConnection.js');
395
+ var RTCSessionDescription = require('./lib/RTCSessionDescription.js');
396
+ var RTCIceCandidate = require('./lib/RTCIceCandidate.js');
397
+ var RTCRtpTransceiver = require('./lib/RTCRtpTransceiver.js');
398
+ var RTCRtpReceiver = require('./lib/RTCRtpReceiver.js');
399
+ var RTCRtpSender = require('./lib/RTCRtpSender.js');
400
+ var RTCDataChannel = require('./lib/RTCDataChannel.js');
401
+ var MediaStream = require('./lib/MediaStream.js');
402
+ var MediaStreamTrack = require('./lib/MediaStreamTrack.js');
403
+ var EventTarget = require('./lib/EventTarget.js').EventTarget;
404
+ var WebRTCAdapter = {
405
+ //Method called by demand in IE for bind video elements
406
+ bindVideoElement: function bindVideoElement(element) {
407
+ checkNewNode(element);
408
+ },
409
+
410
+ //Method called by demand in IE for unbind video elements
411
+ unBindVideoElement: function unBindVideoElement(element) {
412
+ checkRemovedNode(element);
413
+ }
414
+ };
415
+
416
+ defineGlobalProperty('RTCPeerConnection', RTCPeerConnection);
417
+ defineGlobalProperty('RTCSessionDescription', RTCSessionDescription);
418
+ defineGlobalProperty('RTCIceCandidate', RTCIceCandidate);
419
+ defineGlobalProperty('MediaStream', MediaStream);
420
+ defineGlobalProperty('MediaStreamTrack', makeInterface(MediaStreamTrack));
421
+ defineGlobalProperty('RTCRtpTransceiver', makeInterface(RTCRtpTransceiver));
422
+ defineGlobalProperty('RTCRtpReceiver', makeInterface(RTCRtpReceiver));
423
+ defineGlobalProperty('RTCRtpSender', makeInterface(RTCRtpSender));
424
+ defineGlobalProperty('RTCDataChannel', makeInterface(RTCDataChannel));
425
+ defineGlobalProperty('EventTarget', EventTarget);
426
+ defineGlobalProperty('WebRTCAdapter', WebRTCProxy ? WebRTCAdapter : null);
427
+
428
+ // DOM mutation observer to check when a new video element has been added to the DOM
429
+ // TODO: Currently domObserver no observing, need to decide how to make it configurable to prevent performance issues.
430
+ var domObserver = new MutationObserver(function (mutations) {
431
+ for (var i = 0, numMutations = mutations.length; i < numMutations; i++) {
432
+ var mutation = mutations[i];
433
+
434
+ // Check if there has been addition or deletion of nodes
435
+ if (mutation.type !== 'childList') {
436
+ continue;
437
+ }
438
+
439
+ // Check added nodes.
440
+ for (var j = 0, numNodes = mutation.addedNodes.length; j < numNodes; j++) {
441
+ //Check node recursively
442
+ checkNewNode(mutation.addedNodes[j]);
443
+ } // Check removed nodes.
444
+ for (j = 0, numNodes = mutation.removedNodes.length; j < numNodes; j++) {
445
+ //Check node recursively
446
+ checkRemovedNode(mutation.removedNodes[j]);
447
+ }
448
+ }
449
+ });
450
+
451
+ //Get all video elements already present
452
+ var videos = document.getElementsByTagName('video');
453
+
454
+ //Handle them
455
+ for (var i = 0; i < videos.length; ++i) {
456
+ VideoRenderer.handle(videos[i]);
457
+ }
458
+ }
459
+ }, { './lib/EventTarget.js': 4, './lib/MediaDevices.js': 6, './lib/MediaStream.js': 7, './lib/MediaStreamTrack.js': 8, './lib/RTCDataChannel.js': 9, './lib/RTCIceCandidate.js': 10, './lib/RTCPeerConnection.js': 11, './lib/RTCRtpReceiver.js': 12, './lib/RTCRtpSender.js': 13, './lib/RTCRtpTransceiver.js': 14, './lib/RTCSessionDescription.js': 15, './lib/VideoRenderer.js': 16, './lib/WebRTCProxy.js': 17, 'detect-browser': 18 }], 4: [function (require, module, exports) {
460
+
461
+ /**
462
+ * @author Toru Nagashima <https://github.com/mysticatea>
463
+ * @copyright 2015 Toru Nagashima. All rights reserved.
464
+ * See LICENSE file in root directory for full license.
465
+ */
466
+ 'use strict';
467
+
468
+ /**
469
+ * @typedef {object} PrivateData
470
+ * @property {EventTarget} eventTarget The event target.
471
+ * @property {{type:string}} event The original event object.
472
+ * @property {number} eventPhase The current event phase.
473
+ * @property {EventTarget|null} currentTarget The current event target.
474
+ * @property {boolean} canceled The flag to prevent default.
475
+ * @property {boolean} stopped The flag to stop propagation immediately.
476
+ * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
477
+ * @property {number} timeStamp The unix time.
478
+ * @private
479
+ */
480
+
481
+ /**
482
+ * Private data for event wrappers.
483
+ * @type {WeakMap<Event, PrivateData>}
484
+ * @private
485
+ */
486
+
487
+ var _typeof = typeof Symbol === 'function' && _typeof2(Symbol.iterator) === 'symbol' ? function (obj) {
488
+ return typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
489
+ } : function (obj) {
490
+ return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype ? 'symbol' : typeof obj === 'undefined' ? 'undefined' : _typeof2(obj);
491
+ };
492
+
493
+ var privateData = new WeakMap();
494
+
495
+ /**
496
+ * Cache for wrapper classes.
497
+ * @type {WeakMap<Object, Function>}
498
+ * @private
499
+ */
500
+ var wrappers = new WeakMap();
501
+
502
+ /**
503
+ * Get private data.
504
+ * @param {Event} event The event object to get private data.
505
+ * @returns {PrivateData} The private data of the event.
506
+ * @private
507
+ */
508
+ function pd(event) {
509
+ var retv = privateData.get(event);
510
+
511
+ console.assert(retv != null, '\'this\' is expected an Event object, but got', event);
512
+
513
+ return retv;
514
+ }
515
+
516
+ /**
517
+ * @see https://dom.spec.whatwg.org/#interface-event
518
+ * @private
519
+ */
520
+ /**
521
+ * The event wrapper.
522
+ * @constructor
523
+ * @param {EventTarget} eventTarget The event target of this dispatching.
524
+ * @param {Event|{type:string}} event The original event to wrap.
525
+ */
526
+ function Event(eventTarget, event) {
527
+ privateData.set(this, {
528
+ eventTarget: eventTarget,
529
+ event: event,
530
+ eventPhase: 2,
531
+ currentTarget: eventTarget,
532
+ canceled: false,
533
+ stopped: false,
534
+ passiveListener: null,
535
+ timeStamp: event.timeStamp || Date.now()
536
+ });
537
+
538
+ // https://heycam.github.io/webidl/#Unforgeable
539
+ Object.defineProperty(this, 'isTrusted', { value: false, enumerable: true });
540
+
541
+ // Define accessors
542
+ var keys = Object.keys(event);
543
+
544
+ for (var i = 0; i < keys.length; ++i) {
545
+ var key = keys[i];
546
+
547
+ if (!(key in this)) {
548
+ Object.defineProperty(this, key, defineRedirectDescriptor(key));
549
+ }
550
+ }
551
+ }
552
+
553
+ // Should be enumerable, but class methods are not enumerable.
554
+ Event.prototype = {
555
+
556
+ /**
557
+ * The type of this event.
558
+ * @type {string}
559
+ */
560
+ get type() {
561
+ return pd(this).event.type;
562
+ },
563
+
564
+ /**
565
+ * The target of this event.
566
+ * @type {EventTarget}
567
+ */
568
+ get target() {
569
+ return pd(this).eventTarget;
570
+ },
571
+
572
+ /**
573
+ * The target of this event.
574
+ * @type {EventTarget}
575
+ */
576
+ get currentTarget() {
577
+ return pd(this).currentTarget;
578
+ },
579
+
580
+ /**
581
+ * @returns {EventTarget[]} The composed path of this event.
582
+ */
583
+ composedPath: function composedPath() {
584
+ var currentTarget = pd(this).currentTarget;
585
+
586
+ if (currentTarget == null) {
587
+ return [];
588
+ }
589
+
590
+ return [currentTarget];
591
+ },
592
+
593
+ /**
594
+ * Constant of NONE.
595
+ * @type {number}
596
+ */
597
+ get NONE() {
598
+ return 0;
599
+ },
600
+
601
+ /**
602
+ * Constant of CAPTURING_PHASE.
603
+ * @type {number}
604
+ */
605
+ get CAPTURING_PHASE() {
606
+ return 1;
607
+ },
608
+
609
+ /**
610
+ * Constant of AT_TARGET.
611
+ * @type {number}
612
+ */
613
+ get AT_TARGET() {
614
+ return 2;
615
+ },
616
+
617
+ /**
618
+ * Constant of BUBBLING_PHASE.
619
+ * @type {number}
620
+ */
621
+ get BUBBLING_PHASE() {
622
+ return 3;
623
+ },
624
+
625
+ /**
626
+ * The target of this event.
627
+ * @type {number}
628
+ */
629
+ get eventPhase() {
630
+ return pd(this).eventPhase;
631
+ },
632
+
633
+ /**
634
+ * Stop event bubbling.
635
+ * @returns {void}
636
+ */
637
+ stopPropagation: function stopPropagation() {
638
+ var data = pd(this);
639
+
640
+ if (typeof data.event.stopPropagation === 'function') {
641
+ data.event.stopPropagation();
642
+ }
643
+ },
644
+
645
+ /**
646
+ * Stop event bubbling.
647
+ * @returns {void}
648
+ */
649
+ stopImmediatePropagation: function stopImmediatePropagation() {
650
+ var data = pd(this);
651
+
652
+ data.stopped = true;
653
+ if (typeof data.event.stopImmediatePropagation === 'function') {
654
+ data.event.stopImmediatePropagation();
655
+ }
656
+ },
657
+
658
+ /**
659
+ * The flag to be bubbling.
660
+ * @type {boolean}
661
+ */
662
+ get bubbles() {
663
+ return Boolean(pd(this).event.bubbles);
664
+ },
665
+
666
+ /**
667
+ * The flag to be cancelable.
668
+ * @type {boolean}
669
+ */
670
+ get cancelable() {
671
+ return Boolean(pd(this).event.cancelable);
672
+ },
673
+
674
+ /**
675
+ * Cancel this event.
676
+ * @returns {void}
677
+ */
678
+ preventDefault: function preventDefault() {
679
+ var data = pd(this);
680
+
681
+ if (data.passiveListener != null) {
682
+ console.warn('Event#preventDefault() was called from a passive listener:', data.passiveListener);
683
+
684
+ return;
685
+ }
686
+ if (!data.event.cancelable) {
687
+ return;
688
+ }
689
+
690
+ data.canceled = true;
691
+ if (typeof data.event.preventDefault === 'function') {
692
+ data.event.preventDefault();
693
+ }
694
+ },
695
+
696
+ /**
697
+ * The flag to indicate cancellation state.
698
+ * @type {boolean}
699
+ */
700
+ get defaultPrevented() {
701
+ return pd(this).canceled;
702
+ },
703
+
704
+ /**
705
+ * The flag to be composed.
706
+ * @type {boolean}
707
+ */
708
+ get composed() {
709
+ return Boolean(pd(this).event.composed);
710
+ },
711
+
712
+ /**
713
+ * The unix time of this event.
714
+ * @type {number}
715
+ */
716
+ get timeStamp() {
717
+ return pd(this).timeStamp;
718
+ }
719
+ };
720
+
721
+ // `constructor` is not enumerable.
722
+ Object.defineProperty(Event.prototype, 'constructor', { value: Event, configurable: true, writable: true });
723
+
724
+ // Ensure `event instanceof window.Event` is `true`.
725
+ if (typeof window !== 'undefined' && typeof window.Event !== 'undefined') {
726
+ Object.setPrototypeOf(Event.prototype, window.Event.prototype);
727
+
728
+ // Make association for wrappers.
729
+ wrappers.set(window.Event.prototype, Event);
730
+ }
731
+
732
+ /**
733
+ * Get the property descriptor to redirect a given property.
734
+ * @param {string} key Property name to define property descriptor.
735
+ * @returns {PropertyDescriptor} The property descriptor to redirect the property.
736
+ * @private
737
+ */
738
+ function defineRedirectDescriptor(key) {
739
+ return {
740
+ get: function get() {
741
+ return pd(this).event[key];
742
+ },
743
+ set: function set(value) {
744
+ pd(this).event[key] = value;
745
+ },
746
+
747
+ configurable: true,
748
+ enumerable: true
749
+ };
750
+ }
751
+
752
+ /**
753
+ * Get the property descriptor to call a given method property.
754
+ * @param {string} key Property name to define property descriptor.
755
+ * @returns {PropertyDescriptor} The property descriptor to call the method property.
756
+ * @private
757
+ */
758
+ function defineCallDescriptor(key) {
759
+ return {
760
+ value: function value() {
761
+ var event = pd(this).event;
762
+
763
+ return event[key].apply(event, arguments);
764
+ },
765
+
766
+ configurable: true,
767
+ enumerable: true
768
+ };
769
+ }
770
+
771
+ /**
772
+ * Define new wrapper class.
773
+ * @param {Function} BaseEvent The base wrapper class.
774
+ * @param {Object} proto The prototype of the original event.
775
+ * @returns {Function} The defined wrapper class.
776
+ * @private
777
+ */
778
+ function defineWrapper(BaseEvent, proto) {
779
+ var keys = Object.keys(proto);
780
+
781
+ if (keys.length === 0) {
782
+ return BaseEvent;
783
+ }
784
+
785
+ /** CustomEvent */
786
+ function CustomEvent(eventTarget, event) {
787
+ BaseEvent.call(this, eventTarget, event);
788
+ }
789
+
790
+ CustomEvent.prototype = Object.create(BaseEvent.prototype, {
791
+ constructor: { value: CustomEvent, configurable: true, writable: true }
792
+ });
793
+
794
+ // Define accessors.
795
+ for (var i = 0; i < keys.length; ++i) {
796
+ var key = keys[i];
797
+
798
+ if (!(key in BaseEvent.prototype)) {
799
+ var descriptor = Object.getOwnPropertyDescriptor(proto, key);
800
+ var isFunc = typeof descriptor.value === 'function';
801
+
802
+ Object.defineProperty(CustomEvent.prototype, key, isFunc ? defineCallDescriptor(key) : defineRedirectDescriptor(key));
803
+ }
804
+ }
805
+
806
+ return CustomEvent;
807
+ }
808
+
809
+ /**
810
+ * Get the wrapper class of a given prototype.
811
+ * @param {Object} proto The prototype of the original event to get its wrapper.
812
+ * @returns {Function} The wrapper class.
813
+ * @private
814
+ */
815
+ function getWrapper(proto) {
816
+ if (proto == null || proto === Object.prototype) {
817
+ return Event;
818
+ }
819
+
820
+ var wrapper = wrappers.get(proto);
821
+
822
+ if (wrapper == null) {
823
+ wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
824
+ wrappers.set(proto, wrapper);
825
+ }
826
+
827
+ return wrapper;
828
+ }
829
+
830
+ /**
831
+ * Wrap a given event to management a dispatching.
832
+ * @param {EventTarget} eventTarget The event target of this dispatching.
833
+ * @param {Object} event The event to wrap.
834
+ * @returns {Event} The wrapper instance.
835
+ * @private
836
+ */
837
+ function wrapEvent(eventTarget, event) {
838
+ var Wrapper = getWrapper(Object.getPrototypeOf(event));
839
+
840
+ return new Wrapper(eventTarget, event);
841
+ }
842
+
843
+ /**
844
+ * Get the stopped flag of a given event.
845
+ * @param {Event} event The event to get.
846
+ * @returns {boolean} The flag to stop propagation immediately.
847
+ * @private
848
+ */
849
+ function isStopped(event) {
850
+ return pd(event).stopped;
851
+ }
852
+
853
+ /**
854
+ * Set the current event phase of a given event.
855
+ * @param {Event} event The event to set current target.
856
+ * @param {number} eventPhase New event phase.
857
+ * @returns {void}
858
+ * @private
859
+ */
860
+ function setEventPhase(event, eventPhase) {
861
+ pd(event).eventPhase = eventPhase;
862
+ }
863
+
864
+ /**
865
+ * Set the current target of a given event.
866
+ * @param {Event} event The event to set current target.
867
+ * @param {EventTarget|null} currentTarget New current target.
868
+ * @returns {void}
869
+ * @private
870
+ */
871
+ function setCurrentTarget(event, currentTarget) {
872
+ pd(event).currentTarget = currentTarget;
873
+ }
874
+
875
+ /**
876
+ * Set a passive listener of a given event.
877
+ * @param {Event} event The event to set current target.
878
+ * @param {Function|null} passiveListener New passive listener.
879
+ * @returns {void}
880
+ * @private
881
+ */
882
+ function setPassiveListener(event, passiveListener) {
883
+ pd(event).passiveListener = passiveListener;
884
+ }
885
+
886
+ /**
887
+ * @typedef {object} ListenerNode
888
+ * @property {Function} listener
889
+ * @property {1|2|3} listenerType
890
+ * @property {boolean} passive
891
+ * @property {boolean} once
892
+ * @property {ListenerNode|null} next
893
+ * @private
894
+ */
895
+
896
+ /**
897
+ * @type {WeakMap<object, Map<string, ListenerNode>>}
898
+ * @private
899
+ */
900
+ var listenersMap = new WeakMap();
901
+
902
+ // Listener types
903
+ var CAPTURE = 1;
904
+ var BUBBLE = 2;
905
+ var ATTRIBUTE = 3;
906
+
907
+ /**
908
+ * Check whether a given value is an object or not.
909
+ * @param {any} x The value to check.
910
+ * @returns {boolean} `true` if the value is an object.
911
+ */
912
+ function isObject(x) {
913
+ return x !== null && (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object'; //eslint-disable-line no-restricted-syntax
914
+ }
915
+
916
+ /**
917
+ * Get listeners.
918
+ * @param {EventTarget} eventTarget The event target to get.
919
+ * @returns {Map<string, ListenerNode>} The listeners.
920
+ * @private
921
+ */
922
+ function getListeners(eventTarget) {
923
+ var listeners = listenersMap.get(eventTarget);
924
+
925
+ console.assert(listeners != null, '\'this\' is expected an EventTarget object');
926
+
927
+ return listeners || new Map();
928
+ }
929
+
930
+ /**
931
+ * Get the property descriptor for the event attribute of a given event.
932
+ * @param {string} eventName The event name to get property descriptor.
933
+ * @returns {PropertyDescriptor} The property descriptor.
934
+ * @private
935
+ */
936
+ function defineEventAttributeDescriptor(eventName) {
937
+ return {
938
+ get: function get() {
939
+ var listeners = getListeners(this);
940
+ var node = listeners.get(eventName);
941
+
942
+ while (node != null) {
943
+ if (node.listenerType === ATTRIBUTE) {
944
+ return node.listener;
945
+ }
946
+ node = node.next;
947
+ }
948
+
949
+ return null;
950
+ },
951
+ set: function set(listener) {
952
+ if (typeof listener !== 'function' && !isObject(listener)) {
953
+ listener = null; // eslint-disable-line no-param-reassign
954
+ }
955
+ var listeners = getListeners(this);
956
+
957
+ // Traverse to the tail while removing old value.
958
+ var prev = null;
959
+ var node = listeners.get(eventName);
960
+
961
+ while (node != null) {
962
+ if (node.listenerType === ATTRIBUTE) {
963
+ // Remove old value.
964
+ if (prev !== null) {
965
+ prev.next = node.next;
966
+ } else if (node.next !== null) {
967
+ listeners.set(eventName, node.next);
968
+ } else {
969
+ listeners.delete(eventName);
970
+ }
971
+ } else {
972
+ prev = node;
973
+ }
974
+
975
+ node = node.next;
976
+ }
977
+
978
+ // Add new value.
979
+ if (listener !== null) {
980
+ var newNode = {
981
+ listener: listener,
982
+ listenerType: ATTRIBUTE,
983
+ passive: false,
984
+ once: false,
985
+ next: null
986
+ };
987
+
988
+ if (prev === null) {
989
+ listeners.set(eventName, newNode);
990
+ } else {
991
+ prev.next = newNode;
992
+ }
993
+ }
994
+ },
995
+
996
+ configurable: true,
997
+ enumerable: true
998
+ };
999
+ }
1000
+
1001
+ /**
1002
+ * Define an event attribute (e.g. `eventTarget.onclick`).
1003
+ * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
1004
+ * @param {string} eventName The event name to define.
1005
+ * @returns {void}
1006
+ */
1007
+ function defineEventAttribute(eventTargetPrototype, eventName) {
1008
+ Object.defineProperty(eventTargetPrototype, 'on' + eventName, defineEventAttributeDescriptor(eventName));
1009
+ }
1010
+
1011
+ /**
1012
+ * Define a custom EventTarget with event attributes.
1013
+ * @param {string[]} eventNames Event names for event attributes.
1014
+ * @returns {EventTarget} The custom EventTarget.
1015
+ * @private
1016
+ */
1017
+ function defineCustomEventTarget(eventNames) {
1018
+
1019
+ /** CustomEventTarget */
1020
+ function CustomEventTarget() {
1021
+ EventTarget.call(this);
1022
+ }
1023
+
1024
+ CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
1025
+ constructor: { value: CustomEventTarget, configurable: true, writable: true }
1026
+ });
1027
+
1028
+ for (var i = 0; i < eventNames.length; ++i) {
1029
+ defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
1030
+ }
1031
+
1032
+ return CustomEventTarget;
1033
+ }
1034
+
1035
+ /**
1036
+ * EventTarget.
1037
+ *
1038
+ * - This is constructor if no arguments.
1039
+ * - This is a function which returns a CustomEventTarget constructor if there are arguments.
1040
+ *
1041
+ * For example:
1042
+ *
1043
+ * class A extends EventTarget {}
1044
+ * class B extends EventTarget("message") {}
1045
+ * class C extends EventTarget("message", "error") {}
1046
+ * class D extends EventTarget(["message", "error"]) {}
1047
+ */
1048
+ function EventTarget() {
1049
+ /*eslint-disable consistent-return */
1050
+ if (this instanceof EventTarget) {
1051
+ listenersMap.set(this, new Map());
1052
+
1053
+ return;
1054
+ }
1055
+ if (arguments.length === 1 && Array.isArray(arguments[0])) {
1056
+ return defineCustomEventTarget(arguments[0]);
1057
+ }
1058
+ if (arguments.length > 0) {
1059
+ var types = new Array(arguments.length);
1060
+
1061
+ for (var i = 0; i < arguments.length; ++i) {
1062
+ types[i] = arguments[i];
1063
+ }
1064
+
1065
+ return defineCustomEventTarget(types);
1066
+ }
1067
+ throw new TypeError('Cannot call a class as a function');
1068
+ /*eslint-enable consistent-return */
1069
+ }
1070
+
1071
+ // Should be enumerable, but class methods are not enumerable.
1072
+ EventTarget.prototype = {
1073
+
1074
+ /**
1075
+ * Add a given listener to this event target.
1076
+ * @param {string} eventName The event name to add.
1077
+ * @param {Function} listener The listener to add.
1078
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1079
+ * @returns {boolean} `true` if the listener was added actually.
1080
+ */
1081
+ addEventListener: function addEventListener(eventName, listener, options) {
1082
+ if (listener == null) {
1083
+ return false;
1084
+ }
1085
+ if (typeof listener !== 'function' && !isObject(listener)) {
1086
+ throw new TypeError('\'listener\' should be a function or an object.');
1087
+ }
1088
+
1089
+ var listeners = getListeners(this);
1090
+ var optionsIsObj = isObject(options);
1091
+ var capture = optionsIsObj ? Boolean(options.capture) : Boolean(options);
1092
+ var listenerType = capture ? CAPTURE : BUBBLE;
1093
+ var newNode = {
1094
+ listener: listener,
1095
+ listenerType: listenerType,
1096
+ passive: optionsIsObj && Boolean(options.passive),
1097
+ once: optionsIsObj && Boolean(options.once),
1098
+ next: null
1099
+ };
1100
+
1101
+ // Set it as the first node if the first node is null.
1102
+ var node = listeners.get(eventName);
1103
+
1104
+ if (node === undefined) {
1105
+ listeners.set(eventName, newNode);
1106
+
1107
+ return true;
1108
+ }
1109
+
1110
+ // Traverse to the tail while checking duplication..
1111
+ var prev = null;
1112
+
1113
+ while (node != null) {
1114
+ if (node.listener === listener && node.listenerType === listenerType) {
1115
+ // Should ignore duplication.
1116
+ return false;
1117
+ }
1118
+ prev = node;
1119
+ node = node.next;
1120
+ }
1121
+
1122
+ // Add it.
1123
+ prev.next = newNode;
1124
+
1125
+ return true;
1126
+ },
1127
+
1128
+ /**
1129
+ * Remove a given listener from this event target.
1130
+ * @param {string} eventName The event name to remove.
1131
+ * @param {Function} listener The listener to remove.
1132
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
1133
+ * @returns {boolean} `true` if the listener was removed actually.
1134
+ */
1135
+ removeEventListener: function removeEventListener(eventName, listener, options) {
1136
+ if (listener == null) {
1137
+ return false;
1138
+ }
1139
+
1140
+ var listeners = getListeners(this);
1141
+ var capture = isObject(options) ? Boolean(options.capture) : Boolean(options);
1142
+ var listenerType = capture ? CAPTURE : BUBBLE;
1143
+
1144
+ var prev = null;
1145
+ var node = listeners.get(eventName);
1146
+
1147
+ while (node != null) {
1148
+ if (node.listener === listener && node.listenerType === listenerType) {
1149
+ if (prev !== null) {
1150
+ prev.next = node.next;
1151
+ } else if (node.next !== null) {
1152
+ listeners.set(eventName, node.next);
1153
+ } else {
1154
+ listeners.delete(eventName);
1155
+ }
1156
+
1157
+ return true;
1158
+ }
1159
+
1160
+ prev = node;
1161
+ node = node.next;
1162
+ }
1163
+
1164
+ return false;
1165
+ },
1166
+
1167
+ /**
1168
+ * Dispatch a given event.
1169
+ * @param {Event|{type:string}} event The event to dispatch.
1170
+ * @returns {boolean} `false` if canceled.
1171
+ */
1172
+ dispatchEvent: function dispatchEvent(event) {
1173
+ if (event == null || typeof event.type !== 'string') {
1174
+ throw new TypeError('"event.type" should be a string.');
1175
+ }
1176
+
1177
+ // If listeners aren't registered, terminate.
1178
+ var listeners = getListeners(this);
1179
+ var eventName = event.type;
1180
+ var node = listeners.get(eventName);
1181
+
1182
+ if (node == null) {
1183
+ return true;
1184
+ }
1185
+
1186
+ // Since we cannot rewrite several properties, so wrap object.
1187
+ var wrappedEvent = wrapEvent(this, event);
1188
+
1189
+ // This doesn't process capturing phase and bubbling phase.
1190
+ // This isn't participating in a tree.
1191
+ var prev = null;
1192
+
1193
+ while (node != null) {
1194
+ // Remove this listener if it's once
1195
+ if (node.once) {
1196
+ if (prev !== null) {
1197
+ prev.next = node.next;
1198
+ } else if (node.next !== null) {
1199
+ listeners.set(eventName, node.next);
1200
+ } else {
1201
+ listeners.delete(eventName);
1202
+ }
1203
+ } else {
1204
+ prev = node;
1205
+ }
1206
+
1207
+ // Call this listener
1208
+ setPassiveListener(wrappedEvent, node.passive ? node.listener : null);
1209
+ if (typeof node.listener === 'function') {
1210
+ node.listener.call(this, wrappedEvent);
1211
+ } else if (node.listenerType !== ATTRIBUTE && typeof node.listener.handleEvent === 'function') {
1212
+ node.listener.handleEvent(wrappedEvent);
1213
+ }
1214
+
1215
+ // Break if `event.stopImmediatePropagation` was called.
1216
+ if (isStopped(wrappedEvent)) {
1217
+ break;
1218
+ }
1219
+
1220
+ node = node.next;
1221
+ }
1222
+ setPassiveListener(wrappedEvent, null);
1223
+ setEventPhase(wrappedEvent, 0);
1224
+ setCurrentTarget(wrappedEvent, null);
1225
+
1226
+ return !wrappedEvent.defaultPrevented;
1227
+ }
1228
+ };
1229
+
1230
+ // `constructor` is not enumerable.
1231
+ Object.defineProperty(EventTarget.prototype, 'constructor', { value: EventTarget, configurable: true, writable: true });
1232
+
1233
+ // Ensure `eventTarget instanceof window.EventTarget` is `true`.
1234
+ if (typeof window !== 'undefined' && typeof window.EventTarget !== 'undefined') {
1235
+ Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
1236
+ }
1237
+
1238
+ module.exports = EventTarget;
1239
+ module.exports.EventTarget = module.exports.default = EventTarget;
1240
+ module.exports.defineEventAttribute = defineEventAttribute;
1241
+ }, {}], 5: [function (require, module, exports) {
1242
+ 'use strict';
1243
+
1244
+ function InvalidStateError() {
1245
+ try {
1246
+ var xhr = new XMLHttpRequest();
1247
+
1248
+ xhr.responseType = 'blob';
1249
+ } catch (e) {
1250
+ return e;
1251
+ }
1252
+ }
1253
+
1254
+ module.exports = InvalidStateError;
1255
+ }, {}], 6: [function (require, module, exports) {
1256
+ 'use strict';
1257
+
1258
+ var WebRTCProxy = require('./WebRTCProxy.js');
1259
+ var MediaStream = require('./MediaStream.js');
1260
+ var MediaStreamTrack = require('./MediaStreamTrack.js');
1261
+ var EventTarget = require('./EventTarget.js').EventTarget;
1262
+ var defineEventAttribute = require('./EventTarget.js').defineEventAttribute;
1263
+
1264
+ /*
1265
+ interface MediaDevices : EventTarget {
1266
+ attribute EventHandler ondevicechange;
1267
+ Promise<sequence<MediaDeviceInfo>> enumerateDevices();
1268
+ }
1269
+ partial interface MediaDevices {
1270
+ MediaTrackSupportedConstraints getSupportedConstraints();
1271
+ Promise<MediaStream> getUserMedia(optional MediaStreamConstraints constraints);
1272
+ }
1273
+ */
1274
+ var MediaDevices = function MediaDevices() {
1275
+ //Init event targetr
1276
+ EventTarget.call(this);
1277
+ };
1278
+
1279
+ //Inherit from Event Target
1280
+ MediaDevices.prototype = Object.create(EventTarget.prototype, {
1281
+ constructor: {
1282
+ value: MediaDevices,
1283
+ configurable: true,
1284
+ writable: true
1285
+ }
1286
+ });
1287
+
1288
+ // Define Event Handlers
1289
+ defineEventAttribute(MediaDevices.prototype, 'devicechange');
1290
+
1291
+ MediaDevices.prototype.enumerateDevices = function () {
1292
+ return new Promise(function (resolve, reject) {
1293
+ resolve([]);
1294
+ });
1295
+ };
1296
+
1297
+ MediaDevices.prototype.getSupportedConstraints = function () {
1298
+ throw 'Not supported yet';
1299
+ };
1300
+
1301
+ MediaDevices.prototype.getUserMedia = function (constraints) {
1302
+ return new Promise(function (resolve, reject) {
1303
+ var stream = new MediaStream();
1304
+ //If we are being requested audio
1305
+
1306
+ if (constraints.audio) {
1307
+ var options = {};
1308
+ //Get new track
1309
+ var track = WebRTCProxy.createLocalAudioTrack(options);
1310
+ //Add it to the stream
1311
+
1312
+ stream.addTrack(new MediaStreamTrack(track));
1313
+ }
1314
+ //If we are being requested video
1315
+ if (constraints.video) {
1316
+ var options = {};
1317
+ //Get new track
1318
+ var track = WebRTCProxy.createLocalVideoTrack(options);
1319
+ //Add it to the stream
1320
+
1321
+ stream.addTrack(new MediaStreamTrack(track));
1322
+ }
1323
+ //Done
1324
+ resolve(stream);
1325
+ });
1326
+ };
1327
+
1328
+ Object.defineProperty(MediaDevices, 'name', {
1329
+ enumerable: false,
1330
+ configurable: true,
1331
+ writable: false,
1332
+ value: 'MediaDevices'
1333
+ });
1334
+ Object.defineProperty(MediaDevices, 'prototype', { writable: false });
1335
+ module.exports = MediaDevices;
1336
+ }, { './EventTarget.js': 4, './MediaStream.js': 7, './MediaStreamTrack.js': 8, './WebRTCProxy.js': 17 }], 7: [function (require, module, exports) {
1337
+ 'use strict';
1338
+
1339
+ var MediaStreamTrack = require('./MediaStreamTrack');
1340
+ var EventTarget = require('./EventTarget.js').EventTarget;
1341
+ var defineEventAttribute = require('./EventTarget.js').defineEventAttribute;
1342
+
1343
+ /*
1344
+ [Exposed=Window,
1345
+ Constructor,
1346
+ Constructor(MediaStream stream),
1347
+ Constructor(sequence<MediaStreamTrack> tracks)]
1348
+ interface MediaStream : EventTarget {
1349
+ readonly attribute DOMString id;
1350
+ sequence<MediaStreamTrack> getAudioTracks();
1351
+ sequence<MediaStreamTrack> getVideoTracks();
1352
+ sequence<MediaStreamTrack> getTracks();
1353
+ MediaStreamTrack? getTrackById(DOMString trackId);
1354
+ void addTrack(MediaStreamTrack track);
1355
+ void removeTrack(MediaStreamTrack track);
1356
+ MediaStream clone();
1357
+ readonly attribute boolean active;
1358
+ attribute EventHandler onaddtrack;
1359
+ attribute EventHandler onremovetrack;
1360
+ };
1361
+ */
1362
+ var count = 0;
1363
+
1364
+ var MediaStream = function MediaStream(tracks, label) {
1365
+ //Init event target
1366
+ EventTarget.call(this);
1367
+
1368
+ //Private vars
1369
+ this.priv = {
1370
+ tracks: {}
1371
+ };
1372
+
1373
+ //Actual WebRTC MediaStream supports MediaStream or array of MediaTracks as constructor input.
1374
+ //Because of time constraints we implementing the support for array of tracks only.
1375
+ if (tracks) {
1376
+ if (!(tracks instanceof Array)) {
1377
+ throw new Error('tracks should be an array of MediaStreamTrack');
1378
+ }
1379
+
1380
+ for (var i = 0; i < tracks.length; ++i) {
1381
+ if (!(tracks[i] instanceof MediaStreamTrack)) {
1382
+ throw new Error('Each item in tracks array should be an instance of MediaStreamTrack');
1383
+ }
1384
+ this.priv.tracks[tracks[i].id] = tracks[i];
1385
+ }
1386
+ }
1387
+
1388
+ var id = label || 'stream-' + count++;
1389
+
1390
+ Object.defineProperty(this, 'id', { enumerable: true, configurable: false, writable: false, value: id });
1391
+ Object.defineProperty(this, 'active', { enumerable: true, configurable: false, writable: false, value: true });
1392
+
1393
+ return this;
1394
+ };
1395
+
1396
+ //Inherit from Event Target
1397
+ MediaStream.prototype = Object.create(EventTarget.prototype, {
1398
+ constructor: {
1399
+ value: MediaStream,
1400
+ configurable: true,
1401
+ writable: true
1402
+ }
1403
+ });
1404
+ MediaStream.__proto__ = EventTarget;
1405
+
1406
+ // Define Event Handlers
1407
+ defineEventAttribute(MediaStream.prototype, 'addtrack');
1408
+ defineEventAttribute(MediaStream.prototype, 'removetrack');
1409
+
1410
+ MediaStream.prototype.getAudioTracks = function () {
1411
+ var arr = [];
1412
+
1413
+ for (var id in this.priv.tracks) {
1414
+ if (this.priv.tracks[id].kind === 'audio') {
1415
+ arr.push(this.priv.tracks[id]);
1416
+ }
1417
+ }
1418
+
1419
+ return arr;
1420
+ };
1421
+
1422
+ MediaStream.prototype.getVideoTracks = function () {
1423
+ var arr = [];
1424
+
1425
+ for (var id in this.priv.tracks) {
1426
+ if (this.priv.tracks[id].kind === 'video') {
1427
+ arr.push(this.priv.tracks[id]);
1428
+ }
1429
+ }
1430
+
1431
+ return arr;
1432
+ };
1433
+
1434
+ MediaStream.prototype.getTracks = function () {
1435
+ var arr = [];
1436
+
1437
+ for (var id in this.priv.tracks) {
1438
+ arr.push(this.priv.tracks[id]);
1439
+ }
1440
+
1441
+ return arr;
1442
+ };
1443
+
1444
+ MediaStream.prototype.getTrackById = function (id) {
1445
+ return this.priv.tracks[id];
1446
+ };
1447
+
1448
+ MediaStream.prototype.addTrack = function (track) {
1449
+ //Check if already present
1450
+ if (this.priv.tracks.hasOwnProperty(track.id)) {
1451
+ return;
1452
+ }
1453
+ //Add to track
1454
+ this.priv.tracks[track.id] = track;
1455
+
1456
+ if (typeof this.priv.tracks[track.id].enabled !== 'boolean') {
1457
+ this.priv.tracks[track.id].enabled = true;
1458
+ }
1459
+
1460
+ //Create event
1461
+ var event = document.createEvent('Event');
1462
+
1463
+ event.initEvent('addtrack', false, false);
1464
+ event.track = track;
1465
+ //Fire it
1466
+ this.dispatchEvent(event);
1467
+ };
1468
+
1469
+ MediaStream.prototype.removeTrack = function (track) {
1470
+ //Check if it is not already present
1471
+ if (!this.priv.tracks.hasOwnProperty(track.id)) {
1472
+ return;
1473
+ }
1474
+ //Add to track
1475
+ delete this.priv.tracks[track.id];
1476
+ //Create event
1477
+ var event = document.createEvent('Event');
1478
+
1479
+ event.initEvent('removetrack', false, false);
1480
+ event.track = track;
1481
+ //Fire it
1482
+ this.dispatchEvent(event);
1483
+ };
1484
+
1485
+ MediaStream.prototype.clone = function () {
1486
+ return new MediaStream(this.getTracks());
1487
+ };
1488
+
1489
+ Object.defineProperty(MediaStream, 'name', {
1490
+ enumerable: false,
1491
+ configurable: true,
1492
+ writable: false,
1493
+ value: 'MediaStream'
1494
+ });
1495
+ Object.defineProperty(MediaStream, 'prototype', { writable: false });
1496
+ module.exports = MediaStream;
1497
+ }, { './EventTarget.js': 4, './MediaStreamTrack': 8 }], 8: [function (require, module, exports) {
1498
+ 'use strict';
1499
+
1500
+ var EventTarget = require('./EventTarget.js').EventTarget;
1501
+ var defineEventAttribute = require('./EventTarget.js').defineEventAttribute;
1502
+
1503
+ /*
1504
+ [Exposed=Window]
1505
+ interface MediaStreamTrack : EventTarget {
1506
+ readonly attribute DOMString kind;
1507
+ readonly attribute DOMString id;
1508
+ readonly attribute DOMString label;
1509
+ attribute boolean enabled;
1510
+ readonly attribute boolean muted;
1511
+ attribute EventHandler onmute;
1512
+ attribute EventHandler onunmute;
1513
+ readonly attribute MediaStreamTrackState readyState;
1514
+ attribute EventHandler onended;
1515
+ MediaStreamTrack clone();
1516
+ void stop();
1517
+ MediaTrackCapabilities getCapabilities();
1518
+ MediaTrackConstraints getConstraints();
1519
+ MediaTrackSettings getSettings();
1520
+ Promise<void> applyConstraints(optional MediaTrackConstraints constraints);
1521
+ attribute EventHandler onoverconstrained;
1522
+ };
1523
+ partial interface MediaStreamTrack {
1524
+ readonly attribute boolean isolated;
1525
+ attribute EventHandler onisolationchange;
1526
+ };
1527
+ */
1528
+ var MediaStreamTrack = function MediaStreamTrack(track) {
1529
+ //Init event targetr
1530
+ EventTarget.call(this);
1531
+
1532
+ //Private vars
1533
+ var priv = this.priv = {
1534
+ track: track,
1535
+ muted: false,
1536
+ enabled: true
1537
+ };
1538
+
1539
+ Object.defineProperty(this, 'kind', {
1540
+ enumerable: true, configurable: false, get: function get() {
1541
+ return priv.track.kind;
1542
+ }
1543
+ });
1544
+ Object.defineProperty(this, 'id', {
1545
+ enumerable: true, configurable: false, get: function get() {
1546
+ return priv.track.id;
1547
+ }
1548
+ });
1549
+ Object.defineProperty(this, 'label', {
1550
+ enumerable: true, configurable: false, get: function get() {
1551
+ return priv.track.id;
1552
+ }
1553
+ });
1554
+ Object.defineProperty(this, 'enabled', {
1555
+ enumerable: true, configurable: false, get: function get() {
1556
+ return priv.enabled;
1557
+ }, set: function set(enabled) {
1558
+ priv.enabled = !!enabled;
1559
+ }
1560
+ });
1561
+ Object.defineProperty(this, 'muted', {
1562
+ enumerable: true, configurable: false, get: function get() {
1563
+ return priv.muted;
1564
+ }
1565
+ });
1566
+ Object.defineProperty(this, 'readyState', {
1567
+ enumerable: true, configurable: false, get: function get() {
1568
+ return priv.track.state;
1569
+ }
1570
+ });
1571
+ Object.defineProperty(this, 'isolated', {
1572
+ enumerable: true, configurable: false, get: function get() {
1573
+ return false;
1574
+ }
1575
+ });
1576
+
1577
+ return this;
1578
+ };
1579
+
1580
+ //Inherit from Event Target
1581
+ MediaStreamTrack.prototype = Object.create(EventTarget.prototype, {
1582
+ constructor: {
1583
+ value: MediaStreamTrack,
1584
+ configurable: true,
1585
+ writable: false
1586
+ }
1587
+ });
1588
+
1589
+ MediaStreamTrack.__proto__ = EventTarget;
1590
+
1591
+ // Define Event Handlers
1592
+ //TODO: fire them somehow
1593
+ defineEventAttribute(MediaStreamTrack.prototype, 'mute');
1594
+ defineEventAttribute(MediaStreamTrack.prototype, 'unmute');
1595
+ defineEventAttribute(MediaStreamTrack.prototype, 'ended');
1596
+ defineEventAttribute(MediaStreamTrack.prototype, 'isolationchange');
1597
+
1598
+ MediaStreamTrack.prototype.clone = function () {
1599
+ return null;
1600
+ };
1601
+
1602
+ MediaStreamTrack.prototype.stop = function () {
1603
+ this.priv.track.stop();
1604
+ };
1605
+
1606
+ MediaStreamTrack.prototype.getCapabilities = function () {};
1607
+
1608
+ MediaStreamTrack.prototype.getConstraints = function () {};
1609
+
1610
+ MediaStreamTrack.prototype.getSettings = function () {};
1611
+
1612
+ MediaStreamTrack.prototype.applyConstraints = function () {};
1613
+
1614
+ Object.defineProperty(MediaStreamTrack, 'name', {
1615
+ enumerable: false,
1616
+ configurable: true,
1617
+ writable: false,
1618
+ value: 'MediaStreamTrack'
1619
+ });
1620
+ module.exports = MediaStreamTrack;
1621
+ }, { './EventTarget.js': 4 }], 9: [function (require, module, exports) {
1622
+ 'use strict';
1623
+
1624
+ var EventTarget = require('./EventTarget.js').EventTarget;
1625
+ var defineEventAttribute = require('./EventTarget.js').defineEventAttribute;
1626
+ var InvalidStateError = require('./InvalidStateError.js');
1627
+
1628
+ /*
1629
+ [Exposed=Window]
1630
+ interface RTCRTCDataChannel : EventTarget {
1631
+ readonly attribute USVString label;
1632
+ readonly attribute boolean ordered;
1633
+ readonly attribute unsigned short? maxPacketLifeTime;
1634
+ readonly attribute unsigned short? maxRetransmits;
1635
+ readonly attribute USVString protocol;
1636
+ readonly attribute boolean negotiated;
1637
+ readonly attribute unsigned short? id;
1638
+ readonly attribute RTCPriorityType priority;
1639
+ readonly attribute RTCRTCDataChannelState readyState;
1640
+ readonly attribute unsigned long bufferedAmount;
1641
+ attribute unsigned long bufferedAmountLowThreshold;
1642
+ attribute EventHandler onopen;
1643
+ attribute EventHandler onbufferedamountlow;
1644
+ attribute EventHandler onerror;
1645
+ attribute EventHandler onclose;
1646
+ void close();
1647
+ attribute EventHandler onmessage;
1648
+ attribute DOMString binaryType;
1649
+ void send(USVString data);
1650
+ void send(Blob data);
1651
+ void send(ArrayBuffer data);
1652
+ void send(ArrayBufferView data);
1653
+ };
1654
+ */
1655
+ var RTCDataChannel = function RTCDataChannel(dataChannel) {
1656
+ //Init event targetr
1657
+ EventTarget.call(this);
1658
+
1659
+ //Private vars
1660
+ var self = this;
1661
+ var priv = this.priv = {
1662
+ binaryType: 'blob',
1663
+ dataChannel: dataChannel
1664
+ };
1665
+
1666
+ //Read only properties
1667
+ Object.defineProperty(this, 'label', { enumerable: true, configurable: false, get: function get() {
1668
+ return priv.dataChannel.label;
1669
+ } });
1670
+ Object.defineProperty(this, 'ordered', { enumerable: true, configurable: false, get: function get() {
1671
+ return priv.dataChannel.ordered;
1672
+ } });
1673
+ Object.defineProperty(this, 'maxPacketLifeTime', { enumerable: true, configurable: false, get: function get() {
1674
+ return priv.dataChannel.maxPacketLifeTime;
1675
+ } });
1676
+ Object.defineProperty(this, 'protocol', { enumerable: true, configurable: false, get: function get() {
1677
+ return priv.dataChannel.protocol;
1678
+ } });
1679
+ Object.defineProperty(this, 'negotiated', { enumerable: true, configurable: false, get: function get() {
1680
+ return priv.dataChannel.negotiated;
1681
+ } });
1682
+ Object.defineProperty(this, 'id', { enumerable: true, configurable: false, get: function get() {
1683
+ return priv.dataChannel.id;
1684
+ } });
1685
+ Object.defineProperty(this, 'priority', { enumerable: true, configurable: false, get: function get() {
1686
+ return priv.dataChannel.priority;
1687
+ } });
1688
+ Object.defineProperty(this, 'readyState', { enumerable: true, configurable: false, get: function get() {
1689
+ return priv.dataChannel.readyState;
1690
+ } });
1691
+ Object.defineProperty(this, 'bufferedAmount', { enumerable: true, configurable: false, get: function get() {
1692
+ return priv.dataChannel.bufferedAmount;
1693
+ } });
1694
+ //Read & write
1695
+ Object.defineProperty(this, 'bufferedAmountLowThreshold', { enumerable: true, configurable: false,
1696
+ get: function get() {
1697
+ return priv.dataChannel.bufferedAmountLowThreshold;
1698
+ },
1699
+ set: function set(bufferedAmountLowThreshold) {
1700
+ return priv.dataChannel.bufferedAmountLowThreshold = bufferedAmountLowThreshold;
1701
+ }
1702
+ });
1703
+ Object.defineProperty(this, 'binaryType', { enumerable: true, configurable: false,
1704
+ get: function get() {
1705
+ return priv.dataChannel.bufferedAmount;
1706
+ },
1707
+ set: function set(binaryType) {
1708
+ if (binaryType !== 'blob' && binaryType !== 'arraybuffer') {
1709
+ throw new SyntaxError();
1710
+ }
1711
+
1712
+ return priv.binaryType = binaryType;
1713
+ }
1714
+ });
1715
+
1716
+ function createEvent(name) {
1717
+ var e = document.createEvent('Event');
1718
+
1719
+ e.initEvent(name, false, false);
1720
+
1721
+ return e;
1722
+ }
1723
+
1724
+ function fire(name) {
1725
+ self.dispatchEvent(createEvent(name));
1726
+ }
1727
+
1728
+ //Set event
1729
+ priv.dataChannel.onopen = function () {
1730
+ fire('open');
1731
+ };
1732
+ priv.dataChannel.onbufferedamountlow = function () {
1733
+ fire('bufferedamountlow');
1734
+ };
1735
+ priv.dataChannel.onerror = function () {
1736
+ fire('error');
1737
+ };
1738
+ priv.dataChannel.onclose = function () {
1739
+ fire('close');
1740
+ };
1741
+ priv.dataChannel.onmessage = function (message) {
1742
+ //Create event
1743
+ var event = createEvent('message');
1744
+
1745
+ //Check if message is binary
1746
+ if (typeof message !== 'string') {
1747
+ //Create uint array
1748
+ var array = new Uint8Array(message);
1749
+ //Check binary type
1750
+
1751
+ if (priv.binaryType === 'blob') {
1752
+ //Create blob builder
1753
+ var builder = new MSBlobBuilder();
1754
+ //Append message
1755
+
1756
+ builder.append(array);
1757
+ //Get blob
1758
+ event.data = builder.getBlob();
1759
+ } else if (priv.binaryType === 'arraybuffer') {
1760
+ //Get array buffer
1761
+ event.data = array.buffer;
1762
+ } else {
1763
+ return;
1764
+ }
1765
+ } else {
1766
+ //It is a string
1767
+ event.data = message;
1768
+ }
1769
+
1770
+ //Check if
1771
+ self.dispatchEvent(event);
1772
+ };
1773
+
1774
+ //Done
1775
+ return this;
1776
+ };
1777
+
1778
+ //Inherit from Event Target
1779
+ RTCDataChannel.prototype = Object.create(EventTarget.prototype, {
1780
+ constructor: {
1781
+ value: RTCDataChannel,
1782
+ configurable: true,
1783
+ writable: true
1784
+ }
1785
+ });
1786
+ RTCDataChannel.__proto__ = EventTarget;
1787
+
1788
+ // Define Event Handlers
1789
+ defineEventAttribute(RTCDataChannel.prototype, 'open');
1790
+ defineEventAttribute(RTCDataChannel.prototype, 'bufferedamountlow');
1791
+ defineEventAttribute(RTCDataChannel.prototype, 'error');
1792
+ defineEventAttribute(RTCDataChannel.prototype, 'close');
1793
+ defineEventAttribute(RTCDataChannel.prototype, 'message');
1794
+
1795
+ RTCDataChannel.prototype.send = function (data) {
1796
+ var self = this;
1797
+ //Check state
1798
+
1799
+ if (this.readyState !== 'open') {
1800
+ throw new InvalidStateError();
1801
+ }
1802
+
1803
+ try {
1804
+ //Check type
1805
+ if (data instanceof Blob) {
1806
+ var reader = new FileReader();
1807
+
1808
+ reader.onloadend = function () {
1809
+ //Create array from buffer
1810
+ var array = new Uint8Array(reader.result);
1811
+ //Send it
1812
+
1813
+ self.priv.dataChannel.send(array);
1814
+ };
1815
+ //Read data as array
1816
+ reader.readAsArrayBuffer(data);
1817
+ } else if (data instanceof ArrayBuffer) {
1818
+ //Send it
1819
+ this.priv.dataChannel.send(array);
1820
+ } else if (typeof data === 'string') {
1821
+ //Send it
1822
+ this.priv.dataChannel.send(data);
1823
+ } else {
1824
+ throw new TypeError();
1825
+ }
1826
+ } catch (e) {
1827
+ throw InvalidStateError();
1828
+ }
1829
+ };
1830
+
1831
+ RTCDataChannel.prototype.close = function () {
1832
+ this.priv.dataChannel.close();
1833
+ };
1834
+
1835
+ Object.defineProperty(RTCDataChannel, 'name', { enumerable: false, configurable: true, writable: false, value: 'RTCDataChannel' });
1836
+ Object.defineProperty(RTCDataChannel, 'prototype', { writable: false });
1837
+ module.exports = RTCDataChannel;
1838
+ }, { './EventTarget.js': 4, './InvalidStateError.js': 5 }], 10: [function (require, module, exports) {
1839
+ 'use strict';
1840
+
1841
+ var WebRTCProxy = require('./WebRTCProxy.js');
1842
+
1843
+ /*
1844
+ interface RTCIceCandidate {
1845
+ readonly attribute DOMString candidate;
1846
+ readonly attribute DOMString? sdpMid;
1847
+ readonly attribute unsigned short? sdpMLineIndex;
1848
+ readonly attribute DOMString? foundation;
1849
+ readonly attribute RTCIceComponent? component;
1850
+ readonly attribute unsigned long? priority;
1851
+ readonly attribute DOMString? ip;
1852
+ readonly attribute RTCIceProtocol? protocol;
1853
+ readonly attribute unsigned short? port;
1854
+ readonly attribute RTCIceCandidateType? type;
1855
+ readonly attribute RTCIceTcpCandidateType? tcpType;
1856
+ readonly attribute DOMString? relatedAddress;
1857
+ readonly attribute unsigned short? relatedPort;
1858
+ readonly attribute DOMString? usernameFragment;
1859
+ RTCIceCandidateInit toJSON();
1860
+ };
1861
+ */
1862
+ var RTCIceCandidate = function RTCIceCandidate(iceCandidateInit) {
1863
+ if (!iceCandidateInit) {
1864
+ throw new TypeError();
1865
+ }
1866
+
1867
+ //Get values from dictionary
1868
+ var candidate = iceCandidateInit.candidate;
1869
+ var sdpMid = iceCandidateInit.sdpMid;
1870
+ var sdpMLineIndex = iceCandidateInit.sdpMLineIndex;
1871
+ var usernameFragment = iceCandidateInit.usernameFragment;
1872
+ //Not set yet
1873
+ var foundation;
1874
+ var component;
1875
+ var priority;
1876
+ var ip;
1877
+ var protocol;
1878
+ var port;
1879
+ var type;
1880
+ var tcpType;
1881
+ var relatedAddress;
1882
+ var relatedPort;
1883
+
1884
+ //Extended attributes to avoid parsing it twice
1885
+ if (iceCandidateInit.ext) {
1886
+ foundation = iceCandidateInit.ext.foundation;
1887
+ component = iceCandidateInit.ext.component;
1888
+ priority = iceCandidateInit.ext.priority;
1889
+ ip = iceCandidateInit.ext.ip;
1890
+ protocol = iceCandidateInit.ext.protocol;
1891
+ port = iceCandidateInit.ext.port;
1892
+ type = iceCandidateInit.ext.type;
1893
+ tcpType = iceCandidateInit.ext.tcpType;
1894
+ relatedAddress = iceCandidateInit.ext.relatedAddress;
1895
+ relatedPort = iceCandidateInit.ext.relatedPort;
1896
+ } else {
1897
+ try {
1898
+ //Parse candidate
1899
+ var parsed = WebRTCProxy.parseIceCandidate(candidate);
1900
+ } catch (e) {
1901
+ throw new TypeError();
1902
+ }
1903
+ //Set parsed properties
1904
+ foundation = parsed[0];
1905
+ component = parsed[1];
1906
+ priority = parsed[2];
1907
+ ip = parsed[3];
1908
+ protocol = parsed[4];
1909
+ port = parsed[5];
1910
+ type = parsed[6];
1911
+ tcpType = parsed[7];
1912
+ relatedAddress = parsed[8];
1913
+ relatedPort = parsed[9];
1914
+ if (!usernameFragment) {
1915
+ usernameFragment = parsed[10];
1916
+ }
1917
+ }
1918
+
1919
+ //Direct attributes from init
1920
+ Object.defineProperty(this, 'candidate', { enumerable: true, configurable: false, get: function get() {
1921
+ return candidate;
1922
+ } });
1923
+ Object.defineProperty(this, 'sdpMid', { enumerable: true, configurable: false, get: function get() {
1924
+ return sdpMid;
1925
+ } });
1926
+ Object.defineProperty(this, 'sdpMLineIndex', { enumerable: true, configurable: false, get: function get() {
1927
+ return sdpMLineIndex;
1928
+ } });
1929
+ Object.defineProperty(this, 'foundation', { enumerable: true, configurable: false, get: function get() {
1930
+ return foundation;
1931
+ } });
1932
+ Object.defineProperty(this, 'component', { enumerable: true, configurable: false, get: function get() {
1933
+ return component;
1934
+ } });
1935
+ Object.defineProperty(this, 'priority', { enumerable: true, configurable: false, get: function get() {
1936
+ return priority;
1937
+ } });
1938
+ Object.defineProperty(this, 'ip', { enumerable: true, configurable: false, get: function get() {
1939
+ return ip;
1940
+ } });
1941
+ Object.defineProperty(this, 'protocol', { enumerable: true, configurable: false, get: function get() {
1942
+ return protocol;
1943
+ } });
1944
+ Object.defineProperty(this, 'port', { enumerable: true, configurable: false, get: function get() {
1945
+ return port;
1946
+ } });
1947
+ Object.defineProperty(this, 'type', { enumerable: true, configurable: false, get: function get() {
1948
+ return type;
1949
+ } });
1950
+ Object.defineProperty(this, 'tcpType', { enumerable: true, configurable: false, get: function get() {
1951
+ return tcpType;
1952
+ } });
1953
+ Object.defineProperty(this, 'relatedAddress', { enumerable: true, configurable: false, get: function get() {
1954
+ return relatedAddress;
1955
+ } });
1956
+ Object.defineProperty(this, 'relatedPort', { enumerable: true, configurable: false, get: function get() {
1957
+ return relatedPort;
1958
+ } });
1959
+ Object.defineProperty(this, 'usernameFragment', { enumerable: true, configurable: false, get: function get() {
1960
+ return usernameFragment;
1961
+ } });
1962
+
1963
+ return this;
1964
+ };
1965
+
1966
+ RTCIceCandidate.prototype.toJSON = function () {
1967
+ return {
1968
+ candidate: this.candidate,
1969
+ sdpMid: this.sdpMid,
1970
+ sdpMLineIndex: this.sdpMLineIndex,
1971
+ usernameFragment: this.usernameFragment
1972
+ };
1973
+ };
1974
+
1975
+ Object.defineProperty(RTCIceCandidate, 'name', { enumerable: false, configurable: true, writable: false, value: 'RTCIceCandidate' });
1976
+ Object.defineProperty(RTCIceCandidate, 'prototype', { writable: false });
1977
+ module.exports = RTCIceCandidate;
1978
+ }, { './WebRTCProxy.js': 17 }], 11: [function (require, module, exports) {
1979
+ 'use strict';
1980
+
1981
+ var _extends = Object.assign || function (target) {
1982
+ for (var i = 1; i < arguments.length; i++) {
1983
+ var source = arguments[i];
1984
+
1985
+ for (var key in source) {
1986
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1987
+ target[key] = source[key];
1988
+ }
1989
+ }
1990
+ }
1991
+
1992
+ return target;
1993
+ };
1994
+
1995
+ var WebRTCProxy = require('./WebRTCProxy.js');
1996
+ var MediaStreamTrack = require('./MediaStreamTrack.js');
1997
+ var RTCSessionDescription = require('./RTCSessionDescription.js');
1998
+ var RTCIceCandidate = require('./RTCIceCandidate.js');
1999
+ var RTCRtpSender = require('./RTCRtpSender.js');
2000
+ var RTCRtpReceiver = require('./RTCRtpReceiver.js');
2001
+ var RTCRtpTransceiver = require('./RTCRtpTransceiver.js');
2002
+ var DataChannel = require('./RTCDataChannel.js');
2003
+ var InvalidStateError = require('./InvalidStateError.js');
2004
+ var EventTarget = require('./EventTarget.js').EventTarget;
2005
+ var defineEventAttribute = require('./EventTarget.js').defineEventAttribute;
2006
+
2007
+ /*
2008
+ [Constructor(optional RTCConfiguration configuration),Exposed=Window]
2009
+ interface RTCPeerConnection : EventTarget {
2010
+ Promise<RTCSessionDescriptionInit> createOffer(optional RTCOfferOptions options);
2011
+ Promise<RTCSessionDescriptionInit> createAnswer(optional RTCAnswerOptions options);
2012
+ Promise<void> setLocalDescription(RTCSessionDescriptionInit description);
2013
+ readonly attribute RTCSessionDescription? localDescription;
2014
+ readonly attribute RTCSessionDescription? currentLocalDescription;
2015
+ readonly attribute RTCSessionDescription? pendingLocalDescription;
2016
+ Promise<void> setRemoteDescription(RTCSessionDescriptionInit description);
2017
+ readonly attribute RTCSessionDescription? remoteDescription;
2018
+ readonly attribute RTCSessionDescription? currentRemoteDescription;
2019
+ readonly attribute RTCSessionDescription? pendingRemoteDescription;
2020
+ Promise<void> addIceCandidate((RTCIceCandidateInit or RTCIceCandidate) candidate);
2021
+ readonly attribute RTCSignalingState signalingState;
2022
+ readonly attribute RTCIceGatheringState iceGatheringState;
2023
+ readonly attribute RTCIceConnectionState iceConnectionState;
2024
+ readonly attribute RTCPeerConnectionState connectionState;
2025
+ readonly attribute boolean? canTrickleIceCandidates;
2026
+ static sequence<RTCIceServer> getDefaultIceServers();
2027
+ RTCConfiguration getConfiguration();
2028
+ void setConfiguration(RTCConfiguration configuration);
2029
+ void close();
2030
+ attribute EventHandler onnegotiationneeded;
2031
+ attribute EventHandler onicecandidate;
2032
+ attribute EventHandler onicecandidateerror;
2033
+ attribute EventHandler onsignalingstatechange;
2034
+ attribute EventHandler oniceconnectionstatechange;
2035
+ attribute EventHandler onicegatheringstatechange;
2036
+ attribute EventHandler onconnectionstatechange;
2037
+ };
2038
+ */
2039
+
2040
+ var RTCIceTransportPolicy = ['relay', 'all'];
2041
+ var RTCBundlePolicy = ['balanced', 'max-compat', 'max-bundle'];
2042
+ var RTCRtcpMuxPolicy = ['negotiate', 'require'];
2043
+ var RTCIceCredentialType = ['password', 'oauth'];
2044
+
2045
+ //Check if a value is valid in an enum
2046
+ function check(value, valid) {
2047
+ for (var i = 0; i < valid.length; ++i) {
2048
+ if (valid[i] === value) {
2049
+ return;
2050
+ }
2051
+ }throw new TypeError(value + ' not in ' + JSON.stringify(valid));
2052
+ }
2053
+
2054
+ function checkRange(value, min, max) {
2055
+ if (value < min || value > max) {
2056
+ throw new TypeError(value + ' not in [' + min + ',' + max + ']');
2057
+ }
2058
+ }
2059
+
2060
+ function checkNotNull(value) {
2061
+ if (value === null) {
2062
+ throw new TypeError('Null not allowed');
2063
+ }
2064
+ }
2065
+
2066
+ function checkArray(value) {
2067
+ if (!Array.isArray(value)) {
2068
+ throw new TypeError('Must be an array');
2069
+ }
2070
+ }
2071
+
2072
+ function createRTCConfiguration(configuration) {
2073
+
2074
+ /*
2075
+ *
2076
+ dictionary RTCConfiguration {
2077
+ sequence<RTCIceServer> iceServers;
2078
+ RTCIceTransportPolicy iceTransportPolicy = "all";
2079
+ RTCBundlePolicy bundlePolicy = "balanced";
2080
+ RTCRtcpMuxPolicy rtcpMuxPolicy = "require";
2081
+ DOMString peerIdentity;
2082
+ sequence<RTCCertificate> certificates;
2083
+ [EnforceRange]
2084
+ octet iceCandidatePoolSize = 0;
2085
+ };
2086
+ */
2087
+ //Set configuration with default values
2088
+ var sanitized = _extends({
2089
+ iceServers: undefined,
2090
+ iceTransportPolicy: 'all',
2091
+ bundlePolicy: 'balanced',
2092
+ rtcpMuxPolicy: 'require',
2093
+ iceCandidatePoolSize: 0,
2094
+ certificates: undefined
2095
+ },
2096
+ //Remove undefined objects
2097
+ configuration ? JSON.parse(JSON.stringify(configuration)) : {});
2098
+ //Check valid values
2099
+
2100
+ checkNotNull(sanitized.iceServers);
2101
+
2102
+ //Check array
2103
+ if (Array.isArray(sanitized.iceServers)) {
2104
+ //Check each one
2105
+ for (var i = 0; i < sanitized.iceServers.length; ++i) {
2106
+
2107
+ /*
2108
+ *
2109
+ dictionary RTCIceServer {
2110
+ required (DOMString or sequence<DOMString>) urls;
2111
+ DOMString username;
2112
+ (DOMString or RTCOAuthCredential) credential;
2113
+ RTCIceCredentialType credentialType = "password";
2114
+ };
2115
+ */
2116
+ //Set defautls
2117
+ var iceServer = sanitized.iceServers[i] = _extends({
2118
+ credentialType: 'password'
2119
+ }, sanitized.iceServers[i]);
2120
+ //Check it is not null
2121
+
2122
+ checkNotNull(iceServer.urls);
2123
+ //If it is a sring fallback
2124
+ if (typeof iceServer.urls === 'string')
2125
+ //Arraify
2126
+ {
2127
+ iceServer.urls = [iceServer.urls];
2128
+ }
2129
+ checkArray(iceServer.urls);
2130
+ }
2131
+ }
2132
+ //Check the others
2133
+ check(sanitized.iceTransportPolicy, RTCIceTransportPolicy);
2134
+ check(sanitized.bundlePolicy, RTCBundlePolicy);
2135
+ check(sanitized.rtcpMuxPolicy, RTCRtcpMuxPolicy);
2136
+ checkRange(sanitized.iceCandidatePoolSize, 0, 255);
2137
+ //Done
2138
+ return sanitized;
2139
+ }
2140
+
2141
+ var RTCPeerConnection = function RTCPeerConnection() {
2142
+ var self = this;
2143
+ //Init event targetr
2144
+
2145
+ EventTarget.call(this);
2146
+
2147
+ //Create private args
2148
+ var priv = this.priv = {};
2149
+
2150
+ //Set configuration with default values
2151
+ priv.configuration = createRTCConfiguration(arguments.length ? JSON.parse(JSON.stringify(arguments[0])) : {});
2152
+
2153
+ //Other internal data
2154
+ priv.senders = {};
2155
+ priv.remoteStreams = {};
2156
+ priv.lastOffer = null;
2157
+ priv.lastAnswer = null;
2158
+ priv.isClosed = false;
2159
+
2160
+ var signalingState = 'stable';
2161
+ var iceGatheringState = 'new';
2162
+ var iceConnectionState = 'new';
2163
+ var connectionState = 'new';
2164
+
2165
+ //TODO: Implement this
2166
+ var canTrickleIceCandidates = null;
2167
+
2168
+ function toSessionDescription(sdp) {
2169
+ return typeof sdp === 'unknown' ? new RTCSessionDescription(sdp.toArray()) : null;
2170
+ }
2171
+
2172
+ //Define read only properties for each attribute
2173
+ //The localDescription attribute must return pendingLocalDescription if it is not null and otherwise it must return currentLocalDescription .
2174
+ Object.defineProperty(this, 'localDescription', { enumerable: true, configurable: false, get: function get() {
2175
+ return toSessionDescription(priv.pc.localDescription);
2176
+ } });
2177
+ Object.defineProperty(this, 'currentLocalDescription', { enumerable: true, configurable: false, get: function get() {
2178
+ return toSessionDescription(priv.pc.currentLocalDescription);
2179
+ } });
2180
+ Object.defineProperty(this, 'pendingLocalDescription', { enumerable: true, configurable: false, get: function get() {
2181
+ return toSessionDescription(priv.pc.pendingLocalDescription);
2182
+ } });
2183
+
2184
+ Object.defineProperty(this, 'remoteDescription', { enumerable: true, configurable: false, get: function get() {
2185
+ return toSessionDescription(priv.pc.remoteDescription);
2186
+ } });
2187
+ Object.defineProperty(this, 'currentRemoteDescription', { enumerable: true, configurable: false, get: function get() {
2188
+ return toSessionDescription(priv.pc.currentRemoteDescription);
2189
+ } });
2190
+ Object.defineProperty(this, 'pendingRemoteDescription', { enumerable: true, configurable: false, get: function get() {
2191
+ return toSessionDescription(priv.pc.pendingRemoteDescription);
2192
+ } });
2193
+
2194
+ Object.defineProperty(this, 'signalingState', { enumerable: true, configurable: false, get: function get() {
2195
+ return signalingState;
2196
+ } });
2197
+ Object.defineProperty(this, 'iceGatheringState', { enumerable: true, configurable: false, get: function get() {
2198
+ return iceGatheringState;
2199
+ } });
2200
+ Object.defineProperty(this, 'iceConnectionState', { enumerable: true, configurable: false, get: function get() {
2201
+ return iceConnectionState;
2202
+ } });
2203
+ Object.defineProperty(this, 'connectionState', { enumerable: true, configurable: false, get: function get() {
2204
+ return connectionState;
2205
+ } });
2206
+
2207
+ Object.defineProperty(this, 'canTrickleIceCandidates', { enumerable: true, configurable: false, get: function get() {
2208
+ return canTrickleIceCandidates;
2209
+ } });
2210
+
2211
+ function createEvent(name) {
2212
+ var e = document.createEvent('Event');
2213
+
2214
+ e.initEvent(name, false, false);
2215
+
2216
+ return e;
2217
+ }
2218
+ function fire(name) {
2219
+ self.dispatchEvent(createEvent(name));
2220
+ }
2221
+
2222
+ // Create new native pc
2223
+ priv.pc = WebRTCProxy.createPeerConnection(priv.configuration);
2224
+
2225
+ //Event handlers
2226
+ priv.pc.onnegotiationneeded = function () {
2227
+ fire('negotiationneeded');
2228
+ };
2229
+ priv.pc.onicecandidate = function (candidate, sdpMid, sdpMLineIndex, foundation, component, priority, ip, protocol, port, type, tcpType, relatedAddress, relatedPort, usernameFragment, url) {
2230
+ var e = createEvent('icecandidate');
2231
+
2232
+ if (candidate) {
2233
+ e.candidate = new RTCIceCandidate({
2234
+ candidate: candidate,
2235
+ sdpMid: sdpMid,
2236
+ sdpMLineIndex: sdpMLineIndex,
2237
+ ext: {
2238
+ foundation: foundation,
2239
+ component: component,
2240
+ priority: priority,
2241
+ ip: ip,
2242
+ protocol: protocol,
2243
+ port: port,
2244
+ type: type,
2245
+ tcpType: tcpType,
2246
+ relatedAddress: relatedAddress,
2247
+ relatedPort: relatedPort
2248
+ },
2249
+ usernameFragment: usernameFragment
2250
+ });
2251
+ } else {
2252
+ e.candidate = null;
2253
+ }
2254
+ e.url = url;
2255
+ self.dispatchEvent(e);
2256
+ };
2257
+ priv.pc.onicecandidateerror = function () {
2258
+ fire('icecandidateerror');
2259
+ };
2260
+ priv.pc.onsignalingstatechange = function (state) {
2261
+ signalingState = state;
2262
+ fire('signalingstatechange');
2263
+ if (state === 'closed') {
2264
+ priv.isClosed = true;
2265
+ delete priv.pc;
2266
+ }
2267
+ };
2268
+ priv.pc.oniceconnectionstatechange = function (state) {
2269
+ iceConnectionState = state;
2270
+ fire('iceconnectionstatechange');
2271
+ };
2272
+ priv.pc.onicegatheringstatechange = function (state) {
2273
+ iceGatheringState = state;
2274
+ fire('icegatheringstatechange');
2275
+ };
2276
+ priv.pc.onconnectionstatechange = function (state) {
2277
+ connectionState = state;
2278
+ fire('connectionState');
2279
+ };
2280
+ priv.pc.onaddstream = function (label) {
2281
+ //Create new stream
2282
+ var stream = new MediaStream(null, label);
2283
+
2284
+ //Get remote stream tracks
2285
+ priv.pc.getRemoteStreamTracks(label, function () {
2286
+ //Parse arguments
2287
+ var tracks = Array.prototype.slice.call(arguments, 0);
2288
+
2289
+ //For each track
2290
+ for (var i = 0; i < tracks.length; ++i) {
2291
+ //Create a wrapper
2292
+ stream.addTrack(new MediaStreamTrack(tracks[i]));
2293
+ } //Get all tracks
2294
+ var mediaStreamTracks = stream.getTracks();
2295
+
2296
+ //For each track in stream
2297
+ for (var i = 0; i < mediaStreamTracks.length; ++i) {
2298
+ //Create evnet
2299
+ var event = createEvent('track');
2300
+ //Add data
2301
+
2302
+ event.track = mediaStreamTracks[i];
2303
+ event.receiver = { track: mediaStreamTracks[i] };
2304
+ event.transceiver = { receiver: event.receiver };
2305
+ event.streams = [stream];
2306
+ //Fire it
2307
+ self.dispatchEvent(event);
2308
+ }
2309
+ });
2310
+ };
2311
+
2312
+ priv.pc.onremovestream = function (label) {
2313
+ //Delete from remote stream list
2314
+ delete priv.remotes[label];
2315
+ };
2316
+
2317
+ priv.pc.ondatachannel = function (dataChannel) {
2318
+ //Create event
2319
+ var event = createEvent('datachannel');
2320
+ //Create datachannel
2321
+
2322
+ event.channel = new DataChannel(dataChannel);
2323
+ //Fire event
2324
+ self.dispatchEvent(event);
2325
+ };
2326
+ };
2327
+
2328
+ //Inherit from Event Target
2329
+ RTCPeerConnection.prototype = Object.create(EventTarget.prototype, {
2330
+ constructor: {
2331
+ value: RTCPeerConnection,
2332
+ configurable: true,
2333
+ writable: true
2334
+ }
2335
+ });
2336
+ RTCPeerConnection.__proto__ = EventTarget;
2337
+
2338
+ // Define Event Handlers
2339
+ defineEventAttribute(RTCPeerConnection.prototype, 'negotiationneeded');
2340
+ defineEventAttribute(RTCPeerConnection.prototype, 'icecandidate');
2341
+ defineEventAttribute(RTCPeerConnection.prototype, 'icecandidateerror');
2342
+ defineEventAttribute(RTCPeerConnection.prototype, 'signalingstatechange');
2343
+ defineEventAttribute(RTCPeerConnection.prototype, 'iceconnectionstatechange');
2344
+ defineEventAttribute(RTCPeerConnection.prototype, 'icegatheringstatechange');
2345
+ defineEventAttribute(RTCPeerConnection.prototype, 'connectionstatechange');
2346
+ defineEventAttribute(RTCPeerConnection.prototype, 'addtrack');
2347
+
2348
+ RTCPeerConnection.prototype.getConfiguration = function () {
2349
+ return this.priv.configuration;
2350
+ };
2351
+
2352
+ RTCPeerConnection.prototype.setConfiguration = function (configuration) {
2353
+ var priv = this.priv;
2354
+
2355
+ if (!priv.pc || priv.isClosed) {
2356
+ throw new InvalidStateError();
2357
+ }
2358
+
2359
+ //Get configuration object from input
2360
+ var sanitized = createRTCConfiguration(configuration);
2361
+
2362
+ try {
2363
+ //Try to set it
2364
+ priv.pc.setConfiguration(sanitized);
2365
+ } catch (error) {
2366
+ //Launch InvalidModificationError
2367
+ var operationError = new Error(error);
2368
+
2369
+ operationError.name = 'InvalidModificationError';
2370
+ operationError.code = 13;
2371
+ throw operationError;
2372
+ }
2373
+ //Store new configuration
2374
+ priv.configuration = sanitized;
2375
+ };
2376
+
2377
+ RTCPeerConnection.getDefaultIceServers = function () {
2378
+ return [];
2379
+ };
2380
+
2381
+ RTCPeerConnection.prototype.createOffer = function (options) {
2382
+ var priv = this.priv;
2383
+
2384
+ return new Promise(function (resolve, reject) {
2385
+ if (!priv.pc || priv.isClosed) {
2386
+ throw new InvalidStateError();
2387
+ }
2388
+ priv.pc.createOffer(function (type, sdp) {
2389
+ priv.lastOffer = sdp;
2390
+ resolve({
2391
+ type: type,
2392
+ sdp: sdp
2393
+ });
2394
+ }, function () {
2395
+ reject(new InvalidStateError());
2396
+ }, options);
2397
+ });
2398
+ };
2399
+
2400
+ RTCPeerConnection.prototype.createAnswer = function (options) {
2401
+ var self = this;
2402
+ var priv = this.priv;
2403
+
2404
+ return new Promise(function (resolve, reject) {
2405
+ if (!priv.pc || priv.isClosed) {
2406
+ throw new InvalidStateError();
2407
+ }
2408
+ if (self.remoteDescription === null) {
2409
+ throw new InvalidStateError();
2410
+ }
2411
+ priv.pc.createAnswer(function (type, sdp) {
2412
+ priv.lastAnswer = sdp;
2413
+ resolve({
2414
+ type: type,
2415
+ sdp: sdp
2416
+ });
2417
+ }, function () {
2418
+ reject(new InvalidStateError());
2419
+ }, options);
2420
+ });
2421
+ };
2422
+
2423
+ RTCPeerConnection.prototype.setLocalDescription = function (description) {
2424
+ var priv = this.priv;
2425
+
2426
+ //If description.sdp is the empty string and description.type is "answer" or "pranswer", set description.sdp to lastAnswer.
2427
+ if (!description.sdp && (description.type === 'answer' || description.type === 'pranser')) {
2428
+ description.sdp = priv.lastAnswer;
2429
+ }
2430
+
2431
+ //If description.sdp is the empty string and description.type is "offer", set description.sdp to lastOffer.
2432
+ if (!description.sdp && description.type === 'offer') {
2433
+ description.sdp = priv.lastOffer;
2434
+ }
2435
+
2436
+ return new Promise(function (resolve, reject) {
2437
+ if (!priv.pc || priv.isClosed) {
2438
+ throw new InvalidStateError();
2439
+ }
2440
+ priv.pc.setLocalDescription(resolve, function () {
2441
+ reject(new InvalidStateError());
2442
+ }, description);
2443
+ });
2444
+ };
2445
+
2446
+ RTCPeerConnection.prototype.setRemoteDescription = function (description) {
2447
+ var priv = this.priv;
2448
+
2449
+ return new Promise(function (resolve, reject) {
2450
+ if (!priv.pc || priv.isClosed) {
2451
+ throw new InvalidStateError();
2452
+ }
2453
+ priv.pc.setRemoteDescription(resolve, function () {
2454
+ reject(new InvalidStateError());
2455
+ }, description);
2456
+ });
2457
+ };
2458
+
2459
+ RTCPeerConnection.prototype.addIceCandidate = function (candidate) {
2460
+ var self = this;
2461
+ var priv = this.priv;
2462
+ //1. Let candidate be the method's argument.
2463
+ //2. Let connection be the ``[`RTCPeerConnection`](#dom-rtcpeerconnection)`` object on which the method was invoked.
2464
+ //3. If both sdpMid and sdpMLineIndex are `null`, return a promise [rejected](#dfn-rejected) with a newly [created](https://www.w3.org/TR/2016/REC-WebIDL-1-20161215/#dfn-create-exception) `TypeError`.
2465
+
2466
+ if (!candidate || typeof candidate.sdpMid !== 'string' && typeof candidate.sdpMLineIndex !== 'number') {
2467
+ return Promise.reject(new TypeError());
2468
+ }
2469
+
2470
+ //4. Return the result of [enqueuing](#enqueue-an-operation) the following steps to connection's operation queue:
2471
+ return new Promise(function (resolve, reject) {
2472
+ //1. If ``[`remoteDescription`](#dom-rtcpeerconnection-remotedescription)`` is `null` return a promise [rejected](#dfn-rejected) with a newly [created](https://www.w3.org/TR/2016/REC-WebIDL-1-20161215/#dfn-create-exception) `InvalidStateError`.
2473
+ if (self.remoteDescription === null) {
2474
+ throw new InvalidStateError();
2475
+ }
2476
+
2477
+ /*
2478
+ 2. Let p be a new promise.
2479
+ 3. If candidate.sdpMid is not null, run the following steps:
2480
+ 1. If candidate.sdpMid is not equal to the mid of any media description in ``[`remoteDescription`](#dom-rtcpeerconnection-remotedescription)`` , [reject](#dfn-rejected) p with a newly [created](https://www.w3.org/TR/2016/REC-WebIDL-1-20161215/#dfn-create-exception) `OperationError` and abort these steps.
2481
+ 4. Else, if candidate.sdpMLineIndex is not null, run the following steps:
2482
+ 1. If candidate.sdpMLineIndex is equal to or larger than the number of media descriptions in ``[`remoteDescription`](#dom-rtcpeerconnection-remotedescription)`` , [reject](#dfn-rejected) p with a newly [created](https://www.w3.org/TR/2016/REC-WebIDL-1-20161215/#dfn-create-exception) `OperationError` and abort these steps.
2483
+ 5. If `candidate.usernameFragment` is neither `undefined` nor `null`, and is not equal to any username fragment present in the corresponding [media description](#dfn-media-description) of an applied remote description, [reject](#dfn-rejected) p with a newly [created](https://www.w3.org/TR/2016/REC-WebIDL-1-20161215/#dfn-create-exception) `OperationError` and abort these steps.
2484
+ 6. In parallel, add the ICE candidate candidate as described in \[[JSEP](#bib-JSEP)\] ([section 4.1.17.](https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-20#section-4.1.17)). Use `candidate.usernameFragment` to identify the ICE [generation](#dfn-generation); if `usernameFragment` is null, process the candidate for the most recent ICE [generation](#dfn-generation). If `candidate.candidate` is an empty string, process candidate as an end-of-candidates indication for the corresponding [media description](#dfn-media-description) and ICE candidate [generation](#dfn-generation).
2485
+ 1. If candidate could not be successfully added the user agent _MUST_ queue a task that runs the following steps:
2486
+ 1. If connection's [\[\[IsClosed\]\]](#dfn-x%5B%5Bisclosed%5D%5D) slot is `true`, then abort these steps.
2487
+ 2. [Reject](#dfn-rejected) p with a `DOMException` object whose `name` attribute has the value `OperationError` and abort these steps.
2488
+ 2. If candidate is applied successfully, the user agent _MUST_ queue a task that runs the following steps:
2489
+ 1. If connection's [\[\[IsClosed\]\]](#dfn-x%5B%5Bisclosed%5D%5D) slot is `true`, then abort these steps.
2490
+ 2. If ``connection.[`pendingRemoteDescription`](#dom-rtcpeerconnection-pendingremotedescription)`` is non-null, and represents the ICE [generation](#dfn-generation) for which candidate was processed, add candidate to ``connection.[`pendingRemoteDescription`](#dom-rtcpeerconnection-pendingremotedescription)`` .
2491
+ 3. If ``connection.[`currentRemoteDescription`](#dom-rtcpeerconnection-currentremotedescription)`` is non-null, and represents the ICE [generation](#dfn-generation) for which candidate was processed, add candidate to ``connection.[`currentRemoteDescription`](#dom-rtcpeerconnection-currentremotedescription)`` .
2492
+ 4. [Resolve](#dfn-resolved) p with `undefined`.
2493
+ 7. Return p.
2494
+ */
2495
+ try {
2496
+ //Add ICE candidate nativelly
2497
+ priv.pc.addIceCandidate(resolve, function () {
2498
+ reject(new InvalidStateError());
2499
+ }, candidate);
2500
+ } catch (error) {
2501
+ //Launch operation error
2502
+ var operationError = new Error(error);
2503
+
2504
+ operationError.name = 'OperationError';
2505
+ operationError.code = 0;
2506
+ throw operationError;
2507
+ }
2508
+ });
2509
+ };
2510
+
2511
+ RTCPeerConnection.prototype.close = function () {
2512
+
2513
+ var priv = this.priv;
2514
+
2515
+ if (!priv.pc || priv.isClosed) {
2516
+ throw new InvalidStateError();
2517
+ }
2518
+ //Close it
2519
+ priv.pc.close();
2520
+ //We are closed now, we can wait until callback
2521
+ priv.isClosed = true;
2522
+ };
2523
+
2524
+ /*
2525
+ partial interface RTCPeerConnection {
2526
+ sequence<RTCRtpSender> getSenders();
2527
+ sequence<RTCRtpReceiver> getReceivers();
2528
+ sequence<RTCRtpTransceiver> getTransceivers();
2529
+ RTCRtpSender addTrack(MediaStreamTrack track, MediaStream... streams);
2530
+ void removeTrack(RTCRtpSender sender);
2531
+ RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind, optional RTCRtpTransceiverInit init);
2532
+ attribute EventHandler ontrack;
2533
+ };
2534
+ */
2535
+ RTCPeerConnection.prototype.getSenders = function () {
2536
+ throw 'Not implemented';
2537
+ };
2538
+
2539
+ RTCPeerConnection.prototype.getReceivers = function () {
2540
+ throw 'Not implemented';
2541
+ };
2542
+
2543
+ RTCPeerConnection.prototype.getTransceivers = function () {
2544
+ throw 'Not implemented';
2545
+ };
2546
+
2547
+ RTCPeerConnection.prototype.addTrack = function () {
2548
+ var priv = this.priv;
2549
+
2550
+ if (!priv.pc || priv.isClosed) {
2551
+ throw new InvalidStateError();
2552
+ }
2553
+
2554
+ //Parse arguments
2555
+ var track = arguments[0];
2556
+ var streams = Array.prototype.slice.call(arguments, 1);
2557
+
2558
+ //Ensure that we are attaching to at most 1, as it is not supported in libwebrtc
2559
+ if (streams.length > 1) {
2560
+ throw new Error('Adding track to more than one stream is not currently supported');
2561
+ }
2562
+
2563
+ //Get stream label, as it is the only param needed by libwebrtc
2564
+ var label = streams.length ? streams[0].id : '';
2565
+
2566
+ //Add native track to native object it only needs the stream label not the stream
2567
+ var sender = priv.pc.addTrack(track.priv.track, label);
2568
+
2569
+ //Check result
2570
+ if (!sender) {
2571
+ return null;
2572
+ }
2573
+
2574
+ //Create sender
2575
+ var rtpSender = new RTCRtpSender(sender);
2576
+
2577
+ //Get native sender id
2578
+ var senderId = rtpSender.priv.id;
2579
+
2580
+ //Add to senders
2581
+ priv.senders[senderId] = rtpSender;
2582
+
2583
+ return rtpSender;
2584
+ };
2585
+
2586
+ RTCPeerConnection.prototype.addTransceiver = function (trackOrKind, init) {
2587
+ //TODO: Implement!
2588
+ //Not really implemented just for passing tests
2589
+ var sender = new RTCRtpSender(null, null);
2590
+ var track = new MediaStreamTrack(null);
2591
+ var receiver = new RTCRtpReceiver(track);
2592
+ //Return dummy object for now
2593
+
2594
+ return new RTCRtpTransceiver(sender, receiver);
2595
+ };
2596
+
2597
+ /*
2598
+ * Legacy stream apis
2599
+ */
2600
+ RTCPeerConnection.prototype.addStream = function (stream) {
2601
+ var tracks = stream.getTracks();
2602
+
2603
+ for (var i = 0; i < tracks.length; ++i) {
2604
+ this.addTrack(tracks[i], stream);
2605
+ }
2606
+ };
2607
+
2608
+ RTCPeerConnection.prototype.removeTrack = function (rtpSender) {
2609
+ var priv = this.priv;
2610
+
2611
+ if (!priv.pc || priv.isClosed) {
2612
+ throw new InvalidStateError();
2613
+ }
2614
+
2615
+ //Check if sender is invalid
2616
+ if (!rtpSender || !rtpSender.priv.sender || !rtpSender.priv.track) {
2617
+ throw new InvalidStateError();
2618
+ }
2619
+
2620
+ //Get native sender id
2621
+ var senderId = rtpSender.priv.id;
2622
+
2623
+ //Check if senders is from this pc
2624
+ if (!priv.senders.hasOwnProperty(senderId)) {
2625
+ throw new InvalidStateError();
2626
+ }
2627
+
2628
+ //Pass the nateive object
2629
+ priv.pc.removeTrack(rtpSender.priv.sender);
2630
+
2631
+ //Set sender track to null
2632
+ rtpSender.priv.track = null;
2633
+
2634
+ //Remove from senders
2635
+ delete priv.senders[senderId];
2636
+ };
2637
+
2638
+ defineEventAttribute(RTCPeerConnection.prototype, 'track');
2639
+
2640
+ /*
2641
+ partial interface RTCPeerConnection {
2642
+ readonly attribute RTCSctpTransport? sctp;
2643
+ RTCDataChannel createDataChannel(USVString label,
2644
+ optional RTCDataChannelInit dataChannelDict);
2645
+ attribute EventHandler ondatachannel;
2646
+ };
2647
+ */
2648
+ RTCPeerConnection.prototype.createDataChannel = function (label, dataChannelDict) {
2649
+ var priv = this.priv;
2650
+
2651
+ if (!priv.pc || priv.isClosed) {
2652
+ throw new InvalidStateError();
2653
+ }
2654
+
2655
+ //Check if we have a string label (can be empty)
2656
+ if (typeof label !== 'string') {
2657
+ return new TypeError();
2658
+ }
2659
+
2660
+ //Create native datachannel
2661
+ var dataChannel = priv.pc.createDataChannel(label, dataChannelDict);
2662
+
2663
+ //Check
2664
+ if (!dataChannel) {
2665
+ return null;
2666
+ }
2667
+
2668
+ //Return wrapper
2669
+ return new DataChannel(dataChannel);
2670
+ };
2671
+
2672
+ defineEventAttribute(RTCPeerConnection.prototype, 'datachannel');
2673
+
2674
+ Object.defineProperty(RTCPeerConnection, 'RTCPeerConnection', { enumerable: false, configurable: true, writable: false, value: 'RTCPeerConnection' });
2675
+ Object.defineProperty(RTCPeerConnection, 'prototype', { writable: false });
2676
+ module.exports = RTCPeerConnection;
2677
+ }, { './EventTarget.js': 4, './InvalidStateError.js': 5, './MediaStreamTrack.js': 8, './RTCDataChannel.js': 9, './RTCIceCandidate.js': 10, './RTCRtpReceiver.js': 12, './RTCRtpSender.js': 13, './RTCRtpTransceiver.js': 14, './RTCSessionDescription.js': 15, './WebRTCProxy.js': 17 }], 12: [function (require, module, exports) {
2678
+ 'use strict';
2679
+
2680
+ /*
2681
+ [Exposed=Window]
2682
+ interface RTCRtpReceiver {
2683
+ readonly attribute MediaStreamTrack track;
2684
+ readonly attribute RTCDtlsTransport? transport;
2685
+ readonly attribute RTCDtlsTransport? rtcpTransport;
2686
+ // Feature at risk
2687
+ static RTCRtpCapabilities getCapabilities(DOMString kind);
2688
+ RTCRtpParameters getParameters();
2689
+ sequence<RTCRtpContributingSource> getContributingSources();
2690
+ sequence<RTCRtpSynchronizationSource> getSynchronizationSources();
2691
+ Promise<RTCStatsReport> getStats();
2692
+ };
2693
+ */
2694
+
2695
+ var RTCRtpReceiver = function RTCRtpReceiver(track) {
2696
+ var priv = {
2697
+ track: track
2698
+ };
2699
+
2700
+ //Read only
2701
+ Object.defineProperty(this, 'track', {
2702
+ enumerable: true, configurable: false, get: function get() {
2703
+ return priv.track;
2704
+ }
2705
+ });
2706
+ //Not implemented
2707
+ Object.defineProperty(this, 'transport', {
2708
+ enumerable: true, configurable: false, get: function get() {
2709
+ return null;
2710
+ }
2711
+ });
2712
+ Object.defineProperty(this, 'rtcpTransport', {
2713
+ enumerable: true, configurable: false, get: function get() {
2714
+ return null;
2715
+ }
2716
+ });
2717
+ };
2718
+
2719
+ RTCRtpReceiver.getCapabilities = function (kind) {
2720
+ throw 'Not implemented yet';
2721
+ };
2722
+
2723
+ RTCRtpReceiver.getParameters = function () {
2724
+ throw 'Not implemented yet';
2725
+ };
2726
+
2727
+ RTCRtpReceiver.getContributingSources = function () {
2728
+ throw 'Not implemented yet';
2729
+ };
2730
+ RTCRtpReceiver.getSynchronizationSources = function () {
2731
+ throw 'Not implemented yet';
2732
+ };
2733
+ RTCRtpReceiver.getStats = function () {
2734
+ return Promise.reject(new Error('Not implemented yet'));
2735
+ };
2736
+
2737
+ Object.defineProperty(RTCRtpReceiver, 'name', {
2738
+ enumerable: false,
2739
+ configurable: true,
2740
+ writable: false,
2741
+ value: 'RTCRtpReceiver'
2742
+ });
2743
+ Object.defineProperty(RTCRtpReceiver, 'prototype', { writable: false });
2744
+ module.exports = RTCRtpReceiver;
2745
+ }, {}], 13: [function (require, module, exports) {
2746
+ 'use strict';
2747
+
2748
+ /*
2749
+ [Exposed=Window]
2750
+ interface RTCRtpSender {
2751
+ readonly attribute MediaStreamTrack? track;
2752
+ readonly attribute RTCDtlsTransport? transport;
2753
+ readonly attribute RTCDtlsTransport? rtcpTransport;
2754
+ // Feature at risk
2755
+ static RTCRtpCapabilities getCapabilities(DOMString kind);
2756
+ Promise<void> setParameters(optional RTCRtpParameters parameters);
2757
+ RTCRtpParameters getParameters();
2758
+ Promise<void> replaceTrack(MediaStreamTrack? withTrack);
2759
+ Promise<RTCStatsReport> getStats();
2760
+ };
2761
+ */
2762
+
2763
+ var RTCRtpSender = function RTCRtpSender(sender, track) {
2764
+ //Add to map
2765
+ this.priv = {
2766
+ sender: sender,
2767
+ track: track
2768
+ };
2769
+
2770
+ Object.defineProperty(this, 'track', { enumerable: true, configurable: false, get: function get() {
2771
+ return priv.track;
2772
+ } });
2773
+ Object.defineProperty(this, 'transport', { enumerable: true, configurable: false, get: function get() {
2774
+ new Error('Not supported yet');
2775
+ } });
2776
+ Object.defineProperty(this, 'rtcpTransport', { enumerable: true, configurable: false, get: function get() {
2777
+ new Error('Not supported yet');
2778
+ } });
2779
+
2780
+ return this;
2781
+ };
2782
+
2783
+ RTCRtpSender.prototype.getCapabilities = function () {
2784
+ throw new Error('Not supported yet');
2785
+ };
2786
+
2787
+ RTCRtpSender.prototype.setParameters = function () {
2788
+ throw new Error('Not supported yet');
2789
+ };
2790
+
2791
+ RTCRtpSender.prototype.getParameters = function () {
2792
+ throw new Error('Not supported yet');
2793
+ };
2794
+
2795
+ RTCRtpSender.prototype.replaceTrack = function () {
2796
+ throw new Error('Not supported yet');
2797
+ };
2798
+
2799
+ RTCRtpSender.prototype.getStats = function () {
2800
+ throw new Error('Not supported yet');
2801
+ };
2802
+
2803
+ Object.defineProperty(RTCRtpSender, 'name', { enumerable: false, configurable: true, writable: false, value: 'RTCRtpSender' });
2804
+ Object.defineProperty(RTCRtpSender, 'prototype', { writable: false });
2805
+ module.exports = RTCRtpSender;
2806
+ }, {}], 14: [function (require, module, exports) {
2807
+ 'use strict';
2808
+
2809
+ /*
2810
+ [Exposed=Window]
2811
+ interface RTCRtpTransceiver {
2812
+ readonly attribute DOMString? mid;
2813
+ [SameObject]
2814
+ readonly attribute RTCRtpSender sender;
2815
+ [SameObject]
2816
+ readonly attribute RTCRtpReceiver receiver;
2817
+ readonly attribute boolean stopped;
2818
+ attribute RTCRtpTransceiverDirection direction;
2819
+ readonly attribute RTCRtpTransceiverDirection? currentDirection;
2820
+ void stop();
2821
+ void setCodecPreferences(sequence<RTCRtpCodecCapability> codecs);
2822
+ };
2823
+ */
2824
+
2825
+ var RTPRtcTransceiver = function RTPRtcTransceiver(sender, receiver) {
2826
+
2827
+ //Private attributes
2828
+ var priv = this.priv = {
2829
+ mid: null,
2830
+ sender: sender,
2831
+ receiver: receiver,
2832
+ stopped: false,
2833
+ direction: 'sendrecv',
2834
+ currentDirection: 'sendrecv'
2835
+ };
2836
+
2837
+ //Read only
2838
+ Object.defineProperty(this, 'mid', { enumerable: true, configurable: false, get: function get() {
2839
+ return priv.mid;
2840
+ } });
2841
+ Object.defineProperty(this, 'sender', { enumerable: true, configurable: false, get: function get() {
2842
+ return priv.sender;
2843
+ } });
2844
+ Object.defineProperty(this, 'receiver', { enumerable: true, configurable: false, get: function get() {
2845
+ return priv.receiver;
2846
+ } });
2847
+ Object.defineProperty(this, 'stopped', { enumerable: true, configurable: false, get: function get() {
2848
+ return priv.stopped;
2849
+ } });
2850
+ Object.defineProperty(this, 'currentDirection', { enumerable: true, configurable: false, get: function get() {
2851
+ return priv.currentDirection;
2852
+ } });
2853
+
2854
+ //REad and write
2855
+ Object.defineProperty(this, 'currentDirection', { enumerable: true, configurable: false,
2856
+ get: function get() {
2857
+ return priv.direction;
2858
+ },
2859
+ set: function set(direction) {
2860
+ priv.direction = direction;
2861
+ priv.currentDirection = direction;
2862
+
2863
+ return direction;
2864
+ }
2865
+ });
2866
+ };
2867
+
2868
+ RTPRtcTransceiver.prototype.stop = function () {
2869
+ throw 'Not implemented';
2870
+ };
2871
+
2872
+ Object.defineProperty(RTPRtcTransceiver, 'name', { enumerable: false, configurable: true, writable: false, value: 'RTPRtcTransceiver' });
2873
+ Object.defineProperty(RTPRtcTransceiver, 'prototype', { writable: false });
2874
+ module.exports = RTPRtcTransceiver;
2875
+ }, {}], 15: [function (require, module, exports) {
2876
+ 'use strict';
2877
+
2878
+ /*
2879
+ [Constructor(RTCSessionDescriptionInit descriptionInitDict),
2880
+ Exposed=Window]
2881
+ interface RTCSessionDescription {
2882
+ readonly attribute RTCSdpType type;
2883
+ readonly attribute DOMString sdp;
2884
+ [Default] object toJSON();
2885
+ };
2886
+ dictionary RTCSessionDescriptionInit {
2887
+ required RTCSdpType type;
2888
+ DOMString sdp = "";
2889
+ };
2890
+ */
2891
+
2892
+ function RTCSessionDescription(descriptionInitDict) {
2893
+ //Get values from dictionary
2894
+ // we support custom constructor to pass array instead of object as "dictionary" from activexobject
2895
+ var type = Array.isArray(descriptionInitDict) ? descriptionInitDict[0] : descriptionInitDict.type;
2896
+ var sdp = Array.isArray(descriptionInitDict) ? descriptionInitDict[1] : descriptionInitDict.sdp;
2897
+
2898
+ //Direct attributes from init
2899
+ Object.defineProperty(this, 'type', { enumerable: true, configurable: false, get: function get() {
2900
+ return type;
2901
+ } });
2902
+ Object.defineProperty(this, 'sdp', { enumerable: true, configurable: false, get: function get() {
2903
+ return sdp;
2904
+ } });
2905
+
2906
+ return this;
2907
+ }
2908
+
2909
+ RTCSessionDescription.prototype.toJSON = function () {
2910
+ return {
2911
+ type: this.type,
2912
+ sdp: this.sdp
2913
+ };
2914
+ };
2915
+
2916
+ Object.defineProperty(RTCSessionDescription, 'name', { enumerable: false, configurable: true, writable: false, value: 'RTCSessionDescription' });
2917
+ Object.defineProperty(RTCSessionDescription, 'prototype', { writable: false });
2918
+ module.exports = RTCSessionDescription;
2919
+ }, {}], 16: [function (require, module, exports) {
2920
+ 'use strict';
2921
+
2922
+ // This obvserver checks when a video element has been set a srcObj
2923
+
2924
+ var videoObserver = new MutationObserver(function (mutations) {
2925
+ for (var i = 0, numMutations = mutations.length; i < numMutations; i++) {
2926
+ var mutation = mutations[i];
2927
+ // HTML video element.
2928
+
2929
+ if (mutation.target.videoRenderer) {
2930
+ mutation.target.videoRenderer.mutate(mutation);
2931
+ }
2932
+ }
2933
+ });
2934
+
2935
+ var CLASSID = 'CLSID:B8E874D9-72BA-4E54-B59B-3513081DF516';
2936
+
2937
+ function VideoRenderer(video) {
2938
+ var srcObject;
2939
+ var self = this;
2940
+ //Store video element
2941
+
2942
+ this.video = video;
2943
+
2944
+ //Create a new video renderer object
2945
+ var object = this.object = document.createElement('object');
2946
+ //Set csid
2947
+
2948
+ this.object.classid = CLASSID;
2949
+ //Apped it hidden
2950
+ video.appendChild(this.object);
2951
+
2952
+ // Add .src observer to the video element.
2953
+ videoObserver.observe(video, {
2954
+ // Set to true if additions and removals of the target node's child elements (including text
2955
+ // nodes) are to be observed.
2956
+ childList: false,
2957
+ // Set to true if mutations to target's attributes are to be observed.
2958
+ attributes: true,
2959
+ // Set to true if mutations to target's data are to be observed.
2960
+ characterData: false,
2961
+ // Set to true if mutations to not just target, but also target's descendants are to be observed.
2962
+ subtree: false,
2963
+ // Set to true if attributes is set to true and target's attribute value before the mutation
2964
+ // needs to be recorded.
2965
+ attributeOldValue: true,
2966
+ // Set to true if characterData is set to true and target's data before the mutation needs to be
2967
+ // recorded.
2968
+ characterDataOldValue: false
2969
+ // Set to an array of attribute local names (without namespace) if not all attribute mutations
2970
+ // need to be observed.
2971
+ //attributeFilter: [ 'srcObject']
2972
+ });
2973
+ // Define srcObject properties
2974
+ Object.defineProperty(video, 'srcObject', {
2975
+ enumerable: true,
2976
+ configurable: true,
2977
+ get: function get() {
2978
+ return srcObject;
2979
+ },
2980
+ set: function set(stream) {
2981
+ //We need to fire metadata event when we get first resize
2982
+ var needsmetadata = true;
2983
+ //Attach resize event
2984
+
2985
+ object.onresize = function () {
2986
+ //Create event
2987
+ var event = document.createEvent('Event');
2988
+ //Init metadata or resize event
2989
+
2990
+ event.initEvent(needsmetadata ? 'loadedmetadata' : 'resize', false, false);
2991
+ //Dispatch it
2992
+ video.dispatchEvent(event);
2993
+ //No more medatada event
2994
+ needsmetadata = false;
2995
+ };
2996
+ //Get stream track video stream
2997
+ var videoTracks = stream.getVideoTracks();
2998
+ //If found any
2999
+
3000
+ if (videoTracks.length)
3001
+ //Set native video track on video renderer object
3002
+ {
3003
+ object.setTrack(videoTracks[0].priv.track);
3004
+ }
3005
+ //Store it
3006
+ srcObject = stream;
3007
+ //Show renderer
3008
+ self.show();
3009
+ }
3010
+ });
3011
+
3012
+ // Override properties
3013
+ Object.defineProperty(video, 'videoWidth', { enumerable: true, configurable: true, get: function get() {
3014
+ return object.videoWidth;
3015
+ } });
3016
+ Object.defineProperty(video, 'videoHeight', { enumerable: true, configurable: true, get: function get() {
3017
+ return object.videoHeight;
3018
+ } });
3019
+ //TODO: clone attributes
3020
+ }
3021
+
3022
+ VideoRenderer.prototype.mutate = function (mutation) {
3023
+ //Get mutation type
3024
+ //TODO: clone attributes
3025
+ };
3026
+
3027
+ VideoRenderer.prototype.close = function () {
3028
+ //Hide video object
3029
+ this.hide();
3030
+ //Unobserver video element
3031
+ videoObserver.disconnect();
3032
+ //Remove srcObject property
3033
+ Object.defineProperty(this.video, 'srcObject', {});
3034
+ Object.defineProperty(this.video, 'videoWidth', {});
3035
+ Object.defineProperty(this.video, 'videoHeigth', {});
3036
+ //delete object, IE only method
3037
+ this.object.removeNode(false);
3038
+ delete this.object;
3039
+ };
3040
+
3041
+ VideoRenderer.handle = function (video) {
3042
+ if (!video.videoRenderer) {
3043
+ video.videoRenderer = new VideoRenderer(video);
3044
+ }
3045
+ };
3046
+
3047
+ VideoRenderer.unhandle = function (video) {
3048
+ if (video.videoRenderer) {
3049
+ video.videoRenderer.close();
3050
+ delete video.videoRenderer;
3051
+ }
3052
+ };
3053
+
3054
+ VideoRenderer.prototype.show = function () {
3055
+ //Check object is not shown
3056
+ if (this.video !== this.object.parentElement)
3057
+ //Nothing
3058
+ {
3059
+ return;
3060
+ }
3061
+ //Swap them
3062
+ this.video.parentNode.replaceChild(this.object, this.video);
3063
+ this.object.appendChild(this.video);
3064
+ };
3065
+
3066
+ VideoRenderer.prototype.hide = function () {
3067
+ //Check object is not shown
3068
+ if (this.object !== this.video.parentElement)
3069
+ //Nothing
3070
+ {
3071
+ return;
3072
+ }
3073
+ //Swap them
3074
+ this.object.parentNode.replaceChild(this.video, this.object);
3075
+ this.video.appendChild(this.object);
3076
+ };
3077
+
3078
+ module.exports = VideoRenderer;
3079
+ }, {}], 17: [function (require, module, exports) {
3080
+ 'use strict';
3081
+
3082
+ var browser = require('detect-browser').detect();
3083
+
3084
+ var WebRTCProxy = null;
3085
+
3086
+ //If it is internet explorer
3087
+ if (browser.name === 'ie') {
3088
+ // Create singleton
3089
+ try {
3090
+ WebRTCProxy = new ActiveXObject('Cosmo.WebRTCProxy.1');
3091
+ } catch (e) {
3092
+ console.error('TechSee WebRTC Plugin for IE is not installed');
3093
+ }
3094
+ }
3095
+
3096
+ module.exports = WebRTCProxy;
3097
+ }, { 'detect-browser': 18 }], 18: [function (require, module, exports) {
3098
+ (function (process) {
3099
+
3100
+ /**
3101
+ # detect-browser
3102
+ This is a package that attempts to detect a browser vendor and version (in
3103
+ a semver compatible format) using a navigator useragent in a browser or
3104
+ `process.version` in node.
3105
+ ## NOTE: Version 2.x release
3106
+ Release 2.0 introduces a breaking API change (hence the major release)
3107
+ which requires invocation of a `detect` function rather than just inclusion of
3108
+ the module. PR [#46](https://github.com/DamonOehlman/detect-browser/pull/46)
3109
+ provides more context as to why this change has been made.
3110
+ ## Example Usage
3111
+ <<< examples/simple.js
3112
+ Or you can use a switch statement:
3113
+ <<< examples/switch.js
3114
+ ## Adding additional browser support
3115
+ The current list of browsers that can be detected by `detect-browser` is
3116
+ not exhaustive. If you have a browser that you would like to add support for
3117
+ then please submit a pull request with the implementation.
3118
+ Creating an acceptable implementation requires two things:
3119
+ 1. A test demonstrating that the regular expression you have defined identifies
3120
+ your new browser correctly. Examples of this can be found in the
3121
+ `test/logic.js` file.
3122
+ 2. Write the actual regex to the `lib/detectBrowser.js` file. In most cases adding
3123
+ the regex to the list of existing regexes will be suitable (if usage of `detect-brower`
3124
+ returns `undefined` for instance), but in some cases you might have to add it before
3125
+ an existing regex. This would be true for a case where you have a browser that
3126
+ is a specialised variant of an existing browser but is identified as the
3127
+ non-specialised case.
3128
+ When writing the regular expression remember that you would write it containing a
3129
+ single [capturing group](https://regexone.com/lesson/capturing_groups) which
3130
+ captures the version number of the browser.
3131
+ **/
3132
+
3133
+ function detect() {
3134
+ var nodeVersion = getNodeVersion();
3135
+
3136
+ if (nodeVersion) {
3137
+ return nodeVersion;
3138
+ } else if (typeof navigator !== 'undefined') {
3139
+ return parseUserAgent(navigator.userAgent);
3140
+ }
3141
+
3142
+ return null;
3143
+ }
3144
+
3145
+ function detectOS(userAgentString) {
3146
+ var rules = getOperatingSystemRules();
3147
+ var detected = rules.filter(function (os) {
3148
+ return os.rule && os.rule.test(userAgentString);
3149
+ })[0];
3150
+
3151
+ return detected ? detected.name : null;
3152
+ }
3153
+
3154
+ function getNodeVersion() {
3155
+ var isNode = typeof navigator === 'undefined' && typeof process !== 'undefined';
3156
+
3157
+ return isNode ? {
3158
+ name: 'node',
3159
+ version: process.version.slice(1),
3160
+ os: require('os').type().toLowerCase()
3161
+ } : null;
3162
+ }
3163
+
3164
+ function parseUserAgent(userAgentString) {
3165
+ var browsers = getBrowserRules();
3166
+
3167
+ if (!userAgentString) {
3168
+ return null;
3169
+ }
3170
+
3171
+ var detected = browsers.map(function (browser) {
3172
+ var match = browser.rule.exec(userAgentString);
3173
+ var version = match && match[1].split(/[._]/).slice(0, 3);
3174
+
3175
+ if (version && version.length < 3) {
3176
+ version = version.concat(version.length == 1 ? [0, 0] : [0]);
3177
+ }
3178
+
3179
+ return match && {
3180
+ name: browser.name,
3181
+ version: version.join('.')
3182
+ };
3183
+ }).filter(Boolean)[0] || null;
3184
+
3185
+ if (detected) {
3186
+ detected.os = detectOS(userAgentString);
3187
+ }
3188
+
3189
+ return detected;
3190
+ }
3191
+
3192
+ function getBrowserRules() {
3193
+ return buildRules([['edge', /Edge\/([0-9\._]+)/], ['yandexbrowser', /YaBrowser\/([0-9\._]+)/], ['vivaldi', /Vivaldi\/([0-9\.]+)/], ['kakaotalk', /KAKAOTALK\s([0-9\.]+)/], ['chrome', /(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/], ['phantomjs', /PhantomJS\/([0-9\.]+)(:?\s|$)/], ['crios', /CriOS\/([0-9\.]+)(:?\s|$)/], ['firefox', /Firefox\/([0-9\.]+)(?:\s|$)/], ['fxios', /FxiOS\/([0-9\.]+)/], ['opera', /Opera\/([0-9\.]+)(?:\s|$)/], ['opera', /OPR\/([0-9\.]+)(:?\s|$)$/], ['ie', /Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/], ['ie', /MSIE\s([0-9\.]+);.*Trident\/[4-7].0/], ['ie', /MSIE\s(7\.0)/], ['bb10', /BB10;\sTouch.*Version\/([0-9\.]+)/], ['android', /Android\s([0-9\.]+)/], ['ios', /Version\/([0-9\._]+).*Mobile.*Safari.*/], ['safari', /Version\/([0-9\._]+).*Safari/]]);
3194
+ }
3195
+
3196
+ function getOperatingSystemRules() {
3197
+ return buildRules([['iOS', /iP(hone|od|ad)/], ['Android OS', /Android/], ['BlackBerry OS', /BlackBerry|BB10/], ['Windows Mobile', /IEMobile/], ['Amazon OS', /Kindle/], ['Windows 3.11', /Win16/], ['Windows 95', /(Windows 95)|(Win95)|(Windows_95)/], ['Windows 98', /(Windows 98)|(Win98)/], ['Windows 2000', /(Windows NT 5.0)|(Windows 2000)/], ['Windows XP', /(Windows NT 5.1)|(Windows XP)/], ['Windows Server 2003', /(Windows NT 5.2)/], ['Windows Vista', /(Windows NT 6.0)/], ['Windows 7', /(Windows NT 6.1)/], ['Windows 8', /(Windows NT 6.2)/], ['Windows 8.1', /(Windows NT 6.3)/], ['Windows 10', /(Windows NT 10.0)/], ['Windows ME', /Windows ME/], ['Open BSD', /OpenBSD/], ['Sun OS', /SunOS/], ['Linux', /(Linux)|(X11)/], ['Mac OS', /(Mac_PowerPC)|(Macintosh)/], ['QNX', /QNX/], ['BeOS', /BeOS/], ['OS/2', /OS\/2/], ['Search Bot', /(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves\/Teoma)|(ia_archiver)/]]);
3198
+ }
3199
+
3200
+ function buildRules(ruleTuples) {
3201
+ return ruleTuples.map(function (tuple) {
3202
+ return {
3203
+ name: tuple[0],
3204
+ rule: tuple[1]
3205
+ };
3206
+ });
3207
+ }
3208
+
3209
+ module.exports = {
3210
+ detect: detect,
3211
+ detectOS: detectOS,
3212
+ getNodeVersion: getNodeVersion,
3213
+ parseUserAgent: parseUserAgent
3214
+ };
3215
+ }).call(this, require('_process'));
3216
+ }, { '_process': 2, 'os': 1 }] }, {}, [3])(3);
3217
+ });
3218
+ //# sourceMappingURL=webrtc-ie-shim.js.map