@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,407 lines • 553 kB
JavaScript
import { PlaneGeometry as qo, ShaderChunk as vc, Triangle as jt, Vector3 as B, Layers as Wr, MeshBasicMaterial as Hn, DoubleSide as qn, AdditiveBlending as Xo, Object3D as Ts, InstancedBufferAttribute as Be, DynamicDrawUsage as _t, InstancedBufferGeometry as xc, Uniform$1 as Gt, ShaderMaterial as Xn, BufferGeometry as si, BufferAttribute as gt, Mesh as pn, MeshStandardMaterial as _c, MeshPhysicalMaterial as bc, Vector2 as Qt, Plane as Wo, Line3 as ue, Sphere as Yo, Matrix4 as It, Box3 as Pt, REVISION as Zo, BackSide as Sc, FrontSide as Ds, Group as Tc, LineBasicMaterial as Mc, BatchedMesh as Cc, Ray as wc, DataTexture as Wn, NearestFilter as ii, UnsignedIntType as Ui, IntType as Yr, FloatType as Di, UnsignedByteType as Fs, UnsignedShortType as Pc, ByteType as Ls, ShortType as Ec, RGBAFormat as nn, RGBAIntegerFormat as Yn, RGFormat as Ac, RedFormat as kc, RGIntegerFormat as Qo, RedIntegerFormat as Rc, Matrix3 as zc, Vector4 as Ms } from "./three.light.js";
const ot = {
Handedness: Object.freeze({
NONE: "none",
LEFT: "left",
RIGHT: "right"
}),
ComponentState: Object.freeze({
DEFAULT: "default",
TOUCHED: "touched",
PRESSED: "pressed"
}),
ComponentProperty: Object.freeze({
BUTTON: "button",
X_AXIS: "xAxis",
Y_AXIS: "yAxis",
STATE: "state"
}),
ComponentType: Object.freeze({
TRIGGER: "trigger",
SQUEEZE: "squeeze",
TOUCHPAD: "touchpad",
THUMBSTICK: "thumbstick",
BUTTON: "button"
}),
ButtonTouchThreshold: 0.05,
AxisTouchThreshold: 0.1,
VisualResponseProperty: Object.freeze({
TRANSFORM: "transform",
VISIBILITY: "visibility"
})
};
async function Ko(r) {
const t = await fetch(r);
if (t.ok)
return t.json();
throw new Error(t.statusText);
}
async function Bc(r) {
if (!r)
throw new Error("No basePath supplied");
return await Ko(`${r}/profilesList.json`);
}
async function Bf(r, t, e = null, i = !0) {
if (!r)
throw new Error("No xrInputSource supplied");
if (!t)
throw new Error("No basePath supplied");
const n = await Bc(t);
let s;
if (r.profiles.some((a) => {
const l = n[a];
return l && (s = {
profileId: a,
profilePath: `${t}/${l.path}`,
deprecated: !!l.deprecated
}), !!s;
}), !s) {
if (!e)
throw new Error("No matching profile name found");
const a = n[e];
if (!a)
throw new Error(`No matching profile name found and default profile "${e}" missing.`);
s = {
profileId: e,
profilePath: `${t}/${a.path}`,
deprecated: !!a.deprecated
};
}
const o = await Ko(s.profilePath);
let c;
if (i) {
let a;
if (r.handedness === "any" ? a = o.layouts[Object.keys(o.layouts)[0]] : a = o.layouts[r.handedness], !a)
throw new Error(
`No matching handedness, ${r.handedness}, in profile ${s.profileId}`
);
a.assetPath && (c = s.profilePath.replace("profile.json", a.assetPath));
}
return { profile: o, assetPath: c };
}
const Oc = {
xAxis: 0,
yAxis: 0,
button: 0,
state: ot.ComponentState.DEFAULT
};
function Ic(r = 0, t = 0) {
let e = r, i = t;
if (Math.sqrt(r * r + t * t) > 1) {
const o = Math.atan2(t, r);
e = Math.cos(o), i = Math.sin(o);
}
return {
normalizedXAxis: e * 0.5 + 0.5,
normalizedYAxis: i * 0.5 + 0.5
};
}
class Nc {
constructor(t) {
this.componentProperty = t.componentProperty, this.states = t.states, this.valueNodeName = t.valueNodeName, this.valueNodeProperty = t.valueNodeProperty, this.valueNodeProperty === ot.VisualResponseProperty.TRANSFORM && (this.minNodeName = t.minNodeName, this.maxNodeName = t.maxNodeName), this.value = 0, this.updateFromComponent(Oc);
}
/**
* 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: i,
state: n
}) {
const { normalizedXAxis: s, normalizedYAxis: o } = Ic(t, e);
switch (this.componentProperty) {
case ot.ComponentProperty.X_AXIS:
this.value = this.states.includes(n) ? s : 0.5;
break;
case ot.ComponentProperty.Y_AXIS:
this.value = this.states.includes(n) ? o : 0.5;
break;
case ot.ComponentProperty.BUTTON:
this.value = this.states.includes(n) ? i : 0;
break;
case ot.ComponentProperty.STATE:
this.valueNodeProperty === ot.VisualResponseProperty.VISIBILITY ? this.value = this.states.includes(n) : this.value = this.states.includes(n) ? 1 : 0;
break;
default:
throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`);
}
}
}
class Uc {
/**
* @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((i) => {
const n = new Nc(e.visualResponses[i]);
this.visualResponses[i] = n;
}), this.gamepadIndices = Object.assign({}, e.gamepadIndices), this.values = {
state: ot.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 = ot.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 = ot.ComponentState.PRESSED : (e.touched || this.values.button > ot.ButtonTouchThreshold) && (this.values.state = ot.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 === ot.ComponentState.DEFAULT && Math.abs(this.values.xAxis) > ot.AxisTouchThreshold && (this.values.state = ot.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 === ot.ComponentState.DEFAULT && Math.abs(this.values.yAxis) > ot.AxisTouchThreshold && (this.values.state = ot.ComponentState.TOUCHED)), Object.values(this.visualResponses).forEach((e) => {
e.updateFromComponent(this.values);
});
}
}
class Of {
/**
* @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, i) {
if (!t)
throw new Error("No xrInputSource supplied");
if (!e)
throw new Error("No profile supplied");
this.xrInputSource = t, this.assetUrl = i, this.id = e.profileId, this.layoutDescription = e.layouts[t.handedness], this.components = {}, Object.keys(this.layoutDescription.components).forEach((n) => {
const s = this.layoutDescription.components[n];
this.components[n] = new Uc(n, 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 Sn = 2, Yt = 4, le = 4, Dc = 4, ve = new Int32Array(2), Vs = new Float32Array(ve.buffer), Js = new Float64Array(ve.buffer), Sr = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
class fe {
constructor(t, e) {
this.low = t | 0, this.high = e | 0;
}
static create(t, e) {
return t == 0 && e == 0 ? fe.ZERO : new fe(t, e);
}
toFloat64() {
return (this.low >>> 0) + this.high * 4294967296;
}
equals(t) {
return this.low == t.low && this.high == t.high;
}
}
fe.ZERO = new fe(0, 0);
var Zn;
(function(r) {
r[r.UTF8_BYTES = 1] = "UTF8_BYTES", r[r.UTF16_STRING = 2] = "UTF16_STRING";
})(Zn || (Zn = {}));
class sn {
/**
* 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 sn(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 fe(this.readInt32(t), this.readInt32(t + 4));
}
readUint64(t) {
return new fe(this.readUint32(t), this.readUint32(t + 4));
}
readFloat32(t) {
return ve[0] = this.readInt32(t), Vs[0];
}
readFloat64(t) {
return ve[Sr ? 0 : 1] = this.readInt32(t), ve[Sr ? 1 : 0] = this.readInt32(t + 4), Js[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) {
Vs[0] = e, this.writeInt32(t, ve[0]);
}
writeFloat64(t, e) {
Js[0] = e, this.writeInt32(t, ve[Sr ? 0 : 1]), this.writeInt32(t + 4, ve[Sr ? 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_ + Yt + le)
throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");
let t = "";
for (let e = 0; e < le; e++)
t += String.fromCharCode(this.readInt8(this.position_ + Yt + 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 i = t - this.readInt32(t);
return e < this.readInt16(i) ? this.readInt16(i + 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 i = this.readInt32(t);
let n = "", s = 0;
if (t += Yt, e === Zn.UTF8_BYTES)
return this.bytes_.subarray(t, t + i);
for (; s < i; ) {
let o;
const c = this.readUint8(t + s++);
if (c < 192)
o = c;
else {
const a = this.readUint8(t + s++);
if (c < 224)
o = (c & 31) << 6 | a & 63;
else {
const l = this.readUint8(t + s++);
if (c < 240)
o = (c & 15) << 12 | (a & 63) << 6 | l & 63;
else {
const h = this.readUint8(t + s++);
o = (c & 7) << 18 | (a & 63) << 12 | (l & 63) << 6 | h & 63;
}
}
}
o < 65536 ? n += String.fromCharCode(o) : (o -= 65536, n += String.fromCharCode((o >> 10) + 55296, (o & 1024 - 1) + 56320));
}
return n;
}
/**
* 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) + Yt;
}
/**
* 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 != le)
throw new Error("FlatBuffers: file identifier must be length " + le);
for (let e = 0; e < le; e++)
if (t.charCodeAt(e) != this.readInt8(this.position() + Yt + e))
return !1;
return !0;
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return fe.create(t, e);
}
/**
* A helper function for generating list for obj api
*/
createScalarList(t, e) {
const i = [];
for (let n = 0; n < e; ++n)
t(n) !== null && i.push(t(n));
return i;
}
/**
* 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 i = [];
for (let n = 0; n < e; ++n) {
const s = t(n);
s !== null && i.push(s.unpack());
}
return i;
}
}
class ta {
/**
* 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 = sn.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 i = ~(this.bb.capacity() - this.space + e) + 1 & t - 1;
for (; this.space < i + t + e; ) {
const n = this.bb.capacity();
this.bb = ta.growByteBuffer(this.bb), this.space += this.bb.capacity() - n;
}
this.pad(i);
}
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, i) {
(this.force_defaults || e != i) && (this.addInt8(e), this.slot(t));
}
addFieldInt16(t, e, i) {
(this.force_defaults || e != i) && (this.addInt16(e), this.slot(t));
}
addFieldInt32(t, e, i) {
(this.force_defaults || e != i) && (this.addInt32(e), this.slot(t));
}
addFieldInt64(t, e, i) {
(this.force_defaults || !e.equals(i)) && (this.addInt64(e), this.slot(t));
}
addFieldFloat32(t, e, i) {
(this.force_defaults || e != i) && (this.addFloat32(e), this.slot(t));
}
addFieldFloat64(t, e, i) {
(this.force_defaults || e != i) && (this.addFloat64(e), this.slot(t));
}
addFieldOffset(t, e, i) {
(this.force_defaults || e != i) && (this.addOffset(e), this.slot(t));
}
/**
* Structs are stored inline, so nothing additional is being added. `d` is always 0.
*/
addFieldStruct(t, e, i) {
e != i && (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 i = e << 1, n = sn.allocate(i);
return n.setPosition(i - e), n.bytes().set(t.bytes(), i - e), n;
}
/**
* Adds on offset, relative to where it will be written.
*
* @param offset The offset to add.
*/
addOffset(t) {
this.prep(Yt, 0), this.writeInt32(this.offset() - t + Yt);
}
/**
* 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 i = e + 1;
for (; e >= 0; e--)
this.addInt16(this.vtable[e] != 0 ? t - this.vtable[e] : 0);
const n = 2;
this.addInt16(t - this.object_start);
const s = (i + n) * Sn;
this.addInt16(s);
let o = 0;
const c = this.space;
t:
for (e = 0; e < this.vtables.length; e++) {
const a = this.bb.capacity() - this.vtables[e];
if (s == this.bb.readInt16(a)) {
for (let l = Sn; l < s; l += Sn)
if (this.bb.readInt16(c + l) != this.bb.readInt16(a + l))
continue t;
o = this.vtables[e];
break;
}
}
return o ? (this.space = this.bb.capacity() - t, this.bb.writeInt32(this.space, o - 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, i) {
const n = i ? Dc : 0;
if (e) {
const s = e;
if (this.prep(this.minalign, Yt + le + n), s.length != le)
throw new Error("FlatBuffers: file identifier must be length " + le);
for (let o = le - 1; o >= 0; o--)
this.writeInt8(s.charCodeAt(o));
}
this.prep(this.minalign, Yt + n), this.addOffset(t), n && 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 i = this.bb.capacity() - t, n = i - this.bb.readInt32(i);
if (!(this.bb.readInt16(n + 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, i) {
this.notNested(), this.vector_num_elems = e, this.prep(Yt, t * e), this.prep(i, 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 i = 0;
for (; i < t.length; ) {
let n;
const s = t.charCodeAt(i++);
if (s < 55296 || s >= 56320)
n = s;
else {
const o = t.charCodeAt(i++);
n = (s << 10) + o + (65536 - 56623104 - 56320);
}
n < 128 ? e.push(n) : (n < 2048 ? e.push(n >> 6 & 31 | 192) : (n < 65536 ? e.push(n >> 12 & 15 | 224) : e.push(n >> 18 & 7 | 240, n >> 12 & 63 | 128), e.push(n >> 6 & 63 | 128)), e.push(n & 63 | 128));
}
}
this.addInt8(0), this.startVector(1, e.length, 1), this.bb.setPosition(this.space -= e.length);
for (let i = 0, n = this.space, s = this.bb.bytes(); i < e.length; i++)
s[n++] = e[i];
return this.endVector();
}
/**
* A helper function to avoid generated code depending on this file directly.
*/
createLong(t, e) {
return fe.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 i = 0; i < t.length; ++i) {
const n = t[i];
if (n !== null)
e.push(this.createObjectOffset(n));
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 mn(r) {
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
}
var ea = { exports: {} };
(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 i() {
this._pieces = [], this._parts = [];
}
i.prototype.append = function(n) {
typeof n == "number" ? this._pieces.push(n) : (this.flush(), this._parts.push(n));
}, i.prototype.flush = function() {
if (this._pieces.length > 0) {
var n = new Uint8Array(this._pieces);
t.useArrayBufferView || (n = n.buffer), this._parts.push(n), this._pieces = [];
}
}, i.prototype.getBuffer = function() {
if (this.flush(), t.useBlobBuilder) {
for (var n = new e(), s = 0, o = this._parts.length; s < o; s++)
n.append(this._parts[s]);
return n.getBlob();
} else
return new Blob(this._parts);
}, r.exports.BufferBuilder = i;
})(ea);
var ia = ea.exports, Fc = ia.BufferBuilder, Gs = ia.binaryFeatures, Lc = {
unpack: function(r) {
var t = new ft(r);
return t.unpack();
},
pack: function(r) {
var t = new dt();
t.pack(r);
var e = t.getBuffer();
return e;
}
}, Vc = Lc;
function ft(r) {
this.index = 0, this.dataBuffer = r, this.dataView = new Uint8Array(this.dataBuffer), this.length = this.dataBuffer.byteLength;
}
ft.prototype.unpack = function() {
var r = this.unpack_uint8();
if (r < 128)
return r;
if ((r ^ 224) < 32)
return (r ^ 224) - 32;
var t;
if ((t = r ^ 160) <= 15)
return this.unpack_raw(t);
if ((t = r ^ 176) <= 15)
return this.unpack_string(t);
if ((t = r ^ 144) <= 15)
return this.unpack_array(t);
if ((t = r ^ 128) <= 15)
return this.unpack_map(t);
switch (r) {
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 t = this.unpack_uint16(), this.unpack_string(t);
case 217:
return t = this.unpack_uint32(), this.unpack_string(t);
case 218:
return t = this.unpack_uint16(), this.unpack_raw(t);
case 219:
return t = this.unpack_uint32(), this.unpack_raw(t);
case 220:
return t = this.unpack_uint16(), this.unpack_array(t);
case 221:
return t = this.unpack_uint32(), this.unpack_array(t);
case 222:
return t = this.unpack_uint16(), this.unpack_map(t);
case 223:
return t = this.unpack_uint32(), this.unpack_map(t);
}
};
ft.prototype.unpack_uint8 = function() {
var r = this.dataView[this.index] & 255;
return this.index++, r;
};
ft.prototype.unpack_uint16 = function() {
var r = this.read(2), t = (r[0] & 255) * 256 + (r[1] & 255);
return this.index += 2, t;
};
ft.prototype.unpack_uint32 = function() {
var r = this.read(4), t = ((r[0] * 256 + r[1]) * 256 + r[2]) * 256 + r[3];
return this.index += 4, t;
};
ft.prototype.unpack_uint64 = function() {
var r = this.read(8), t = ((((((r[0] * 256 + r[1]) * 256 + r[2]) * 256 + r[3]) * 256 + r[4]) * 256 + r[5]) * 256 + r[6]) * 256 + r[7];
return this.index += 8, t;
};
ft.prototype.unpack_int8 = function() {
var r = this.unpack_uint8();
return r < 128 ? r : r - 256;
};
ft.prototype.unpack_int16 = function() {
var r = this.unpack_uint16();
return r < 32768 ? r : r - 65536;
};
ft.prototype.unpack_int32 = function() {
var r = this.unpack_uint32();
return r < Math.pow(2, 31) ? r : r - Math.pow(2, 32);
};
ft.prototype.unpack_int64 = function() {
var r = this.unpack_uint64();
return r < Math.pow(2, 63) ? r : r - Math.pow(2, 64);
};
ft.prototype.unpack_raw = function(r) {
if (this.length < this.index + r)
throw new Error("BinaryPackFailure: index is out of range " + this.index + " " + r + " " + this.length);
var t = this.dataBuffer.slice(this.index, this.index + r);
return this.index += r, t;
};
ft.prototype.unpack_string = function(r) {
for (var t = this.read(r), e = 0, i = "", n, s; e < r; )
n = t[e], n < 128 ? (i += String.fromCharCode(n), e++) : (n ^ 192) < 32 ? (s = (n ^ 192) << 6 | t[e + 1] & 63, i += String.fromCharCode(s), e += 2) : (s = (n & 15) << 12 | (t[e + 1] & 63) << 6 | t[e + 2] & 63, i += String.fromCharCode(s), e += 3);
return this.index += r, i;
};
ft.prototype.unpack_array = function(r) {
for (var t = new Array(r), e = 0; e < r; e++)
t[e] = this.unpack();
return t;
};
ft.prototype.unpack_map = function(r) {
for (var t = {}, e = 0; e < r; e++) {
var i = this.unpack(), n = this.unpack();
t[i] = n;
}
return t;
};
ft.prototype.unpack_float = function() {
var r = this.unpack_uint32(), t = r >> 31, e = (r >> 23 & 255) - 127, i = r & 8388607 | 8388608;
return (t === 0 ? 1 : -1) * i * Math.pow(2, e - 23);
};
ft.prototype.unpack_double = function() {
var r = this.unpack_uint32(), t = this.unpack_uint32(), e = r >> 31, i = (r >> 20 & 2047) - 1023, n = r & 1048575 | 1048576, s = n * Math.pow(2, i - 20) + t * Math.pow(2, i - 52);
return (e === 0 ? 1 : -1) * s;
};
ft.prototype.read = function(r) {
var t = this.index;
if (t + r <= this.length)
return this.dataView.subarray(t, t + r);
throw new Error("BinaryPackFailure: read index out of range");
};
function dt() {
this.bufferBuilder = new Fc();
}
dt.prototype.getBuffer = function() {
return this.bufferBuilder.getBuffer();
};
dt.prototype.pack = function(r) {
var t = typeof r;
if (t === "string")
this.pack_string(r);
else if (t === "number")
Math.floor(r) === r ? this.pack_integer(r) : this.pack_double(r);
else if (t === "boolean")
r === !0 ? this.bufferBuilder.append(195) : r === !1 && this.bufferBuilder.append(194);
else if (t === "undefined")
this.bufferBuilder.append(192);
else if (t === "object")
if (r === null)
this.bufferBuilder.append(192);
else {
var e = r.constructor;
if (e == Array)
this.pack_array(r);
else if (e == Blob || e == File || r instanceof Blob || r instanceof File)
this.pack_bin(r);
else if (e == ArrayBuffer)
Gs.useArrayBufferView ? this.pack_bin(new Uint8Array(r)) : this.pack_bin(r);
else if ("BYTES_PER_ELEMENT" in r)
Gs.useArrayBufferView ? this.pack_bin(new Uint8Array(r.buffer)) : this.pack_bin(r.buffer);
else if (e == Object || e.toString().startsWith("class"))
this.pack_object(r);
else if (e == Date)
this.pack_string(r.toString());
else if (typeof r.toBinaryPack == "function")
this.bufferBuilder.append(r.toBinaryPack());
else
throw new Error('Type "' + e.toString() + '" not yet supported');
}
else
throw new Error('Type "' + t + '" not yet supported');
this.bufferBuilder.flush();
};
dt.prototype.pack_bin = function(r) {
var t = r.length || r.byteLength || r.size;
if (t <= 15)
this.pack_uint8(160 + t);
else if (t <= 65535)
this.bufferBuilder.append(218), this.pack_uint16(t);
else if (t <= 4294967295)
this.bufferBuilder.append(219), this.pack_uint32(t);
else
throw new Error("Invalid length");
this.bufferBuilder.append(r);
};
dt.prototype.pack_string = function(r) {
var t = Gc(r);
if (t <= 15)
this.pack_uint8(176 + t);
else if (t <= 65535)
this.bufferBuilder.append(216), this.pack_uint16(t);
else if (t <= 4294967295)
this.bufferBuilder.append(217), this.pack_uint32(t);
else
throw new Error("Invalid length");
this.bufferBuilder.append(r);
};
dt.prototype.pack_array = function(r) {
var t = r.length;
if (t <= 15)
this.pack_uint8(144 + t);
else if (t <= 65535)
this.bufferBuilder.append(220), this.pack_uint16(t);
else if (t <= 4294967295)
this.bufferBuilder.append(221), this.pack_uint32(t);
else
throw new Error("Invalid length");
for (var e = 0; e < t; e++)
this.pack(r[e]);
};
dt.prototype.pack_integer = function(r) {
if (r >= -32 && r <= 127)
this.bufferBuilder.append(r & 255);
else if (r >= 0 && r <= 255)
this.bufferBuilder.append(204), this.pack_uint8(r);
else if (r >= -128 && r <= 127)
this.bufferBuilder.append(208), this.pack_int8(r);
else if (r >= 0 && r <= 65535)
this.bufferBuilder.append(205), this.pack_uint16(r);
else if (r >= -32768 && r <= 32767)
this.bufferBuilder.append(209), this.pack_int16(r);
else if (r >= 0 && r <= 4294967295)
this.bufferBuilder.append(206), this.pack_uint32(r);
else if (r >= -2147483648 && r <= 2147483647)
this.bufferBuilder.append(210), this.pack_int32(r);
else if (r >= -9223372036854776e3 && r <= 9223372036854776e3)
this.bufferBuilder.append(211), this.pack_int64(r);
else if (r >= 0 && r <= 18446744073709552e3)
this.bufferBuilder.append(207), this.pack_uint64(r);
else
throw new Error("Invalid integer");
};
dt.prototype.pack_double = function(r) {
var t = 0;
r < 0 && (t = 1, r = -r);
var e = Math.floor(Math.log(r) / Math.LN2), i = r / Math.pow(2, e) - 1, n = Math.floor(i * Math.pow(2, 52)), s = Math.pow(2, 32), o = t << 31 | e + 1023 << 20 | n / s & 1048575, c = n % s;
this.bufferBuilder.append(203), this.pack_int32(o), this.pack_int32(c);
};
dt.prototype.pack_object = function(r) {
var t = Object.keys(r), e = t.length;
if (e <= 15)
this.pack_uint8(128 + e);
else if (e <= 65535)
this.bufferBuilder.append(222), this.pack_uint16(e);
else if (e <= 4294967295)
this.bufferBuilder.append(223), this.pack_uint32(e);
else
throw new Error("Invalid length");
for (var i in r)
r.hasOwnProperty(i) && (this.pack(i), this.pack(r[i]));
};
dt.prototype.pack_uint8 = function(r) {
this.bufferBuilder.append(r);
};
dt.prototype.pack_uint16 = function(r) {
this.bufferBuilder.append(r >> 8), this.bufferBuilder.append(r & 255);
};
dt.prototype.pack_uint32 = function(r) {
var t = r & 4294967295;
this.bufferBuilder.append((t & 4278190080) >>> 24), this.bufferBuilder.append((t & 16711680) >>> 16), this.bufferBuilder.append((t & 65280) >>> 8), this.bufferBuilder.append(t & 255);
};
dt.prototype.pack_uint64 = function(r) {
var t = r / Math.pow(2, 32), e = r % Math.pow(2, 32);
this.bufferBuilder.append((t & 4278190080) >>> 24), this.bufferBuilder.append((t & 16711680) >>> 16), this.bufferBuilder.append((t & 65280) >>> 8), this.bufferBuilder.append(t & 255), this.bufferBuilder.append((e & 4278190080) >>> 24), this.bufferBuilder.append((e & 16711680) >>> 16), this.bufferBuilder.append((e & 65280) >>> 8), this.bufferBuilder.append(e & 255);
};
dt.prototype.pack_int8 = function(r) {
this.bufferBuilder.append(r & 255);
};
dt.prototype.pack_int16 = function(r) {
this.bufferBuilder.append((r & 65280) >> 8), this.bufferBuilder.append(r & 255);
};
dt.prototype.pack_int32 = function(r) {
this.bufferBuilder.append(r >>> 24 & 255), this.bufferBuilder.append((r & 16711680) >>> 16), this.bufferBuilder.append((r & 65280) >>> 8), this.bufferBuilder.append(r & 255);
};
dt.prototype.pack_int64 = function(r) {
var t = Math.floor(r / Math.pow(2, 32)), e = r % Math.pow(2, 32);
this.bufferBuilder.append((t & 4278190080) >>> 24), this.bufferBuilder.append((t & 16711680) >>> 16), this.bufferBuilder.append((t & 65280) >>> 8), this.bufferBuilder.append(t & 255), this.bufferBuilder.append((e & 4278190080) >>> 24), this.bufferBuilder.append((e & 16711680) >>> 16), this.bufferBuilder.append((e & 65280) >>> 8), this.bufferBuilder.append(e & 255);
};
function Jc(r) {
var t = r.charCodeAt(0);
return t <= 2047 ? "00" : t <= 65535 ? "000" : t <= 2097151 ? "0000" : t <= 67108863 ? "00000" : "000000";
}
function Gc(r) {
return r.length > 600 ? new Blob([r]).size : r.replace(/[^\u0000-\u007F]/g, Jc).length;
}
const js = /* @__PURE__ */ mn(Vc);
let ra = !0, na = !0;
function zi(r, t, e) {
const i = r.match(t);
return i && i.length >= e && parseInt(i[e], 10);
}
function hi(r, t, e) {
if (!r.RTCPeerConnection)
return;
const i = r.RTCPeerConnection.prototype, n = i.addEventListener;
i.addEventListener = function(o, c) {
if (o !== t)
return n.apply(this, arguments);
const a = (l) => {
const h = e(l);
h && (c.handleEvent ? c.handleEvent(h) : c(h));
};
return this._eventMap = this._eventMap || {}, this._eventMap[t] || (this._eventMap[t] = /* @__PURE__ */ new Map()), this._eventMap[t].set(c, a), n.apply(this, [
o,
a
]);
};
const s = i.removeEventListener;
i.removeEventListener = function(o, c) {
if (o !== t || !this._eventMap || !this._eventMap[t])
return s.apply(this, arguments);
if (!this._eventMap[t].has(c))
return s.apply(this, arguments);
const a = this._eventMap[t].get(c);
return this._eventMap[t].delete(c), this._eventMap[t].size === 0 && delete this._eventMap[t], Object.keys(this._eventMap).length === 0 && delete this._eventMap, s.apply(this, [
o,
a
]);
}, Object.defineProperty(i, "on" + t, {
get() {
return this["_on" + t];
},
set(o) {
this["_on" + t] && (this.removeEventListener(
t,
this["_on" + t]
), delete this["_on" + t]), o && this.addEventListener(
t,
this["_on" + t] = o
);
},
enumerable: !0,
configurable: !0
});
}
function jc(r) {
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (ra = r, r ? "adapter.js logging disabled" : "adapter.js logging enabled");
}
function $c(r) {
return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (na = !r, "adapter.js deprecation warnings " + (r ? "disabled" : "enabled"));
}
function Cs() {
if (typeof window == "object") {
if (ra)
return;
typeof console < "u" && typeof console.log == "function" && console.log.apply(console, arguments);
}
}
function yn(r, t) {
na && console.warn(r + " is deprecated, please use " + t + " instead.");
}
function Hc(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 = zi(
e.userAgent,
/Firefox\/(\d+)\./,
1
);
else if (e.webkitGetUserMedia || r.isSecureContext === !1 && r.webkitRTCPeerConnection && !r.RTCIceGatherer)
t.browser = "chrome", t.version = zi(
e.userAgent,
/Chrom(e|ium)\/(\d+)\./,
2
);
else if (e.mediaDevices && e.userAgent.match(/Edge\/(\d+).(\d+)$/))
t.browser = "edge", t.version = zi(
e.userAgent,
/Edge\/(\d+).(\d+)$/,
2
);
else if (r.RTCPeerConnection && e.userAgent.match(/AppleWebKit\/(\d+)\./))
t.browser = "safari", t.version = zi(
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 $s(r) {
return Object.prototype.toString.call(r) === "[object Object]";
}
function sa(r) {
return $s(r) ? Object.keys(r).reduce(function(t, e) {
const i = $s(r[e]), n = i ? sa(r[e]) : r[e], s = i && !Object.keys(n).length;
return n === void 0 || s ? t : Object.assign(t, { [e]: n });
}, {}) : r;
}
function Qn(r, t, e) {
!t || e.has(t.id) || (e.set(t.id, t), Object.keys(t).forEach((i) => {
i.endsWith("Id") ? Qn(r, r.get(t[i]), e) : i.endsWith("Ids") && t[i].forEach((n) => {
Qn(r, r.get(n), e);
});
}));
}
function Hs(r, t, e) {
const i = e ? "outbound-rtp" : "inbound-rtp", n = /* @__PURE__ */ new Map();
if (t === null)
return n;
const s = [];
return r.forEach((o) => {
o.type === "track" && o.trackIdentifier === t.id && s.push(o);
}), s.forEach((o) => {
r.forEach((c) => {
c.type === i && c.trackId === o.id && Qn(r, c, n);
});
}), n;
}
const qs = Cs;
function oa(r, t) {
const e = r && r.navigator;
if (!e.mediaDevices)
return;
const i = function(c) {
if (typeof c != "object" || c.mandatory || c.optional)
return c;
const a = {};
return Object.keys(c).forEach((l) => {
if (l === "require" || l === "advanced" || l === "mediaSource")
return;
const h = typeof c[l] == "object" ? c[l] : { ideal: c[l] };
h.exact !== void 0 && typeof h.exact == "number" && (h.min = h.max = h.exact);
const u = function(f, d) {
return f ? f + d.charAt(0).toUpperCase() + d.slice(1) : d === "deviceId" ? "sourceId" : d;
};
if (h.ideal !== void 0) {
a.optional = a.optional || [];
let f = {};
typeof h.ideal == "number" ? (f[u("min", l)] = h.ideal, a.optional.push(f), f = {}, f[u("max", l)] = h.ideal, a.optional.push(f)) : (f[u("", l)] = h.ideal, a.optional.push(f));
}
h.exact !== void 0 && typeof h.exact != "number" ? (a.mandatory = a.mandatory || {}, a.mandatory[u("", l)] = h.exact) : ["min", "max"].forEach((f) => {
h[f] !== void 0 && (a.mandatory = a.mandatory || {}, a.mandatory[u(f, l)] = h[f]);
});
}), c.advanced && (a.optional = (a.optional || []).concat(c.advanced)), a;
}, n = function(c, a) {
if (t.version >= 61)
return a(c);
if (c = JSON.parse(JSON.stringify(c)), c && typeof c.audio == "object") {
const l = function(h, u, f) {
u in h && !(f in h) && (h[f] = h[u], delete h[u]);
};
c = JSON.parse(JSON.stringify(c)), l(c.audio, "autoGainControl", "googAutoGainControl"), l(c.audio, "noiseSuppression", "googNoiseSuppression"), c.audio = i(c.audio);
}
if (c && typeof c.video == "object") {
let l = c.video.facingMode;
l = l && (typeof l == "object" ? l : { ideal: l });
const h = t.version < 66;
if (l && (l.exact === "user" || l.exact === "environment" || l.ideal === "user" || l.ideal === "environment") && !(e.mediaDevices.getSupportedConstraints && e.mediaDevices.getSupportedConstraints().facingMode && !h)) {
delete c.video.facingMode;
let u;
if (l.exact === "environment" || l.ideal === "environment" ? u = ["back", "rear"] : (l.exact === "user" || l.ideal === "user") && (u = ["front"]), u)
return e.mediaDevices.enumerateDevices().then((f) => {
f = f.filter((p) => p.kind === "videoinput");
let d = f.find((p) => u.some((m) => p.label.toLowerCase().includes(m)));
return !d && f.length && u.includes("back") && (d = f[f.length - 1]), d && (c.video.deviceId = l.exact ? { exact: d.deviceId } : { ideal: d.deviceId }), c.video = i(c.video), qs("chrome: " + JSON.stringify(c)), a(c);
});
}
c.video = i(c.video);
}
return qs("chrome: " + JSON.stringify(c)), a(c);
}, s = function(c) {
return t.version >= 64 ? c : {
name: {
PermissionDeniedError: "NotAllowedError",
PermissionDismissedError: "NotAllowedError",
InvalidStateError: "NotAllowedError",
DevicesNotFoundError: "NotFoundError",
ConstraintNotSatisfiedError: "OverconstrainedError",
TrackStartError: "NotReadableError",
MediaDeviceFailedDueToShutdown: "NotAllowedError",
MediaDeviceKillSwitchOn: "NotAllowedError",
TabCaptureError: "AbortError",
ScreenCaptureError: "AbortError",
DeviceCaptureError: "AbortError"
}[c.name] || c.name,
message: c.message,
constraint: c.constraint || c.constraintName,
toString() {
return this.name + (this.message && ": ") + this.message;
}
};
}, o = function(c, a, l) {
n(c, (h) => {
e.webkitGetUserMedia(h, a, (u) => {
l && l(s(u));
});
});
};
if (e.getUserMedia = o.bind(e), e.mediaDevices.getUserMedia) {
const c = e.mediaDevices.getUserMedia.bind(e.mediaDevices);
e.mediaDevices.getUserMedia = function(a) {
return n(a, (l) => c(l).then((h) => {
if (l.audio && !h.getAudioTracks().length || l.video && !h.getVideoTracks().length)
throw h.getTracks(