peerjs
Version:
PeerJS client
1,128 lines (1,116 loc) • 225 kB
JavaScript
(() => {
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
class $616ebdf1c4998439$export$f1c5f4c9cb95390b {
constructor(){
this.chunkedMTU = 16300 // The original 60000 bytes setting does not work when sending data from Firefox to Chrome, which is "cut off" after 16384 bytes and delivered individually.
;
// Binary stuff
this._dataCount = 1;
this.chunk = (blob)=>{
const chunks = [];
const size = blob.byteLength;
const total = Math.ceil(size / this.chunkedMTU);
let index = 0;
let start = 0;
while(start < size){
const end = Math.min(size, start + this.chunkedMTU);
const b = blob.slice(start, end);
const chunk = {
__peerData: this._dataCount,
n: index,
data: b,
total: total
};
chunks.push(chunk);
start = end;
index++;
}
this._dataCount++;
return chunks;
};
}
}
function $616ebdf1c4998439$export$52c89ebcdc4f53f2(bufs) {
let size = 0;
for (const buf of bufs)size += buf.byteLength;
const result = new Uint8Array(size);
let offset = 0;
for (const buf of bufs){
result.set(buf, offset);
offset += buf.byteLength;
}
return result;
}
class $bf7fb46c6d68ead7$var$$e8379818650e2442$export$93654d4f2d6cd524 {
append_buffer(data) {
this.flush();
this._parts.push(data);
}
append(data) {
this._pieces.push(data);
}
flush() {
if (this._pieces.length > 0) {
const buf = new Uint8Array(this._pieces);
this._parts.push(buf);
this._pieces = [];
}
}
toArrayBuffer() {
const buffer = [];
for (const part of this._parts)buffer.push(part);
return $bf7fb46c6d68ead7$var$$e8379818650e2442$var$concatArrayBuffers(buffer).buffer;
}
constructor(){
this.encoder = new TextEncoder();
this._pieces = [];
this._parts = [];
}
}
function $bf7fb46c6d68ead7$var$$e8379818650e2442$var$concatArrayBuffers(bufs) {
let size = 0;
for (const buf of bufs)size += buf.byteLength;
const result = new Uint8Array(size);
let offset = 0;
for (const buf of bufs){
const view = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
result.set(view, offset);
offset += buf.byteLength;
}
return result;
}
function $bf7fb46c6d68ead7$export$417857010dc9287f(data) {
const unpacker = new $bf7fb46c6d68ead7$var$$0cfd7828ad59115f$var$Unpacker(data);
return unpacker.unpack();
}
function $bf7fb46c6d68ead7$export$2a703dbb0cb35339(data) {
const packer = new $bf7fb46c6d68ead7$export$b9ec4b114aa40074();
const res = packer.pack(data);
if (res instanceof Promise) return res.then(()=>packer.getBuffer());
return packer.getBuffer();
}
class $bf7fb46c6d68ead7$var$$0cfd7828ad59115f$var$Unpacker {
unpack() {
const type = this.unpack_uint8();
if (type < 0x80) return type;
else if ((type ^ 0xe0) < 0x20) return (type ^ 0xe0) - 0x20;
let size;
if ((size = type ^ 0xa0) <= 0x0f) return this.unpack_raw(size);
else if ((size = type ^ 0xb0) <= 0x0f) return this.unpack_string(size);
else if ((size = type ^ 0x90) <= 0x0f) return this.unpack_array(size);
else if ((size = type ^ 0x80) <= 0x0f) return this.unpack_map(size);
switch(type){
case 0xc0:
return null;
case 0xc1:
return undefined;
case 0xc2:
return false;
case 0xc3:
return true;
case 0xca:
return this.unpack_float();
case 0xcb:
return this.unpack_double();
case 0xcc:
return this.unpack_uint8();
case 0xcd:
return this.unpack_uint16();
case 0xce:
return this.unpack_uint32();
case 0xcf:
return this.unpack_uint64();
case 0xd0:
return this.unpack_int8();
case 0xd1:
return this.unpack_int16();
case 0xd2:
return this.unpack_int32();
case 0xd3:
return this.unpack_int64();
case 0xd4:
return undefined;
case 0xd5:
return undefined;
case 0xd6:
return undefined;
case 0xd7:
return undefined;
case 0xd8:
size = this.unpack_uint16();
return this.unpack_string(size);
case 0xd9:
size = this.unpack_uint32();
return this.unpack_string(size);
case 0xda:
size = this.unpack_uint16();
return this.unpack_raw(size);
case 0xdb:
size = this.unpack_uint32();
return this.unpack_raw(size);
case 0xdc:
size = this.unpack_uint16();
return this.unpack_array(size);
case 0xdd:
size = this.unpack_uint32();
return this.unpack_array(size);
case 0xde:
size = this.unpack_uint16();
return this.unpack_map(size);
case 0xdf:
size = this.unpack_uint32();
return this.unpack_map(size);
}
}
unpack_uint8() {
const byte = this.dataView[this.index] & 0xff;
this.index++;
return byte;
}
unpack_uint16() {
const bytes = this.read(2);
const uint16 = (bytes[0] & 0xff) * 256 + (bytes[1] & 0xff);
this.index += 2;
return uint16;
}
unpack_uint32() {
const bytes = this.read(4);
const uint32 = ((bytes[0] * 256 + bytes[1]) * 256 + bytes[2]) * 256 + bytes[3];
this.index += 4;
return uint32;
}
unpack_uint64() {
const bytes = this.read(8);
const uint64 = ((((((bytes[0] * 256 + bytes[1]) * 256 + bytes[2]) * 256 + bytes[3]) * 256 + bytes[4]) * 256 + bytes[5]) * 256 + bytes[6]) * 256 + bytes[7];
this.index += 8;
return uint64;
}
unpack_int8() {
const uint8 = this.unpack_uint8();
return uint8 < 0x80 ? uint8 : uint8 - 256;
}
unpack_int16() {
const uint16 = this.unpack_uint16();
return uint16 < 0x8000 ? uint16 : uint16 - 65536;
}
unpack_int32() {
const uint32 = this.unpack_uint32();
return uint32 < 2 ** 31 ? uint32 : uint32 - 2 ** 32;
}
unpack_int64() {
const uint64 = this.unpack_uint64();
return uint64 < 2 ** 63 ? uint64 : uint64 - 2 ** 64;
}
unpack_raw(size) {
if (this.length < this.index + size) throw new Error(`BinaryPackFailure: index is out of range ${this.index} ${size} ${this.length}`);
const buf = this.dataBuffer.slice(this.index, this.index + size);
this.index += size;
return buf;
}
unpack_string(size) {
const bytes = this.read(size);
let i = 0;
let str = "";
let c;
let code;
while(i < size){
c = bytes[i];
// The length of a UTF-8 sequence is specified in the first byte:
// 0xxxxxxx means length 1,
// 110xxxxx means length 2,
// 1110xxxx means length 3,
// 11110xxx means length 4.
// 10xxxxxx is for non-initial bytes.
if (c < 0xa0) {
// One-byte sequence: bits 0xxxxxxx
code = c;
i++;
} else if ((c ^ 0xc0) < 0x20) {
// Two-byte sequence: bits 110xxxxx 10xxxxxx
code = (c & 0x1f) << 6 | bytes[i + 1] & 0x3f;
i += 2;
} else if ((c ^ 0xe0) < 0x10) {
// Three-byte sequence: bits 1110xxxx 10xxxxxx 10xxxxxx
code = (c & 0x0f) << 12 | (bytes[i + 1] & 0x3f) << 6 | bytes[i + 2] & 0x3f;
i += 3;
} else {
// Four-byte sequence: bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
code = (c & 0x07) << 18 | (bytes[i + 1] & 0x3f) << 12 | (bytes[i + 2] & 0x3f) << 6 | bytes[i + 3] & 0x3f;
i += 4;
}
str += String.fromCodePoint(code);
}
this.index += size;
return str;
}
unpack_array(size) {
const objects = new Array(size);
for(let i = 0; i < size; i++)objects[i] = this.unpack();
return objects;
}
unpack_map(size) {
const map = {};
for(let i = 0; i < size; i++){
const key = this.unpack();
map[key] = this.unpack();
}
return map;
}
unpack_float() {
const uint32 = this.unpack_uint32();
const sign = uint32 >> 31;
const exp = (uint32 >> 23 & 0xff) - 127;
const fraction = uint32 & 0x7fffff | 0x800000;
return (sign === 0 ? 1 : -1) * fraction * 2 ** (exp - 23);
}
unpack_double() {
const h32 = this.unpack_uint32();
const l32 = this.unpack_uint32();
const sign = h32 >> 31;
const exp = (h32 >> 20 & 0x7ff) - 1023;
const hfrac = h32 & 0xfffff | 0x100000;
const frac = hfrac * 2 ** (exp - 20) + l32 * 2 ** (exp - 52);
return (sign === 0 ? 1 : -1) * frac;
}
read(length) {
const j = this.index;
if (j + length <= this.length) return this.dataView.subarray(j, j + length);
else throw new Error("BinaryPackFailure: read index out of range");
}
constructor(data){
this.index = 0;
this.dataBuffer = data;
this.dataView = new Uint8Array(this.dataBuffer);
this.length = this.dataBuffer.byteLength;
}
}
class $bf7fb46c6d68ead7$export$b9ec4b114aa40074 {
getBuffer() {
return this._bufferBuilder.toArrayBuffer();
}
pack(value) {
if (typeof value === "string") this.pack_string(value);
else if (typeof value === "number") {
if (Math.floor(value) === value) this.pack_integer(value);
else this.pack_double(value);
} else if (typeof value === "boolean") {
if (value === true) this._bufferBuilder.append(0xc3);
else if (value === false) this._bufferBuilder.append(0xc2);
} else if (value === undefined) this._bufferBuilder.append(0xc0);
else if (typeof value === "object") {
if (value === null) this._bufferBuilder.append(0xc0);
else {
const constructor = value.constructor;
if (value instanceof Array) {
const res = this.pack_array(value);
if (res instanceof Promise) return res.then(()=>this._bufferBuilder.flush());
} else if (value instanceof ArrayBuffer) this.pack_bin(new Uint8Array(value));
else if ("BYTES_PER_ELEMENT" in value) {
const v = value;
this.pack_bin(new Uint8Array(v.buffer, v.byteOffset, v.byteLength));
} else if (value instanceof Date) this.pack_string(value.toString());
else if (value instanceof Blob) return value.arrayBuffer().then((buffer)=>{
this.pack_bin(new Uint8Array(buffer));
this._bufferBuilder.flush();
});
else if (constructor == Object || constructor.toString().startsWith("class")) {
const res = this.pack_object(value);
if (res instanceof Promise) return res.then(()=>this._bufferBuilder.flush());
} else throw new Error(`Type "${constructor.toString()}" not yet supported`);
}
} else throw new Error(`Type "${typeof value}" not yet supported`);
this._bufferBuilder.flush();
}
pack_bin(blob) {
const length = blob.length;
if (length <= 0x0f) this.pack_uint8(0xa0 + length);
else if (length <= 0xffff) {
this._bufferBuilder.append(0xda);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this._bufferBuilder.append(0xdb);
this.pack_uint32(length);
} else throw new Error("Invalid length");
this._bufferBuilder.append_buffer(blob);
}
pack_string(str) {
const encoded = this._textEncoder.encode(str);
const length = encoded.length;
if (length <= 0x0f) this.pack_uint8(0xb0 + length);
else if (length <= 0xffff) {
this._bufferBuilder.append(0xd8);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this._bufferBuilder.append(0xd9);
this.pack_uint32(length);
} else throw new Error("Invalid length");
this._bufferBuilder.append_buffer(encoded);
}
pack_array(ary) {
const length = ary.length;
if (length <= 0x0f) this.pack_uint8(0x90 + length);
else if (length <= 0xffff) {
this._bufferBuilder.append(0xdc);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this._bufferBuilder.append(0xdd);
this.pack_uint32(length);
} else throw new Error("Invalid length");
const packNext = (index)=>{
if (index < length) {
const res = this.pack(ary[index]);
if (res instanceof Promise) return res.then(()=>packNext(index + 1));
return packNext(index + 1);
}
};
return packNext(0);
}
pack_integer(num) {
if (num >= -32 && num <= 0x7f) this._bufferBuilder.append(num & 0xff);
else if (num >= 0x00 && num <= 0xff) {
this._bufferBuilder.append(0xcc);
this.pack_uint8(num);
} else if (num >= -128 && num <= 0x7f) {
this._bufferBuilder.append(0xd0);
this.pack_int8(num);
} else if (num >= 0x0000 && num <= 0xffff) {
this._bufferBuilder.append(0xcd);
this.pack_uint16(num);
} else if (num >= -32768 && num <= 0x7fff) {
this._bufferBuilder.append(0xd1);
this.pack_int16(num);
} else if (num >= 0x00000000 && num <= 0xffffffff) {
this._bufferBuilder.append(0xce);
this.pack_uint32(num);
} else if (num >= -2147483648 && num <= 0x7fffffff) {
this._bufferBuilder.append(0xd2);
this.pack_int32(num);
} else if (num >= -9223372036854776000 && num <= 0x7fffffffffffffff) {
this._bufferBuilder.append(0xd3);
this.pack_int64(num);
} else if (num >= 0x0000000000000000 && num <= 0xffffffffffffffff) {
this._bufferBuilder.append(0xcf);
this.pack_uint64(num);
} else throw new Error("Invalid integer");
}
pack_double(num) {
let sign = 0;
if (num < 0) {
sign = 1;
num = -num;
}
const exp = Math.floor(Math.log(num) / Math.LN2);
const frac0 = num / 2 ** exp - 1;
const frac1 = Math.floor(frac0 * 2 ** 52);
const b32 = 2 ** 32;
const h32 = sign << 31 | exp + 1023 << 20 | frac1 / b32 & 0x0fffff;
const l32 = frac1 % b32;
this._bufferBuilder.append(0xcb);
this.pack_int32(h32);
this.pack_int32(l32);
}
pack_object(obj) {
const keys = Object.keys(obj);
const length = keys.length;
if (length <= 0x0f) this.pack_uint8(0x80 + length);
else if (length <= 0xffff) {
this._bufferBuilder.append(0xde);
this.pack_uint16(length);
} else if (length <= 0xffffffff) {
this._bufferBuilder.append(0xdf);
this.pack_uint32(length);
} else throw new Error("Invalid length");
const packNext = (index)=>{
if (index < keys.length) {
const prop = keys[index];
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(prop)) {
this.pack(prop);
const res = this.pack(obj[prop]);
if (res instanceof Promise) return res.then(()=>packNext(index + 1));
}
return packNext(index + 1);
}
};
return packNext(0);
}
pack_uint8(num) {
this._bufferBuilder.append(num);
}
pack_uint16(num) {
this._bufferBuilder.append(num >> 8);
this._bufferBuilder.append(num & 0xff);
}
pack_uint32(num) {
const n = num & 0xffffffff;
this._bufferBuilder.append((n & 0xff000000) >>> 24);
this._bufferBuilder.append((n & 0x00ff0000) >>> 16);
this._bufferBuilder.append((n & 0x0000ff00) >>> 8);
this._bufferBuilder.append(n & 0x000000ff);
}
pack_uint64(num) {
const high = num / 2 ** 32;
const low = num % 2 ** 32;
this._bufferBuilder.append((high & 0xff000000) >>> 24);
this._bufferBuilder.append((high & 0x00ff0000) >>> 16);
this._bufferBuilder.append((high & 0x0000ff00) >>> 8);
this._bufferBuilder.append(high & 0x000000ff);
this._bufferBuilder.append((low & 0xff000000) >>> 24);
this._bufferBuilder.append((low & 0x00ff0000) >>> 16);
this._bufferBuilder.append((low & 0x0000ff00) >>> 8);
this._bufferBuilder.append(low & 0x000000ff);
}
pack_int8(num) {
this._bufferBuilder.append(num & 0xff);
}
pack_int16(num) {
this._bufferBuilder.append((num & 0xff00) >> 8);
this._bufferBuilder.append(num & 0xff);
}
pack_int32(num) {
this._bufferBuilder.append(num >>> 24 & 0xff);
this._bufferBuilder.append((num & 0x00ff0000) >>> 16);
this._bufferBuilder.append((num & 0x0000ff00) >>> 8);
this._bufferBuilder.append(num & 0x000000ff);
}
pack_int64(num) {
const high = Math.floor(num / 2 ** 32);
const low = num % 2 ** 32;
this._bufferBuilder.append((high & 0xff000000) >>> 24);
this._bufferBuilder.append((high & 0x00ff0000) >>> 16);
this._bufferBuilder.append((high & 0x0000ff00) >>> 8);
this._bufferBuilder.append(high & 0x000000ff);
this._bufferBuilder.append((low & 0xff000000) >>> 24);
this._bufferBuilder.append((low & 0x00ff0000) >>> 16);
this._bufferBuilder.append((low & 0x0000ff00) >>> 8);
this._bufferBuilder.append(low & 0x000000ff);
}
constructor(){
this._bufferBuilder = new $bf7fb46c6d68ead7$var$$e8379818650e2442$export$93654d4f2d6cd524();
this._textEncoder = new TextEncoder();
}
}
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/ /* eslint-env node */ /*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/ /*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/ /* eslint-env node */ "use strict";
let $9fea4db837311579$var$logDisabled_ = true;
let $9fea4db837311579$var$deprecationWarnings_ = true;
function $9fea4db837311579$export$e3c02be309be1f23(uastring, expr, pos) {
const match = uastring.match(expr);
return match && match.length >= pos && parseInt(match[pos], 10);
}
function $9fea4db837311579$export$1f48841962b828b1(window1, eventNameToWrap, wrapper) {
if (!window1.RTCPeerConnection) return;
const proto = window1.RTCPeerConnection.prototype;
const nativeAddEventListener = proto.addEventListener;
proto.addEventListener = function(nativeEventName, cb) {
if (nativeEventName !== eventNameToWrap) return nativeAddEventListener.apply(this, arguments);
const wrappedCallback = (e)=>{
const modifiedEvent = wrapper(e);
if (modifiedEvent) {
if (cb.handleEvent) cb.handleEvent(modifiedEvent);
else cb(modifiedEvent);
}
};
this._eventMap = this._eventMap || {};
if (!this._eventMap[eventNameToWrap]) this._eventMap[eventNameToWrap] = new Map();
this._eventMap[eventNameToWrap].set(cb, wrappedCallback);
return nativeAddEventListener.apply(this, [
nativeEventName,
wrappedCallback
]);
};
const nativeRemoveEventListener = proto.removeEventListener;
proto.removeEventListener = function(nativeEventName, cb) {
if (nativeEventName !== eventNameToWrap || !this._eventMap || !this._eventMap[eventNameToWrap]) return nativeRemoveEventListener.apply(this, arguments);
if (!this._eventMap[eventNameToWrap].has(cb)) return nativeRemoveEventListener.apply(this, arguments);
const unwrappedCb = this._eventMap[eventNameToWrap].get(cb);
this._eventMap[eventNameToWrap].delete(cb);
if (this._eventMap[eventNameToWrap].size === 0) delete this._eventMap[eventNameToWrap];
if (Object.keys(this._eventMap).length === 0) delete this._eventMap;
return nativeRemoveEventListener.apply(this, [
nativeEventName,
unwrappedCb
]);
};
Object.defineProperty(proto, "on" + eventNameToWrap, {
get () {
return this["_on" + eventNameToWrap];
},
set (cb) {
if (this["_on" + eventNameToWrap]) {
this.removeEventListener(eventNameToWrap, this["_on" + eventNameToWrap]);
delete this["_on" + eventNameToWrap];
}
if (cb) this.addEventListener(eventNameToWrap, this["_on" + eventNameToWrap] = cb);
},
enumerable: true,
configurable: true
});
}
function $9fea4db837311579$export$afbfee8cc06fd3e4(bool) {
if (typeof bool !== "boolean") return new Error("Argument type: " + typeof bool + ". Please use a boolean.");
$9fea4db837311579$var$logDisabled_ = bool;
return bool ? "adapter.js logging disabled" : "adapter.js logging enabled";
}
function $9fea4db837311579$export$51516be4b019e41e(bool) {
if (typeof bool !== "boolean") return new Error("Argument type: " + typeof bool + ". Please use a boolean.");
$9fea4db837311579$var$deprecationWarnings_ = !bool;
return "adapter.js deprecation warnings " + (bool ? "disabled" : "enabled");
}
function $9fea4db837311579$export$bef1f36f5486a6a3() {
if (typeof window === "object") {
if ($9fea4db837311579$var$logDisabled_) return;
if (typeof console !== "undefined" && typeof console.log === "function") console.log.apply(console, arguments);
}
}
function $9fea4db837311579$export$cdd73fc4100a6ef4(oldMethod, newMethod) {
if (!$9fea4db837311579$var$deprecationWarnings_) return;
console.warn(oldMethod + " is deprecated, please use " + newMethod + " instead.");
}
function $9fea4db837311579$export$2d31490a0c05f094(window1) {
// Returned result object.
const result = {
browser: null,
version: null
};
// Fail early if it's not a browser
if (typeof window1 === "undefined" || !window1.navigator || !window1.navigator.userAgent) {
result.browser = "Not a browser.";
return result;
}
const { navigator: navigator } = window1;
// Prefer navigator.userAgentData.
if (navigator.userAgentData && navigator.userAgentData.brands) {
const chromium = navigator.userAgentData.brands.find((brand)=>{
return brand.brand === "Chromium";
});
if (chromium) return {
browser: "chrome",
version: parseInt(chromium.version, 10)
};
}
if (navigator.mozGetUserMedia) {
result.browser = "firefox";
result.version = $9fea4db837311579$export$e3c02be309be1f23(navigator.userAgent, /Firefox\/(\d+)\./, 1);
} else if (navigator.webkitGetUserMedia || window1.isSecureContext === false && window1.webkitRTCPeerConnection) {
// Chrome, Chromium, Webview, Opera.
// Version matches Chrome/WebRTC version.
// Chrome 74 removed webkitGetUserMedia on http as well so we need the
// more complicated fallback to webkitRTCPeerConnection.
result.browser = "chrome";
result.version = $9fea4db837311579$export$e3c02be309be1f23(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
} else if (window1.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
result.browser = "safari";
result.version = $9fea4db837311579$export$e3c02be309be1f23(navigator.userAgent, /AppleWebKit\/(\d+)\./, 1);
result.supportsUnifiedPlan = window1.RTCRtpTransceiver && "currentDirection" in window1.RTCRtpTransceiver.prototype;
} else {
result.browser = "Not a supported browser.";
return result;
}
return result;
}
/**
* Checks if something is an object.
*
* @param {*} val The something you want to check.
* @return true if val is an object, false otherwise.
*/ function $9fea4db837311579$var$isObject(val) {
return Object.prototype.toString.call(val) === "[object Object]";
}
function $9fea4db837311579$export$15384eac40dc88c8(data) {
if (!$9fea4db837311579$var$isObject(data)) return data;
return Object.keys(data).reduce(function(accumulator, key) {
const isObj = $9fea4db837311579$var$isObject(data[key]);
const value = isObj ? $9fea4db837311579$export$15384eac40dc88c8(data[key]) : data[key];
const isEmptyObject = isObj && !Object.keys(value).length;
if (value === undefined || isEmptyObject) return accumulator;
return Object.assign(accumulator, {
[key]: value
});
}, {});
}
function $9fea4db837311579$export$571b373e75babb58(stats, base, resultSet) {
if (!base || resultSet.has(base.id)) return;
resultSet.set(base.id, base);
Object.keys(base).forEach((name)=>{
if (name.endsWith("Id")) $9fea4db837311579$export$571b373e75babb58(stats, stats.get(base[name]), resultSet);
else if (name.endsWith("Ids")) base[name].forEach((id)=>{
$9fea4db837311579$export$571b373e75babb58(stats, stats.get(id), resultSet);
});
});
}
function $9fea4db837311579$export$93439ffc3f787d51(result, track, outbound) {
const streamStatsType = outbound ? "outbound-rtp" : "inbound-rtp";
const filteredResult = new Map();
if (track === null) return filteredResult;
const trackStats = [];
result.forEach((value)=>{
if (value.type === "track" && value.trackIdentifier === track.id) trackStats.push(value);
});
trackStats.forEach((trackStat)=>{
result.forEach((stats)=>{
if (stats.type === streamStatsType && stats.trackId === trackStat.id) $9fea4db837311579$export$571b373e75babb58(result, stats, filteredResult);
});
});
return filteredResult;
}
var $fb04e59b477f17ce$exports = {};
$parcel$export($fb04e59b477f17ce$exports, "shimMediaStream", () => $fb04e59b477f17ce$export$33ee24e7a300bcd1);
$parcel$export($fb04e59b477f17ce$exports, "shimOnTrack", () => $fb04e59b477f17ce$export$f358708f68ab068);
$parcel$export($fb04e59b477f17ce$exports, "shimGetSendersWithDtmf", () => $fb04e59b477f17ce$export$a41a030a2842f5d6);
$parcel$export($fb04e59b477f17ce$exports, "shimSenderReceiverGetStats", () => $fb04e59b477f17ce$export$f2f0f2338114eb4b);
$parcel$export($fb04e59b477f17ce$exports, "shimAddTrackRemoveTrackWithNative", () => $fb04e59b477f17ce$export$30e3cdd46f8d5100);
$parcel$export($fb04e59b477f17ce$exports, "shimAddTrackRemoveTrack", () => $fb04e59b477f17ce$export$9588259fcf4ebc91);
$parcel$export($fb04e59b477f17ce$exports, "shimPeerConnection", () => $fb04e59b477f17ce$export$852a08dda9a55ea7);
$parcel$export($fb04e59b477f17ce$exports, "fixNegotiationNeeded", () => $fb04e59b477f17ce$export$341293bbeaae37cb);
$parcel$export($fb04e59b477f17ce$exports, "shimGetUserMedia", () => $de41d89a4eaa283f$export$1ed4910f4d37dc5e);
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/ /* eslint-env node */
/*
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree.
*/ /* eslint-env node */
"use strict";
const $de41d89a4eaa283f$var$logging = $9fea4db837311579$export$bef1f36f5486a6a3;
function $de41d89a4eaa283f$export$1ed4910f4d37dc5e(window, browserDetails) {
const navigator = window && window.navigator;
if (!navigator.mediaDevices) return;
const constraintsToChrome_ = function(c) {
if (typeof c !== "object" || c.mandatory || c.optional) return c;
const cc = {};
Object.keys(c).forEach((key)=>{
if (key === "require" || key === "advanced" || key === "mediaSource") return;
const r = typeof c[key] === "object" ? c[key] : {
ideal: c[key]
};
if (r.exact !== undefined && typeof r.exact === "number") r.min = r.max = r.exact;
const oldname_ = function(prefix, name) {
if (prefix) return prefix + name.charAt(0).toUpperCase() + name.slice(1);
return name === "deviceId" ? "sourceId" : name;
};
if (r.ideal !== undefined) {
cc.optional = cc.optional || [];
let oc = {};
if (typeof r.ideal === "number") {
oc[oldname_("min", key)] = r.ideal;
cc.optional.push(oc);
oc = {};
oc[oldname_("max", key)] = r.ideal;
cc.optional.push(oc);
} else {
oc[oldname_("", key)] = r.ideal;
cc.optional.push(oc);
}
}
if (r.exact !== undefined && typeof r.exact !== "number") {
cc.mandatory = cc.mandatory || {};
cc.mandatory[oldname_("", key)] = r.exact;
} else [
"min",
"max"
].forEach((mix)=>{
if (r[mix] !== undefined) {
cc.mandatory = cc.mandatory || {};
cc.mandatory[oldname_(mix, key)] = r[mix];
}
});
});
if (c.advanced) cc.optional = (cc.optional || []).concat(c.advanced);
return cc;
};
const shimConstraints_ = function(constraints, func) {
if (browserDetails.version >= 61) return func(constraints);
constraints = JSON.parse(JSON.stringify(constraints));
if (constraints && typeof constraints.audio === "object") {
const remap = function(obj, a, b) {
if (a in obj && !(b in obj)) {
obj[b] = obj[a];
delete obj[a];
}
};
constraints = JSON.parse(JSON.stringify(constraints));
remap(constraints.audio, "autoGainControl", "googAutoGainControl");
remap(constraints.audio, "noiseSuppression", "googNoiseSuppression");
constraints.audio = constraintsToChrome_(constraints.audio);
}
if (constraints && typeof constraints.video === "object") {
// Shim facingMode for mobile & surface pro.
let face = constraints.video.facingMode;
face = face && (typeof face === "object" ? face : {
ideal: face
});
const getSupportedFacingModeLies = browserDetails.version < 66;
if (face && (face.exact === "user" || face.exact === "environment" || face.ideal === "user" || face.ideal === "environment") && !(navigator.mediaDevices.getSupportedConstraints && navigator.mediaDevices.getSupportedConstraints().facingMode && !getSupportedFacingModeLies)) {
delete constraints.video.facingMode;
let matches;
if (face.exact === "environment" || face.ideal === "environment") matches = [
"back",
"rear"
];
else if (face.exact === "user" || face.ideal === "user") matches = [
"front"
];
if (matches) // Look for matches in label, or use last cam for back (typical).
return navigator.mediaDevices.enumerateDevices().then((devices)=>{
devices = devices.filter((d)=>d.kind === "videoinput");
let dev = devices.find((d)=>matches.some((match)=>d.label.toLowerCase().includes(match)));
if (!dev && devices.length && matches.includes("back")) dev = devices[devices.length - 1]; // more likely the back cam
if (dev) constraints.video.deviceId = face.exact ? {
exact: dev.deviceId
} : {
ideal: dev.deviceId
};
constraints.video = constraintsToChrome_(constraints.video);
$de41d89a4eaa283f$var$logging("chrome: " + JSON.stringify(constraints));
return func(constraints);
});
}
constraints.video = constraintsToChrome_(constraints.video);
}
$de41d89a4eaa283f$var$logging("chrome: " + JSON.stringify(constraints));
return func(constraints);
};
const shimError_ = function(e) {
if (browserDetails.version >= 64) return e;
return {
name: ({
PermissionDeniedError: "NotAllowedError",
PermissionDismissedError: "NotAllowedError",
InvalidStateError: "NotAllowedError",
DevicesNotFoundError: "NotFoundError",
ConstraintNotSatisfiedError: "OverconstrainedError",
TrackStartError: "NotReadableError",
MediaDeviceFailedDueToShutdown: "NotAllowedError",
MediaDeviceKillSwitchOn: "NotAllowedError",
TabCaptureError: "AbortError",
ScreenCaptureError: "AbortError",
DeviceCaptureError: "AbortError"
})[e.name] || e.name,
message: e.message,
constraint: e.constraint || e.constraintName,
toString () {
return this.name + (this.message && ": ") + this.message;
}
};
};
const getUserMedia_ = function(constraints, onSuccess, onError) {
shimConstraints_(constraints, (c)=>{
navigator.webkitGetUserMedia(c, onSuccess, (e)=>{
if (onError) onError(shimError_(e));
});
});
};
navigator.getUserMedia = getUserMedia_.bind(navigator);
// Even though Chrome 45 has navigator.mediaDevices and a getUserMedia
// function which returns a Promise, it does not accept spec-style
// constraints.
if (navigator.mediaDevices.getUserMedia) {
const origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
navigator.mediaDevices.getUserMedia = function(cs) {
return shimConstraints_(cs, (c)=>origGetUserMedia(c).then((stream)=>{
if (c.audio && !stream.getAudioTracks().length || c.video && !stream.getVideoTracks().length) {
stream.getTracks().forEach((track)=>{
track.stop();
});
throw new DOMException("", "NotFoundError");
}
return stream;
}, (e)=>Promise.reject(shimError_(e))));
};
}
}
"use strict";
function $fb04e59b477f17ce$export$33ee24e7a300bcd1(window) {
window.MediaStream = window.MediaStream || window.webkitMediaStream;
}
function $fb04e59b477f17ce$export$f358708f68ab068(window) {
if (typeof window === "object" && window.RTCPeerConnection && !("ontrack" in window.RTCPeerConnection.prototype)) {
Object.defineProperty(window.RTCPeerConnection.prototype, "ontrack", {
get () {
return this._ontrack;
},
set (f) {
if (this._ontrack) this.removeEventListener("track", this._ontrack);
this.addEventListener("track", this._ontrack = f);
},
enumerable: true,
configurable: true
});
const origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
if (!this._ontrackpoly) {
this._ontrackpoly = (e)=>{
// onaddstream does not fire when a track is added to an existing
// stream. But stream.onaddtrack is implemented so we use that.
e.stream.addEventListener("addtrack", (te)=>{
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) receiver = this.getReceivers().find((r)=>r.track && r.track.id === te.track.id);
else receiver = {
track: te.track
};
const event = new Event("track");
event.track = te.track;
event.receiver = receiver;
event.transceiver = {
receiver: receiver
};
event.streams = [
e.stream
];
this.dispatchEvent(event);
});
e.stream.getTracks().forEach((track)=>{
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) receiver = this.getReceivers().find((r)=>r.track && r.track.id === track.id);
else receiver = {
track: track
};
const event = new Event("track");
event.track = track;
event.receiver = receiver;
event.transceiver = {
receiver: receiver
};
event.streams = [
e.stream
];
this.dispatchEvent(event);
});
};
this.addEventListener("addstream", this._ontrackpoly);
}
return origSetRemoteDescription.apply(this, arguments);
};
} else // even if RTCRtpTransceiver is in window, it is only used and
// emitted in unified-plan. Unfortunately this means we need
// to unconditionally wrap the event.
$9fea4db837311579$export$1f48841962b828b1(window, "track", (e)=>{
if (!e.transceiver) Object.defineProperty(e, "transceiver", {
value: {
receiver: e.receiver
}
});
return e;
});
}
function $fb04e59b477f17ce$export$a41a030a2842f5d6(window) {
// Overrides addTrack/removeTrack, depends on shimAddTrackRemoveTrack.
if (typeof window === "object" && window.RTCPeerConnection && !("getSenders" in window.RTCPeerConnection.prototype) && "createDTMFSender" in window.RTCPeerConnection.prototype) {
const shimSenderWithDtmf = function(pc, track) {
return {
track: track,
get dtmf () {
if (this._dtmf === undefined) {
if (track.kind === "audio") this._dtmf = pc.createDTMFSender(track);
else this._dtmf = null;
}
return this._dtmf;
},
_pc: pc
};
};
// augment addTrack when getSenders is not available.
if (!window.RTCPeerConnection.prototype.getSenders) {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
this._senders = this._senders || [];
return this._senders.slice(); // return a copy of the internal state.
};
const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
let sender = origAddTrack.apply(this, arguments);
if (!sender) {
sender = shimSenderWithDtmf(this, track);
this._senders.push(sender);
}
return sender;
};
const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
origRemoveTrack.apply(this, arguments);
const idx = this._senders.indexOf(sender);
if (idx !== -1) this._senders.splice(idx, 1);
};
}
const origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
this._senders = this._senders || [];
origAddStream.apply(this, [
stream
]);
stream.getTracks().forEach((track)=>{
this._senders.push(shimSenderWithDtmf(this, track));
});
};
const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
this._senders = this._senders || [];
origRemoveStream.apply(this, [
stream
]);
stream.getTracks().forEach((track)=>{
const sender = this._senders.find((s)=>s.track === track);
if (sender) this._senders.splice(this._senders.indexOf(sender), 1);
});
};
} else if (typeof window === "object" && window.RTCPeerConnection && "getSenders" in window.RTCPeerConnection.prototype && "createDTMFSender" in window.RTCPeerConnection.prototype && window.RTCRtpSender && !("dtmf" in window.RTCRtpSender.prototype)) {
const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
const senders = origGetSenders.apply(this, []);
senders.forEach((sender)=>sender._pc = this);
return senders;
};
Object.defineProperty(window.RTCRtpSender.prototype, "dtmf", {
get () {
if (this._dtmf === undefined) {
if (this.track.kind === "audio") this._dtmf = this._pc.createDTMFSender(this.track);
else this._dtmf = null;
}
return this._dtmf;
}
});
}
}
function $fb04e59b477f17ce$export$f2f0f2338114eb4b(window) {
if (!(typeof window === "object" && window.RTCPeerConnection && window.RTCRtpSender && window.RTCRtpReceiver)) return;
// shim sender stats.
if (!("getStats" in window.RTCRtpSender.prototype)) {
const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
if (origGetSenders) window.RTCPeerConnection.prototype.getSenders = function getSenders() {
const senders = origGetSenders.apply(this, []);
senders.forEach((sender)=>sender._pc = this);
return senders;
};
const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
if (origAddTrack) window.RTCPeerConnection.prototype.addTrack = function addTrack() {
const sender = origAddTrack.apply(this, arguments);
sender._pc = this;
return sender;
};
window.RTCRtpSender.prototype.getStats = function getStats() {
const sender = this;
return this._pc.getStats().then((result)=>/* Note: this will include stats of all senders that
* send a track with the same id as sender.track as
* it is not possible to identify the RTCRtpSender.
*/ $9fea4db837311579$export$93439ffc3f787d51(result, sender.track, true));
};
}
// shim receiver stats.
if (!("getStats" in window.RTCRtpReceiver.prototype)) {
const origGetReceivers = window.RTCPeerConnection.prototype.getReceivers;
if (origGetReceivers) window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
const receivers = origGetReceivers.apply(this, []);
receivers.forEach((receiver)=>receiver._pc = this);
return receivers;
};
$9fea4db837311579$export$1f48841962b828b1(window, "track", (e)=>{
e.receiver._pc = e.srcElement;
return e;
});
window.RTCRtpReceiver.prototype.getStats = function getStats() {
const receiver = this;
return this._pc.getStats().then((result)=>$9fea4db837311579$export$93439ffc3f787d51(result, receiver.track, false));
};
}
if (!("getStats" in window.RTCRtpSender.prototype && "getStats" in window.RTCRtpReceiver.prototype)) return;
// shim RTCPeerConnection.getStats(track).
const origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function getStats() {
if (arguments.length > 0 && arguments[0] instanceof window.MediaStreamTrack) {
const track = arguments[0];
let sender;
let receiver;
let err;
this.getSenders().forEach((s)=>{
if (s.track === track) {
if (sender) err = true;
else sender = s;
}
});
this.getReceivers().forEach((r)=>{
if (r.track === track) {
if (receiver) err = true;
else receiver = r;
}
return r.track === track;
});
if (err || sender && receiver) return Promise.reject(new DOMException("There are more than one sender or receiver for the track.", "InvalidAccessError"));
else if (sender) return sender.getStats();
else if (receiver) return receiver.getStats();
return Promise.reject(new DOMException("There is no sender or receiver for the track.", "InvalidAccessError"));
}
return origGetStats.apply(this, arguments);
};
}
function $fb04e59b477f17ce$export$30e3cdd46f8d5100(window) {
// shim addTrack/removeTrack with native variants in order to make
// the interactions with legacy getLocalStreams behave as in other browsers.
// Keeps a mapping stream.id => [stream, rtpsenders...]
window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
return Object.keys(this._shimmedLocalStreams).map((streamId)=>this._shimmedLocalStreams[streamId][0]);
};
const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
if (!stream) return origAddTrack.apply(this, arguments);
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
const sender = origAddTrack.apply(this, arguments);
if (!this._shimmedLocalStreams[stream.id]) this._shimmedLocalStreams[stream.id] = [
stream,
sender
];
else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) this._shimmedLocalStreams[stream.id].push(sender);
return sender;
};
const origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
stream.getTracks().forEach((track)=>{
const alreadyExists = this.getSenders().find((s)=>s.track === track);
if (alreadyExists) throw new DOMException("Track already exists.", "InvalidAccessError");
});
const existingSenders = this.getSenders();
origAddStream.apply(this, arguments);
const newSenders = this.getSenders().filter((newSender)=>existingSenders.indexOf(newSender) === -1);
this._shimmedLocalStreams[stream.id] = [
stream
].concat(newSenders);
};
const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
delete this._shimmedLocalStreams[stream.id];
return origRemoveStream.apply(this, arguments);
};
const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};