@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
1,365 lines • 629 kB
JavaScript
import { PlaneGeometry as gc, ShaderChunk as Kl, Object3D as vc, Layers as Br, MeshBasicMaterial as sa, DoubleSide as Xs, AdditiveBlending as Sc, InstancedBufferAttribute as mn, DynamicDrawUsage as ee, InstancedBufferGeometry as Ql, Uniform$1 as Re, ShaderMaterial as Ys, BufferGeometry as yi, BufferAttribute as he, Mesh as Zr, MeshStandardMaterial as tu, MeshPhysicalMaterial as eu, Triangle as Mn, Vector3 as H, Box3 as Le, Matrix4 as Oe, Line3 as tn, Plane as xc, Vector2 as hn, BackSide as nu, REVISION as _c, Ray as iu, FrontSide as oa, LineSegments as bc, LineLoop as Tc, Line as Cc, Points as Mc, Sphere as ru, BatchedMesh as su, Matrix3 as ou, Vector4 as To, SkinnedMesh as au, InterpolateDiscrete as cu, InterpolateLinear as wc, AnimationClip as lu, QuaternionKeyframeTrack as uu, ColorKeyframeTrack as hu, VectorKeyframeTrack as fu, BooleanKeyframeTrack as du, NumberKeyframeTrack as pu, PropertyBinding as aa } from "./three.js";
const It = {
ComponentState: Object.freeze({
DEFAULT: "default",
TOUCHED: "touched",
PRESSED: "pressed"
}),
ComponentProperty: Object.freeze({
BUTTON: "button",
X_AXIS: "xAxis",
Y_AXIS: "yAxis",
STATE: "state"
}),
ButtonTouchThreshold: 0.05,
AxisTouchThreshold: 0.1,
VisualResponseProperty: Object.freeze({
TRANSFORM: "transform",
VISIBILITY: "visibility"
})
};
async function Pc(r) {
const t = await fetch(r);
if (t.ok)
return t.json();
throw new Error(t.statusText);
}
async function mu(r) {
return await Pc(`${r}/profilesList.json`);
}
async function Ud(r, t, e = null, n = !0) {
if (!r)
throw new Error("No xrInputSource supplied");
const i = await mu(t);
let s;
if (r.profiles.some((c) => {
const l = i[c];
return l && (s = {
profileId: c,
profilePath: `${t}/${l.path}`,
deprecated: !!l.deprecated
}), !!s;
}), !s) {
if (!e)
throw new Error("No matching profile name found");
const c = i[e];
if (!c)
throw new Error(`No matching profile name found and default profile "${e}" missing.`);
s = {
profileId: e,
profilePath: `${t}/${c.path}`,
deprecated: !!c.deprecated
};
}
const a = await Pc(s.profilePath);
let o;
if (n) {
let c;
if (r.handedness === "any" ? c = a.layouts[Object.keys(a.layouts)[0]] : c = a.layouts[r.handedness], !c)
throw new Error(
`No matching handedness, ${r.handedness}, in profile ${s.profileId}`
);
c.assetPath && (o = s.profilePath.replace("profile.json", c.assetPath));
}
return { profile: a, assetPath: o };
}
const yu = {
xAxis: 0,
yAxis: 0,
button: 0,
state: It.ComponentState.DEFAULT
};
function gu(r = 0, t = 0) {
let e = r, n = t;
if (Math.sqrt(r * r + t * t) > 1) {
const a = Math.atan2(t, r);
e = Math.cos(a), n = Math.sin(a);
}
return {
normalizedXAxis: e * 0.5 + 0.5,
normalizedYAxis: n * 0.5 + 0.5
};
}
class vu {
constructor(t) {
this.componentProperty = t.componentProperty, this.states = t.states, this.valueNodeName = t.valueNodeName, this.valueNodeProperty = t.valueNodeProperty, this.valueNodeProperty === It.VisualResponseProperty.TRANSFORM && (this.minNodeName = t.minNodeName, this.maxNodeName = t.maxNodeName), this.value = 0, this.updateFromComponent(yu);
}
/**
* Computes the visual response's interpolation weight based on component state
* @param {Object} componentValues - The component from which to update
* @param {number} xAxis - The reported X axis value of the component
* @param {number} yAxis - The reported Y axis value of the component
* @param {number} button - The reported value of the component's button
* @param {string} state - The component's active state
*/
updateFromComponent({
xAxis: t,
yAxis: e,
button: n,
state: i
}) {
const { normalizedXAxis: s, normalizedYAxis: a } = gu(t, e);
switch (this.componentProperty) {
case It.ComponentProperty.X_AXIS:
this.value = this.states.includes(i) ? s : 0.5;
break;
case It.ComponentProperty.Y_AXIS:
this.value = this.states.includes(i) ? a : 0.5;
break;
case It.ComponentProperty.BUTTON:
this.value = this.states.includes(i) ? n : 0;
break;
case It.ComponentProperty.STATE:
this.valueNodeProperty === It.VisualResponseProperty.VISIBILITY ? this.value = this.states.includes(i) : this.value = this.states.includes(i) ? 1 : 0;
break;
default:
throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`);
}
}
}
class Su {
/**
* @param {Object} componentId - Id of the component
* @param {Object} componentDescription - Description of the component to be created
*/
constructor(t, e) {
if (!t || !e || !e.visualResponses || !e.gamepadIndices || Object.keys(e.gamepadIndices).length === 0)
throw new Error("Invalid arguments supplied");
this.id = t, this.type = e.type, this.rootNodeName = e.rootNodeName, this.touchPointNodeName = e.touchPointNodeName, this.visualResponses = {}, Object.keys(e.visualResponses).forEach((n) => {
const i = new vu(e.visualResponses[n]);
this.visualResponses[n] = i;
}), this.gamepadIndices = Object.assign({}, e.gamepadIndices), this.values = {
state: It.ComponentState.DEFAULT,
button: this.gamepadIndices.button !== void 0 ? 0 : void 0,
xAxis: this.gamepadIndices.xAxis !== void 0 ? 0 : void 0,
yAxis: this.gamepadIndices.yAxis !== void 0 ? 0 : void 0
};
}
get data() {
return { id: this.id, ...this.values };
}
/**
* @description Poll for updated data based on current gamepad state
* @param {Object} gamepad - The gamepad object from which the component data should be polled
*/
updateFromGamepad(t) {
if (this.values.state = It.ComponentState.DEFAULT, this.gamepadIndices.button !== void 0 && t.buttons.length > this.gamepadIndices.button) {
const e = t.buttons[this.gamepadIndices.button];
this.values.button = e.value, this.values.button = this.values.button < 0 ? 0 : this.values.button, this.values.button = this.values.button > 1 ? 1 : this.values.button, e.pressed || this.values.button === 1 ? this.values.state = It.ComponentState.PRESSED : (e.touched || this.values.button > It.ButtonTouchThreshold) && (this.values.state = It.ComponentState.TOUCHED);
}
this.gamepadIndices.xAxis !== void 0 && t.axes.length > this.gamepadIndices.xAxis && (this.values.xAxis = t.axes[this.gamepadIndices.xAxis], this.values.xAxis = this.values.xAxis < -1 ? -1 : this.values.xAxis, this.values.xAxis = this.values.xAxis > 1 ? 1 : this.values.xAxis, this.values.state === It.ComponentState.DEFAULT && Math.abs(this.values.xAxis) > It.AxisTouchThreshold && (this.values.state = It.ComponentState.TOUCHED)), this.gamepadIndices.yAxis !== void 0 && t.axes.length > this.gamepadIndices.yAxis && (this.values.yAxis = t.axes[this.gamepadIndices.yAxis], this.values.yAxis = this.values.yAxis < -1 ? -1 : this.values.yAxis, this.values.yAxis = this.values.yAxis > 1 ? 1 : this.values.yAxis, this.values.state === It.ComponentState.DEFAULT && Math.abs(this.values.yAxis) > It.AxisTouchThreshold && (this.values.state = It.ComponentState.TOUCHED)), Object.values(this.visualResponses).forEach((e) => {
e.updateFromComponent(this.values);
});
}
}
class Dd {
/**
* @param {Object} xrInputSource - The XRInputSource to build the MotionController around
* @param {Object} profile - The best matched profile description for the supplied xrInputSource
* @param {Object} assetUrl
*/
constructor(t, e, n) {
if (!t)
throw new Error("No xrInputSource supplied");
if (!e)
throw new Error("No profile supplied");
this.xrInputSource = t, this.assetUrl = n, this.id = e.profileId, this.layoutDescription = e.layouts[t.handedness], this.components = {}, Object.keys(this.layoutDescription.components).forEach((i) => {
const s = this.layoutDescription.components[i];
this.components[i] = new Su(i, s);
}), this.updateFromGamepad();
}
get gripSpace() {
return this.xrInputSource.gripSpace;
}
get targetRaySpace() {
return this.xrInputSource.targetRaySpace;
}
/**
* @description Returns a subset of component data for simplified debugging
*/
get data() {
const t = [];
return Object.values(this.components).forEach((e) => {
t.push(e.data);
}), t;
}
/**
* @description Poll for updated data based on current gamepad state
*/
updateFromGamepad() {
Object.values(this.components).forEach((t) => {
t.updateFromGamepad(this.xrInputSource.gamepad);
});
}
}
const vs = 2, Ue = 4, Ze = 4, xu = 4, an = new Int32Array(2), ca = new Float32Array(an.buffer), la = new Float64Array(an.buffer), cr = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
class Qe {
constructor(t, e) {
this.low = t | 0, this.high = e | 0;
}
static create(t, e) {
return t == 0 && e == 0 ? Qe.ZERO : new Qe(t, e);
}
toFloat64() {
return (this.low >>> 0) + this.high * 4294967296;
}
equals(t) {
return this.low == t.low && this.high == t.high;
}
}
Qe.ZERO = new Qe(0, 0);
var Zs;
(function(r) {
r[r.UTF8_BYTES = 1] = "UTF8_BYTES", r[r.UTF16_STRING = 2] = "UTF16_STRING";
})(Zs || (Zs = {}));
class Jr {
/**
* Create a new ByteBuffer with a given array of bytes (`Uint8Array`)
*/
constructor(t) {
this.bytes_ = t, this.position_ = 0;
}
/**
* Create and allocate a new ByteBuffer with a given size.
*/
static allocate(t) {
return new Jr(new Uint8Array(t));
}
clear() {
this.position_ = 0;
}
/**
* Get the underlying `Uint8Array`.
*/
bytes() {
return this.bytes_;
}
/**
* Get the buffer's position.
*/
position() {
return this.position_;
}
/**
* Set the buffer's position.
*/
setPosition(t) {
this.position_ = t;
}
/**
* Get the buffer's capacity.
*/
capacity() {
return this.bytes_.length;
}
readInt8(t) {
return this.readUint8(t) << 24 >> 24;
}
readUint8(t) {
return this.bytes_[t];
}
readInt16(t) {
return this.readUint16(t) << 16 >> 16;
}
readUint16(t) {
return this.bytes_[t] | this.bytes_[t + 1] << 8;
}
readInt32(t) {
return this.bytes_[t] | this.bytes_[t + 1] << 8 | this.bytes_[t + 2] << 16 | this.bytes_[t + 3] << 24;
}
readUint32(t) {
return this.readInt32(t) >>> 0;
}
readInt64(t) {
return new Qe(this.readInt32(t), this.readInt32(t + 4));
}
readUint64(t) {
return new Qe(this.readUint32(t), this.readUint32(t + 4));
}
readFloat32(t) {
return an[0] = this.readInt32(t), ca[0];
}
readFloat64(t) {
return an[cr ? 0 : 1] = this.readInt32(t), an[cr ? 1 : 0] = this.readInt32(t + 4), la[0];
}
writeInt8(t, e) {
this.bytes_[t] = e;
}
writeUint8(t, e) {
this.bytes_[t] = e;
}
writeInt16(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8;
}
writeUint16(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8;
}
writeInt32(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8, this.bytes_[t + 2] = e >> 16, this.bytes_[t + 3] = e >> 24;
}
writeUint32(t, e) {
this.bytes_[t] = e, this.bytes_[t + 1] = e >> 8, this.bytes_[t + 2] = e >> 16, this.bytes_[t + 3] = e >> 24;
}
writeInt64(t, e) {
this.writeInt32(t, e.low), this.writeInt32(t + 4, e.high);
}
writeUint64(t, e) {
this.writeUint32(t, e.low), this.writeUint32(t + 4, e.high);
}
writeFloat32(t, e) {
ca[0] = e, this.writeInt32(t, an[0]);
}
writeFloat64(t, e) {
la[0] = e, this.writeInt32(t, an[cr ? 0 : 1]), this.writeInt32(t + 4, an[cr ? 1 : 0]);
}
/**
* Return the file identifier. Behavior is undefined for FlatBuffers whose
* schema does not include a file_identifier (likely points at padding or the
* start of a the root vtable).
*/
getBufferIdentifier() {
if (this.bytes_.length < this.position_ + Ue + Ze)
throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");
let t = "";
for (let e = 0; e < Ze; e++)
t += String.fromCharCode(this.readInt8(this.position_ + Ue + e));
return t;
}
/**
* Look up a field in the vtable, return an offset into the object, or 0 if the
* field is not present.
*/
__offset(t, e) {
const n = t - this.readInt32(t);
return e < this.readInt16(n) ? this.readInt16(n + e) : 0;
}
/**
* Initialize any Table-derived type to point to the union at the given offset.
*/
__union(t, e) {
return t.bb_pos = e + this.readInt32(e), t.bb = this, t;
}
/**
* Create a JavaScript string from UTF-8 data stored inside the FlatBuffer.
* This allocates a new string and converts to wide chars upon each access.
*
* To avoid the conversion to UTF-16, pass Encoding.UTF8_BYTES as
* the "optionalEncoding" argument. This is useful for avoiding conversion to
* and from UTF-16 when the data will just be packaged back up in another
* FlatBuffer later on.
*
* @param offset
* @param opt_encoding Defaults to UTF16_STRING
*/
__string(t, e) {
t += this.readInt32(t);
const n = this.readInt32(t);
let i = "", s = 0;
if (t += Ue, e === Zs.UTF8_BYTES)
return this.bytes_.subarray(t, t + n);
for (; s < n; ) {
let a;
const o = this.readUint8(t + s++);
if (o < 192)
a = o;
else {
const c = this.readUint8(t + s++);
if (o < 224)
a = (o & 31) << 6 | c & 63;
else {
const l = this.readUint8(t + s++);
if (o < 240)
a = (o & 15) << 12 | (c & 63) << 6 | l & 63;
else {
const u = this.readUint8(t + s++);
a = (o & 7) << 18 | (c & 63) << 12 | (l & 63) << 6 | u & 63;
}
}
}
a < 65536 ? i += String.fromCharCode(a) : (a -= 65536, i += String.fromCharCode((a >> 10) + 55296, (a & 1023) + 56320));
}
return i;
}
/**
* Handle unions that can contain string as its member, if a Table-derived type then initialize it,
* if a string then return a new one
*
* WARNING: strings are immutable in JS so we can't change the string that the user gave us, this
* makes the behaviour of __union_with_string different compared to __union
*/
__union_with_string(t, e) {
return typeof t == "string" ? this.__string(e) : this.__union(t, e);
}
/**
* Retrieve the relative offset stored at "offset"
*/
__indirect(t) {
return t + this.readInt32(t);
}
/**
* Get the start of data of a vector whose offset is stored at "offset" in this object.
*/
__vector(t) {
return t + this.readInt32(t) + Ue;
}
/**
* Get the length of a vector whose offset is stored at "offset" in this object.
*/
__vector_len(t) {
return this.readInt32(t + this.readInt32(t));
}
__has_identifier(t) {
if (t.length != Ze)
throw new Error("FlatBuffers: file identifier must be length " + Ze);
for (let e = 0; e < Ze; e++)
if (t.charCodeAt(e) != this.readInt8(this.position() + Ue + e))
return !1;
return !0;
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return Qe.create(t, e);
}
/**
* A helper function for generating list for obj api
*/
createScalarList(t, e) {
const n = [];
for (let i = 0; i < e; ++i)
t(i) !== null && n.push(t(i));
return n;
}
/**
* A helper function for generating list for obj api
* @param listAccessor function that accepts an index and return data at that index
* @param listLength listLength
* @param res result list
*/
createObjList(t, e) {
const n = [];
for (let i = 0; i < e; ++i) {
const s = t(i);
s !== null && n.push(s.unpack());
}
return n;
}
}
class Ec {
/**
* Create a FlatBufferBuilder.
*/
constructor(t) {
this.minalign = 1, this.vtable = null, this.vtable_in_use = 0, this.isNested = !1, this.object_start = 0, this.vtables = [], this.vector_num_elems = 0, this.force_defaults = !1, this.string_maps = null;
let e;
t ? e = t : e = 1024, this.bb = Jr.allocate(e), this.space = e;
}
clear() {
this.bb.clear(), this.space = this.bb.capacity(), this.minalign = 1, this.vtable = null, this.vtable_in_use = 0, this.isNested = !1, this.object_start = 0, this.vtables = [], this.vector_num_elems = 0, this.force_defaults = !1, this.string_maps = null;
}
/**
* In order to save space, fields that are set to their default value
* don't get serialized into the buffer. Forcing defaults provides a
* way to manually disable this optimization.
*
* @param forceDefaults true always serializes default values
*/
forceDefaults(t) {
this.force_defaults = t;
}
/**
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
* called finish(). The actual data starts at the ByteBuffer's current position,
* not necessarily at 0.
*/
dataBuffer() {
return this.bb;
}
/**
* Get the bytes representing the FlatBuffer. Only call this after you've
* called finish().
*/
asUint8Array() {
return this.bb.bytes().subarray(this.bb.position(), this.bb.position() + this.offset());
}
/**
* Prepare to write an element of `size` after `additional_bytes` have been
* written, e.g. if you write a string, you need to align such the int length
* field is aligned to 4 bytes, and the string data follows it directly. If all
* you need to do is alignment, `additional_bytes` will be 0.
*
* @param size This is the of the new element to write
* @param additional_bytes The padding size
*/
prep(t, e) {
t > this.minalign && (this.minalign = t);
const n = ~(this.bb.capacity() - this.space + e) + 1 & t - 1;
for (; this.space < n + t + e; ) {
const i = this.bb.capacity();
this.bb = Ec.growByteBuffer(this.bb), this.space += this.bb.capacity() - i;
}
this.pad(n);
}
pad(t) {
for (let e = 0; e < t; e++)
this.bb.writeInt8(--this.space, 0);
}
writeInt8(t) {
this.bb.writeInt8(this.space -= 1, t);
}
writeInt16(t) {
this.bb.writeInt16(this.space -= 2, t);
}
writeInt32(t) {
this.bb.writeInt32(this.space -= 4, t);
}
writeInt64(t) {
this.bb.writeInt64(this.space -= 8, t);
}
writeFloat32(t) {
this.bb.writeFloat32(this.space -= 4, t);
}
writeFloat64(t) {
this.bb.writeFloat64(this.space -= 8, t);
}
/**
* Add an `int8` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int8` to add the the buffer.
*/
addInt8(t) {
this.prep(1, 0), this.writeInt8(t);
}
/**
* Add an `int16` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int16` to add the the buffer.
*/
addInt16(t) {
this.prep(2, 0), this.writeInt16(t);
}
/**
* Add an `int32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int32` to add the the buffer.
*/
addInt32(t) {
this.prep(4, 0), this.writeInt32(t);
}
/**
* Add an `int64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `int64` to add the the buffer.
*/
addInt64(t) {
this.prep(8, 0), this.writeInt64(t);
}
/**
* Add a `float32` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float32` to add the the buffer.
*/
addFloat32(t) {
this.prep(4, 0), this.writeFloat32(t);
}
/**
* Add a `float64` to the buffer, properly aligned, and grows the buffer (if necessary).
* @param value The `float64` to add the the buffer.
*/
addFloat64(t) {
this.prep(8, 0), this.writeFloat64(t);
}
addFieldInt8(t, e, n) {
(this.force_defaults || e != n) && (this.addInt8(e), this.slot(t));
}
addFieldInt16(t, e, n) {
(this.force_defaults || e != n) && (this.addInt16(e), this.slot(t));
}
addFieldInt32(t, e, n) {
(this.force_defaults || e != n) && (this.addInt32(e), this.slot(t));
}
addFieldInt64(t, e, n) {
(this.force_defaults || !e.equals(n)) && (this.addInt64(e), this.slot(t));
}
addFieldFloat32(t, e, n) {
(this.force_defaults || e != n) && (this.addFloat32(e), this.slot(t));
}
addFieldFloat64(t, e, n) {
(this.force_defaults || e != n) && (this.addFloat64(e), this.slot(t));
}
addFieldOffset(t, e, n) {
(this.force_defaults || e != n) && (this.addOffset(e), this.slot(t));
}
/**
* Structs are stored inline, so nothing additional is being added. `d` is always 0.
*/
addFieldStruct(t, e, n) {
e != n && (this.nested(e), this.slot(t));
}
/**
* Structures are always stored inline, they need to be created right
* where they're used. You'll get this assertion failure if you
* created it elsewhere.
*/
nested(t) {
if (t != this.offset())
throw new Error("FlatBuffers: struct must be serialized inline.");
}
/**
* Should not be creating any other object, string or vector
* while an object is being constructed
*/
notNested() {
if (this.isNested)
throw new Error("FlatBuffers: object serialization must not be nested.");
}
/**
* Set the current vtable at `voffset` to the current location in the buffer.
*/
slot(t) {
this.vtable !== null && (this.vtable[t] = this.offset());
}
/**
* @returns Offset relative to the end of the buffer.
*/
offset() {
return this.bb.capacity() - this.space;
}
/**
* Doubles the size of the backing ByteBuffer and copies the old data towards
* the end of the new buffer (since we build the buffer backwards).
*
* @param bb The current buffer with the existing data
* @returns A new byte buffer with the old data copied
* to it. The data is located at the end of the buffer.
*
* uint8Array.set() formally takes {Array<number>|ArrayBufferView}, so to pass
* it a uint8Array we need to suppress the type check:
* @suppress {checkTypes}
*/
static growByteBuffer(t) {
const e = t.capacity();
if (e & 3221225472)
throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");
const n = e << 1, i = Jr.allocate(n);
return i.setPosition(n - e), i.bytes().set(t.bytes(), n - e), i;
}
/**
* Adds on offset, relative to where it will be written.
*
* @param offset The offset to add.
*/
addOffset(t) {
this.prep(Ue, 0), this.writeInt32(this.offset() - t + Ue);
}
/**
* Start encoding a new object in the buffer. Users will not usually need to
* call this directly. The FlatBuffers compiler will generate helper methods
* that call this method internally.
*/
startObject(t) {
this.notNested(), this.vtable == null && (this.vtable = []), this.vtable_in_use = t;
for (let e = 0; e < t; e++)
this.vtable[e] = 0;
this.isNested = !0, this.object_start = this.offset();
}
/**
* Finish off writing the object that is under construction.
*
* @returns The offset to the object inside `dataBuffer`
*/
endObject() {
if (this.vtable == null || !this.isNested)
throw new Error("FlatBuffers: endObject called without startObject");
this.addInt32(0);
const t = this.offset();
let e = this.vtable_in_use - 1;
for (; e >= 0 && this.vtable[e] == 0; e--)
;
const n = e + 1;
for (; e >= 0; e--)
this.addInt16(this.vtable[e] != 0 ? t - this.vtable[e] : 0);
const i = 2;
this.addInt16(t - this.object_start);
const s = (n + i) * vs;
this.addInt16(s);
let a = 0;
const o = this.space;
t: for (e = 0; e < this.vtables.length; e++) {
const c = this.bb.capacity() - this.vtables[e];
if (s == this.bb.readInt16(c)) {
for (let l = vs; l < s; l += vs)
if (this.bb.readInt16(o + l) != this.bb.readInt16(c + l))
continue t;
a = this.vtables[e];
break;
}
}
return a ? (this.space = this.bb.capacity() - t, this.bb.writeInt32(this.space, a - t)) : (this.vtables.push(this.offset()), this.bb.writeInt32(this.bb.capacity() - t, this.offset() - t)), this.isNested = !1, t;
}
/**
* Finalize a buffer, poiting to the given `root_table`.
*/
finish(t, e, n) {
const i = n ? xu : 0;
if (e) {
const s = e;
if (this.prep(this.minalign, Ue + Ze + i), s.length != Ze)
throw new Error("FlatBuffers: file identifier must be length " + Ze);
for (let a = Ze - 1; a >= 0; a--)
this.writeInt8(s.charCodeAt(a));
}
this.prep(this.minalign, Ue + i), this.addOffset(t), i && this.addInt32(this.bb.capacity() - this.space), this.bb.setPosition(this.space);
}
/**
* Finalize a size prefixed buffer, pointing to the given `root_table`.
*/
finishSizePrefixed(t, e) {
this.finish(t, e, !0);
}
/**
* This checks a required field has been set in a given table that has
* just been constructed.
*/
requiredField(t, e) {
const n = this.bb.capacity() - t, i = n - this.bb.readInt32(n);
if (!(this.bb.readInt16(i + e) != 0))
throw new Error("FlatBuffers: field " + e + " must be set");
}
/**
* Start a new array/vector of objects. Users usually will not call
* this directly. The FlatBuffers compiler will create a start/end
* method for vector types in generated code.
*
* @param elem_size The size of each element in the array
* @param num_elems The number of elements in the array
* @param alignment The alignment of the array
*/
startVector(t, e, n) {
this.notNested(), this.vector_num_elems = e, this.prep(Ue, t * e), this.prep(n, t * e);
}
/**
* Finish off the creation of an array and all its elements. The array must be
* created with `startVector`.
*
* @returns The offset at which the newly created array
* starts.
*/
endVector() {
return this.writeInt32(this.vector_num_elems), this.offset();
}
/**
* Encode the string `s` in the buffer using UTF-8. If the string passed has
* already been seen, we return the offset of the already written string
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createSharedString(t) {
if (!t)
return 0;
if (this.string_maps || (this.string_maps = /* @__PURE__ */ new Map()), this.string_maps.has(t))
return this.string_maps.get(t);
const e = this.createString(t);
return this.string_maps.set(t, e), e;
}
/**
* Encode the string `s` in the buffer using UTF-8. If a Uint8Array is passed
* instead of a string, it is assumed to contain valid UTF-8 encoded data.
*
* @param s The string to encode
* @return The offset in the buffer where the encoded string starts
*/
createString(t) {
if (!t)
return 0;
let e;
if (t instanceof Uint8Array)
e = t;
else {
e = [];
let n = 0;
for (; n < t.length; ) {
let i;
const s = t.charCodeAt(n++);
if (s < 55296 || s >= 56320)
i = s;
else {
const a = t.charCodeAt(n++);
i = (s << 10) + a + -56613888;
}
i < 128 ? e.push(i) : (i < 2048 ? e.push(i >> 6 & 31 | 192) : (i < 65536 ? e.push(i >> 12 & 15 | 224) : e.push(i >> 18 & 7 | 240, i >> 12 & 63 | 128), e.push(i >> 6 & 63 | 128)), e.push(i & 63 | 128));
}
}
this.addInt8(0), this.startVector(1, e.length, 1), this.bb.setPosition(this.space -= e.length);
for (let n = 0, i = this.space, s = this.bb.bytes(); n < e.length; n++)
s[i++] = e[n];
return this.endVector();
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return Qe.create(t, e);
}
/**
* A helper function to pack an object
*
* @returns offset of obj
*/
createObjectOffset(t) {
return t === null ? 0 : typeof t == "string" ? this.createString(t) : t.pack(this);
}
/**
* A helper function to pack a list of object
*
* @returns list of offsets of each non null object
*/
createObjectOffsetList(t) {
const e = [];
for (let n = 0; n < t.length; ++n) {
const i = t[n];
if (i !== null)
e.push(this.createObjectOffset(i));
else
throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.");
}
return e;
}
createStructOffsetList(t, e) {
return e(this, t.length), this.createObjectOffsetList(t), this.endVector();
}
}
function Kr(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
}
var Ss = { exports: {} }, ua;
function ha() {
return ua || (ua = 1, (function(r) {
var t = {};
t.useBlobBuilder = (function() {
try {
return new Blob([]), !1;
} catch {
return !0;
}
})(), t.useArrayBufferView = !t.useBlobBuilder && (function() {
try {
return new Blob([new Uint8Array([])]).size === 0;
} catch {
return !0;
}
})(), r.exports.binaryFeatures = t;
var e = r.exports.BlobBuilder;
typeof window < "u" && (e = r.exports.BlobBuilder = window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder || window.BlobBuilder);
function n() {
this._pieces = [], this._parts = [];
}
n.prototype.append = function(i) {
typeof i == "number" ? this._pieces.push(i) : (this.flush(), this._parts.push(i));
}, n.prototype.flush = function() {
if (this._pieces.length > 0) {
var i = new Uint8Array(this._pieces);
t.useArrayBufferView || (i = i.buffer), this._parts.push(i), this._pieces = [];
}
}, n.prototype.getBuffer = function() {
if (this.flush(), t.useBlobBuilder) {
for (var i = new e(), s = 0, a = this._parts.length; s < a; s++)
i.append(this._parts[s]);
return i.getBlob();
} else
return new Blob(this._parts);
}, r.exports.BufferBuilder = n;
})(Ss)), Ss.exports;
}
var xs, fa;
function _u() {
if (fa) return xs;
fa = 1;
var r = ha().BufferBuilder, t = ha().binaryFeatures, e = {
unpack: function(o) {
var c = new n(o);
return c.unpack();
},
pack: function(o) {
var c = new i();
c.pack(o);
var l = c.getBuffer();
return l;
}
};
xs = e;
function n(o) {
this.index = 0, this.dataBuffer = o, this.dataView = new Uint8Array(this.dataBuffer), this.length = this.dataBuffer.byteLength;
}
n.prototype.unpack = function() {
var o = this.unpack_uint8();
if (o < 128)
return o;
if ((o ^ 224) < 32)
return (o ^ 224) - 32;
var c;
if ((c = o ^ 160) <= 15)
return this.unpack_raw(c);
if ((c = o ^ 176) <= 15)
return this.unpack_string(c);
if ((c = o ^ 144) <= 15)
return this.unpack_array(c);
if ((c = o ^ 128) <= 15)
return this.unpack_map(c);
switch (o) {
case 192:
return null;
case 193:
return;
case 194:
return !1;
case 195:
return !0;
case 202:
return this.unpack_float();
case 203:
return this.unpack_double();
case 204:
return this.unpack_uint8();
case 205:
return this.unpack_uint16();
case 206:
return this.unpack_uint32();
case 207:
return this.unpack_uint64();
case 208:
return this.unpack_int8();
case 209:
return this.unpack_int16();
case 210:
return this.unpack_int32();
case 211:
return this.unpack_int64();
case 212:
return;
case 213:
return;
case 214:
return;
case 215:
return;
case 216:
return c = this.unpack_uint16(), this.unpack_string(c);
case 217:
return c = this.unpack_uint32(), this.unpack_string(c);
case 218:
return c = this.unpack_uint16(), this.unpack_raw(c);
case 219:
return c = this.unpack_uint32(), this.unpack_raw(c);
case 220:
return c = this.unpack_uint16(), this.unpack_array(c);
case 221:
return c = this.unpack_uint32(), this.unpack_array(c);
case 222:
return c = this.unpack_uint16(), this.unpack_map(c);
case 223:
return c = this.unpack_uint32(), this.unpack_map(c);
}
}, n.prototype.unpack_uint8 = function() {
var o = this.dataView[this.index] & 255;
return this.index++, o;
}, n.prototype.unpack_uint16 = function() {
var o = this.read(2), c = (o[0] & 255) * 256 + (o[1] & 255);
return this.index += 2, c;
}, n.prototype.unpack_uint32 = function() {
var o = this.read(4), c = ((o[0] * 256 + o[1]) * 256 + o[2]) * 256 + o[3];
return this.index += 4, c;
}, n.prototype.unpack_uint64 = function() {
var o = this.read(8), c = ((((((o[0] * 256 + o[1]) * 256 + o[2]) * 256 + o[3]) * 256 + o[4]) * 256 + o[5]) * 256 + o[6]) * 256 + o[7];
return this.index += 8, c;
}, n.prototype.unpack_int8 = function() {
var o = this.unpack_uint8();
return o < 128 ? o : o - 256;
}, n.prototype.unpack_int16 = function() {
var o = this.unpack_uint16();
return o < 32768 ? o : o - 65536;
}, n.prototype.unpack_int32 = function() {
var o = this.unpack_uint32();
return o < Math.pow(2, 31) ? o : o - Math.pow(2, 32);
}, n.prototype.unpack_int64 = function() {
var o = this.unpack_uint64();
return o < Math.pow(2, 63) ? o : o - Math.pow(2, 64);
}, n.prototype.unpack_raw = function(o) {
if (this.length < this.index + o)
throw new Error("BinaryPackFailure: index is out of range " + this.index + " " + o + " " + this.length);
var c = this.dataBuffer.slice(this.index, this.index + o);
return this.index += o, c;
}, n.prototype.unpack_string = function(o) {
for (var c = this.read(o), l = 0, u = "", f, p; l < o; )
f = c[l], f < 128 ? (u += String.fromCharCode(f), l++) : (f ^ 192) < 32 ? (p = (f ^ 192) << 6 | c[l + 1] & 63, u += String.fromCharCode(p), l += 2) : (p = (f & 15) << 12 | (c[l + 1] & 63) << 6 | c[l + 2] & 63, u += String.fromCharCode(p), l += 3);
return this.index += o, u;
}, n.prototype.unpack_array = function(o) {
for (var c = new Array(o), l = 0; l < o; l++)
c[l] = this.unpack();
return c;
}, n.prototype.unpack_map = function(o) {
for (var c = {}, l = 0; l < o; l++) {
var u = this.unpack(), f = this.unpack();
c[u] = f;
}
return c;
}, n.prototype.unpack_float = function() {
var o = this.unpack_uint32(), c = o >> 31, l = (o >> 23 & 255) - 127, u = o & 8388607 | 8388608;
return (c === 0 ? 1 : -1) * u * Math.pow(2, l - 23);
}, n.prototype.unpack_double = function() {
var o = this.unpack_uint32(), c = this.unpack_uint32(), l = o >> 31, u = (o >> 20 & 2047) - 1023, f = o & 1048575 | 1048576, p = f * Math.pow(2, u - 20) + c * Math.pow(2, u - 52);
return (l === 0 ? 1 : -1) * p;
}, n.prototype.read = function(o) {
var c = this.index;
if (c + o <= this.length)
return this.dataView.subarray(c, c + o);
throw new Error("BinaryPackFailure: read index out of range");
};
function i() {
this.bufferBuilder = new r();
}
i.prototype.getBuffer = function() {
return this.bufferBuilder.getBuffer();
}, i.prototype.pack = function(o) {
var c = typeof o;
if (c === "string")
this.pack_string(o);
else if (c === "number")
Math.floor(o) === o ? this.pack_integer(o) : this.pack_double(o);
else if (c === "boolean")
o === !0 ? this.bufferBuilder.append(195) : o === !1 && this.bufferBuilder.append(194);
else if (c === "undefined")
this.bufferBuilder.append(192);
else if (c === "object")
if (o === null)
this.bufferBuilder.append(192);
else {
var l = o.constructor;
if (l == Array)
this.pack_array(o);
else if (l == Blob || l == File || o instanceof Blob || o instanceof File)
this.pack_bin(o);
else if (l == ArrayBuffer)
t.useArrayBufferView ? this.pack_bin(new Uint8Array(o)) : this.pack_bin(o);
else if ("BYTES_PER_ELEMENT" in o)
t.useArrayBufferView ? this.pack_bin(new Uint8Array(o.buffer)) : this.pack_bin(o.buffer);
else if (l == Object || l.toString().startsWith("class"))
this.pack_object(o);
else if (l == Date)
this.pack_string(o.toString());
else if (typeof o.toBinaryPack == "function")
this.bufferBuilder.append(o.toBinaryPack());
else
throw new Error('Type "' + l.toString() + '" not yet supported');
}
else
throw new Error('Type "' + c + '" not yet supported');
this.bufferBuilder.flush();
}, i.prototype.pack_bin = function(o) {
var c = o.length || o.byteLength || o.size;
if (c <= 15)
this.pack_uint8(160 + c);
else if (c <= 65535)
this.bufferBuilder.append(218), this.pack_uint16(c);
else if (c <= 4294967295)
this.bufferBuilder.append(219), this.pack_uint32(c);
else
throw new Error("Invalid length");
this.bufferBuilder.append(o);
}, i.prototype.pack_string = function(o) {
var c = a(o);
if (c <= 15)
this.pack_uint8(176 + c);
else if (c <= 65535)
this.bufferBuilder.append(216), this.pack_uint16(c);
else if (c <= 4294967295)
this.bufferBuilder.append(217), this.pack_uint32(c);
else
throw new Error("Invalid length");
this.bufferBuilder.append(o);
}, i.prototype.pack_array = function(o) {
var c = o.length;
if (c <= 15)
this.pack_uint8(144 + c);
else if (c <= 65535)
this.bufferBuilder.append(220), this.pack_uint16(c);
else if (c <= 4294967295)
this.bufferBuilder.append(221), this.pack_uint32(c);
else
throw new Error("Invalid length");
for (var l = 0; l < c; l++)
this.pack(o[l]);
}, i.prototype.pack_integer = function(o) {
if (o >= -32 && o <= 127)
this.bufferBuilder.append(o & 255);
else if (o >= 0 && o <= 255)
this.bufferBuilder.append(204), this.pack_uint8(o);
else if (o >= -128 && o <= 127)
this.bufferBuilder.append(208), this.pack_int8(o);
else if (o >= 0 && o <= 65535)
this.bufferBuilder.append(205), this.pack_uint16(o);
else if (o >= -32768 && o <= 32767)
this.bufferBuilder.append(209), this.pack_int16(o);
else if (o >= 0 && o <= 4294967295)
this.bufferBuilder.append(206), this.pack_uint32(o);
else if (o >= -2147483648 && o <= 2147483647)
this.bufferBuilder.append(210), this.pack_int32(o);
else if (o >= -9223372036854776e3 && o <= 9223372036854776e3)
this.bufferBuilder.append(211), this.pack_int64(o);
else if (o >= 0 && o <= 18446744073709552e3)
this.bufferBuilder.append(207), this.pack_uint64(o);
else
throw new Error("Invalid integer");
}, i.prototype.pack_double = function(o) {
var c = 0;
o < 0 && (c = 1, o = -o);
var l = Math.floor(Math.log(o) / Math.LN2), u = o / Math.pow(2, l) - 1, f = Math.floor(u * Math.pow(2, 52)), p = Math.pow(2, 32), m = c << 31 | l + 1023 << 20 | f / p & 1048575, x = f % p;
this.bufferBuilder.append(203), this.pack_int32(m), this.pack_int32(x);
}, i.prototype.pack_object = function(o) {
var c = Object.keys(o), l = c.length;
if (l <= 15)
this.pack_uint8(128 + l);
else if (l <= 65535)
this.bufferBuilder.append(222), this.pack_uint16(l);
else if (l <= 4294967295)
this.bufferBuilder.append(223), this.pack_uint32(l);
else
throw new Error("Invalid length");
for (var u in o)
o.hasOwnProperty(u) && (this.pack(u), this.pack(o[u]));
}, i.prototype.pack_uint8 = function(o) {
this.bufferBuilder.append(o);
}, i.prototype.pack_uint16 = function(o) {
this.bufferBuilder.append(o >> 8), this.bufferBuilder.append(o & 255);
}, i.prototype.pack_uint32 = function(o) {
var c = o & 4294967295;
this.bufferBuilder.append((c & 4278190080) >>> 24), this.bufferBuilder.append((c & 16711680) >>> 16), this.bufferBuilder.append((c & 65280) >>> 8), this.bufferBuilder.append(c & 255);
}, i.prototype.pack_uint64 = function(o) {
var c = o / Math.pow(2, 32), l = o % Math.pow(2, 32);
this.bufferBuilder.append((c & 4278190080) >>> 24), this.bufferBuilder.append((c & 16711680) >>> 16), this.bufferBuilder.append((c & 65280) >>> 8), this.bufferBuilder.append(c & 255), this.bufferBuilder.append((l & 4278190080) >>> 24), this.bufferBuilder.append((l & 16711680) >>> 16), this.bufferBuilder.append((l & 65280) >>> 8), this.bufferBuilder.append(l & 255);
}, i.prototype.pack_int8 = function(o) {
this.bufferBuilder.append(o & 255);
}, i.prototype.pack_int16 = function(o) {
this.bufferBuilder.append((o & 65280) >> 8), this.bufferBuilder.append(o & 255);
}, i.prototype.pack_int32 = function(o) {
this.bufferBuilder.append(o >>> 24 & 255), this.bufferBuilder.append((o & 16711680) >>> 16), this.bufferBuilder.append((o & 65280) >>> 8), this.bufferBuilder.append(o & 255);
}, i.prototype.pack_int64 = function(o) {
var c = Math.floor(o / Math.pow(2, 32)), l = o % Math.pow(2, 32);
this.bufferBuilder.append((c & 4278190080) >>> 24), this.bufferBuilder.append((c & 16711680) >>> 16), this.bufferBuilder.append((c & 65280) >>> 8), this.bufferBuilder.append(c & 255), this.bufferBuilder.append((l & 4278190080) >>> 24), this.bufferBuilder.append((l & 16711680) >>> 16), this.bufferBuilder.append((l & 65280) >>> 8), this.bufferBuilder.append(l & 255);
};
function s(o) {
var c = o.charCodeAt(0);
return c <= 2047 ? "00" : c <= 65535 ? "000" : c <= 2097151 ? "0000" : c <= 67108863 ? "00000" : "000000";
}
function a(o) {
return o.length > 600 ? new Blob([o]).size : o.replace(/[^\u0000-\u007F]/g, s).length;
}
return xs;
}
var bu = _u();
const da = /* @__PURE__ */ Kr(bu);
let kc = !0, Rc = !0;
function fi(r, t, e) {
const n = r.match(t);
return n && n.length >= e && parseInt(n[e], 10);
}
function Zn(r, t, e) {
if (!r.RTCPeerConnection)
return;
const n = r.RTCPeerConnection.prototype, i = n.addEventListener;
n.addEventListener = function(a, o) {
if (a !== t)
return i.apply(this, arguments);
const c = (l) => {
const u = e(l);
u && (o.handleEvent ? o.handleEvent(u) : o(u));
};
return this._eventMap = this._eventMap || {}, this._eventMap[t] || (this._eventMap[t] = /* @__PURE__ */ new Map()), this._eventMap[t].set(o, c), i.apply(this, [
a,
c
]);
};
const s = n.removeEventListener;
n.removeEventListener = function(a, o) {
if (a !== t || !this._eventMap || !this._eventMap[t])
return s.apply(this, arguments);
if (!this._eventMap[t].has(o))
return s.apply(this, arguments);
const c = this._eventMap[t].get(o);
return this._eventMap[t].delete(o), this._eventMap[t].size === 0 && delete this._eventMap[t], Object.keys(this._eventMap).length === 0 && delete this._eventMap, s.apply(this, [
a,
c
]);
}, Object.defineProperty(n, "on" + t, {
get() {
return this["_on" + t];
},
set(a) {
this["_on" + t] && (this.removeEventListener(
t,
this["_on" + t]
), delete this["_on" + t]), a && this.addEventListener(
t,
this["_on" + t] = a
);
},
enumerable: !0,
configurable: !0
});
}
function Tu(r) {
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (kc = r, r ? "adapter.js logging disabled" : "adapter.js logging enabled");
}
function Cu(r) {
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (Rc = !r, "adapter.js deprecation warnings " + (r ? "disabled" : "enabled"));
}
function Co() {
if (typeof window == "object") {
if (kc)
return;
typeof console < "u" && typeof console.log == "function" && console.log.apply(console, arguments);
}
}
function Qr(r, t) {
Rc && console.warn(r + " is deprecated, please use " + t + " instead.");
}
function Mu(r) {
const t = { browser: null, version: null };
if (typeof r > "u" || !r.navigator)
return t.browser = "Not a browser.", t;
const { navigator: e } = r;
if (e.mozGetUserMedia)
t.browser = "firefox", t.version = fi(
e.userAgent,
/Firefox\/(\d+)\./,
1
);
else if (e.webkitGetUserMedia || r.isSecureContext === !1 && r.webkitRTCPeerConnection && !r.RTCIceGatherer)
t.browser = "chrome", t.version = fi(
e.userAgent,
/Chrom(e|ium)\/(\d+)\./,
2
);
else if (e.mediaDevices && e.userAgent.match(/Edge\/(\d+).(\d+)$/))
t.browser = "edge", t.version = fi(
e.userAgent,
/Edge\/(\d+).(\d+)$/,
2
);
else if (r.RTCPeerConnection && e.userAgent.match(/AppleWebKit\/(\d+)\./))
t.browser = "safari", t.version = fi(
e.userAgent,
/AppleWebKit\/(\d+)\./,
1
), t.supportsUnifiedPlan = r.RTCRtpTransceiver && "currentDirection" in r.RTCRtpTransceiver.prototype;
else
return t.browser = "Not a supported browser.", t;
return t;
}
function pa(r) {
return Object.prototype.toString.call(r) === "[object Object]";
}
function Ac(r) {
return pa(r) ? Object.keys(r).reduce(function(t, e) {
const n = pa(r[e]), i = n ? Ac(r[e]) : r[e], s = n && !Object.keys(i).length;
return i === void 0 || s ? t : Object.assign(t, { [e]: i });
}, {}) : r;
}
function Ks(r, t, e) {
!t || e.has(t.id) || (e.set(t.id, t), Object.keys(t).forEach((n) => {
n.endsWith("Id") ? Ks(r, r.get(t[n]), e) : n.endsWith("Ids") && t[n].forEach((i) => {
Ks(r, r.get(i), e);
});
}));
}
function ma(r, t, e) {
const n = e ? "outbound-rtp" : "inbound-rtp", i = /* @__PURE__ */ new Map();
if (t === null)
return i;
const s = [];
return r.forEach((a) => {
a.type === "track" && a.trackIdentifier === t.id && s.push(a);
}), s.forEach((a) => {
r.forEach((o) => {
o.type === n && o.trackId === a.id && Ks(r, o, i);
});
}), i;
}
const ya = Co;
function Oc(r, t) {
const e = r && r.navigator;
if (!e.mediaDevices)
return;
const n = function(o) {
if (typeof o != "object" || o.mandatory || o.optional)
return o;
const c = {};
return Object.keys(o).forEach((l) => {
if (l === "require" || l === "advanced" || l === "mediaSource")
return;
const u = typeof o[l] == "object" ? o[l] : { ideal: o[l] };
u.exact !== void 0 && typeof u.exact == "number" && (u.min = u.max = u.exact);
const f = function(p, m) {
return p ? p + m.charAt(0).toUpperCase() + m.slice(1) : m === "deviceId" ? "sourceId" : m;
};
if (u.ideal !== void 0) {
c.optional = c.optional || [];
let p = {};
typeof u.ideal == "number" ? (p[f("min", l)] = u.ideal, c.optional.push(p), p = {}, p[f("max", l)] = u.ideal, c.optional.push(p)) : (p[f("", l)] = u.ideal, c.optional.push(p));
}
u.exact !== void 0 && typeof u.exact != "number" ? (c.mandatory = c.mandatory || {}, c.mandatory[f("", l)] = u.exact) : ["min", "max"].forEach((p) => {
u[p] !== void 0 && (c.mandatory = c.mandatory || {}, c.mandatory[f(p, l)] = u[p]);
});
}), o.advanced && (c.optional = (c.optional || []).concat(o.advanced)), c;
}, i = function(o, c) {
if (t.version >= 61)
return c(o);
if (o = JSON.parse(JSON.stringify(o)), o && typeof o.audio == "object") {
const l = function(u, f, p) {
f in u && !(p in u) && (u[p] = u[f], delete u[f]);
};
o = JSON.parse(JSON.stringify(o)), l(o.audio, "autoGainControl", "googAutoGainControl"), l(o.audio, "noiseSuppression", "googNoiseSuppression"), o.audio = n(o.audio);
}
if (o && typeof o.video == "object") {
let l = o.video.facingMode;
l = l && (typeof l == "object" ? l : { ideal: l });
const u = t.version < 66;
if (l && (l.exact === "user" || l.exact === "environment" || l.ideal === "user" || l.ideal === "environment") && !(e.mediaDevices.getSupportedConstraints && e.mediaDevices.getSupportedConstraints().facingMode && !u)) {
delete o.video.facingMode;
let f;
if (l.exact === "environment" || l.ideal === "environment" ? f = ["back", "rear"] : (l.exact === "user" || l.ideal === "user") && (f = ["front"]), f)
return e.mediaDevices.enumerateDevices().then((p) => {
p = p.filter((x) => x.kind === "videoinput");
let m = p.find((x) => f.some((T) => x.label.toLowerCase().includes(T)));
return !m && p.length && f.includes("back") && (m = p[p.length - 1]), m && (o.video.deviceId = l.exact ? { exact: m.deviceId } : { ideal: m.deviceId }), o.video = n(o.video), ya("chrome: " + JSON.stringify(o)), c(o);
});
}
o.video = n(o.video);
}
return ya("chrome: " + JSON.stringify(o)), c(o);
}, s = function(o) {
return t.version >= 64 ? o : {
name: {
PermissionDeniedError: "NotAllowedError",
PermissionDismissedError: "NotAllowedError",
InvalidStateError: "NotAllowedError",
DevicesNotFoundError: "NotFoundError",
ConstraintNotSatisfiedError: "OverconstrainedError",
TrackStartError: "NotReadableError",
MediaDeviceFailedDueToShutdown: "NotAllowedError",
MediaDeviceKillSwitchOn: "NotAllowedError",
TabCaptureError: "AbortError",
ScreenCaptureError: "AbortError",
DeviceCaptureError: "AbortError"
}[o.name] || o.name,
message: o.message,
constraint: o.constraint || o.constraintName,
toString() {
return this.name + (this.message && ": ") + this.message;
}
};
}, a = function(o, c, l) {
i(o, (u) => {
e.webkitGetUserMedia(u, c, (f) => {
l && l(s(f));
});
});
};
if (e.getUserMedia = a.bind(e), e.mediaDevices.getUserMed