@techsee/techsee-media-service 999.20.0-nodejs.lite.2 → 999.20.1-alpha

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