@decartai/sdk 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -9
- package/dist/create-client.js +102 -0
- package/dist/files/types.js +4 -1
- package/dist/package.js +4 -0
- package/dist/process/types.d.ts +1 -1
- package/dist/realtime/browser/frame-metadata-diagnostics.js +90 -0
- package/dist/realtime/browser/frame-metadata-worker.js +2 -0
- package/dist/realtime/browser/mirror-stream.js +1 -1
- package/dist/realtime/browser/preflight.js +6 -7
- package/dist/realtime/browser/prepare-connection.js +27 -9
- package/dist/realtime/client.js +9 -0
- package/dist/realtime/config-realtime.js +51 -0
- package/dist/realtime/livekit.js +1 -1
- package/dist/realtime/media-channel.js +28 -6
- package/dist/realtime/methods.js +4 -0
- package/dist/realtime/observability/connection-quality.d.ts +3 -3
- package/dist/realtime/observability/connection-quality.js +3 -1
- package/dist/realtime/observability/realtime-observability.js +2 -16
- package/dist/realtime/observability/webrtc-stats.d.ts +3 -3
- package/dist/realtime/signaling-channel.js +3 -1
- package/dist/realtime/stream-session.js +4 -2
- package/dist/realtime/subscribe-client.js +1 -1
- package/dist/shared/model.d.ts +1 -1
- package/dist/shared/model.js +28 -1
- package/dist/shared/types.d.ts +1 -1
- package/dist/shared/types.js +6 -0
- package/dist/utils/errors.js +1 -1
- package/dist/utils/media.js +1 -1
- package/dist/utils/user-agent.js +1 -1
- package/dist/version.js +9 -4
- package/package.json +1 -1
- package/dist/realtime/browser/glass-to-glass-diagnostics.js +0 -27
- package/dist/realtime/browser/glass-to-glass.js +0 -212
- package/dist/realtime/browser/pixel-marker.js +0 -144
package/README.md
CHANGED
|
@@ -164,23 +164,38 @@ realtimeClient.on("connectionQuality", (report) => { /* ... */ });
|
|
|
164
164
|
realtimeClient.getConnectionQuality(); // latest report, or null before the first sample
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
+
> `onConnectionQuality` and the `connectionQuality` event are **debounced** — they only re-fire
|
|
168
|
+
> when the verdict (`quality`/`limitingFactor`) changes, so they're not a live metrics feed. For a
|
|
169
|
+
> continuous read of the raw numbers, updated every stats tick (~1/s), use the `stats` event or
|
|
170
|
+
> poll `getConnectionQuality()?.metrics`:
|
|
171
|
+
>
|
|
172
|
+
> ```typescript
|
|
173
|
+
> realtimeClient.on("stats", (s) => updateLatencyHud(s.glassToGlass?.medianMs, s.video?.framesPerSecond));
|
|
174
|
+
> // or, on your own interval:
|
|
175
|
+
> setInterval(() => console.log(realtimeClient.getConnectionQuality()?.metrics.g2gMs), 1000);
|
|
176
|
+
> ```
|
|
177
|
+
|
|
167
178
|
**Glass-to-glass latency (opt-in, diagnostic).** Network RTT hides the dominant cost in
|
|
168
179
|
real-time video — model inference — so a session can read "good" while actually feeling laggy.
|
|
169
|
-
Set `debugQuality: true` to measure the *real* camera→display latency
|
|
170
|
-
|
|
171
|
-
(`ttffMs`) and **steady-state**
|
|
172
|
-
When present, glass-to-glass drives the latency verdict instead of RTT.
|
|
180
|
+
Set `debugQuality: true` to measure the *real* camera→display latency. The SDK attaches a capture
|
|
181
|
+
timestamp using LiveKit frame metadata; the server propagates it through inference and the SDK
|
|
182
|
+
matches it to output playout. This surfaces **startup** (`ttffMs`) and **steady-state**
|
|
183
|
+
(`g2gMs`) latency. When present, glass-to-glass drives the latency verdict instead of RTT.
|
|
173
184
|
|
|
174
|
-
>
|
|
175
|
-
>
|
|
185
|
+
> Frame metadata is currently experimental in LiveKit and requires encoded-transform support.
|
|
186
|
+
> It does not alter visible pixels. `g2gDropRatio` remains `null` until frame IDs are propagated
|
|
187
|
+
> through the server pipeline as well as timestamps.
|
|
176
188
|
|
|
177
189
|
```typescript
|
|
178
190
|
const realtimeClient = await client.realtime.connect(stream, {
|
|
179
191
|
model,
|
|
180
192
|
debugQuality: true,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// g2g updates every stats tick — read it from the `stats` event (the
|
|
196
|
+
// `connectionQuality` verdict is debounced and would go stale between changes):
|
|
197
|
+
realtimeClient.on("stats", ({ glassToGlass }) => {
|
|
198
|
+
console.log(glassToGlass?.ttffMs, glassToGlass?.medianMs);
|
|
184
199
|
});
|
|
185
200
|
```
|
|
186
201
|
|
package/dist/create-client.js
CHANGED
|
@@ -94,11 +94,113 @@ const createDecartClientForPlatform = (createRealtime, options = {}) => {
|
|
|
94
94
|
realtime: {
|
|
95
95
|
connect: realtime.connect,
|
|
96
96
|
subscribe: realtime.subscribe,
|
|
97
|
+
/**
|
|
98
|
+
* Check whether the user's network can support a real-time session
|
|
99
|
+
* *before* connecting — so you can gate showing the integration.
|
|
100
|
+
*
|
|
101
|
+
* Default (STUN-only): validates WebRTC reachability (UDP egress / TURN
|
|
102
|
+
* need) and approximate latency via a throwaway peer connection — no
|
|
103
|
+
* session, instant. Opt-in deep probe (`{ deep: true, model }`): briefly
|
|
104
|
+
* opens a real session with a synthetic source and measures *true*
|
|
105
|
+
* glass-to-glass latency (plus upstream loss/jitter),
|
|
106
|
+
* then tears it down — accurate, but costs a short GPU session.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* // Fast, pre-session reachability check
|
|
111
|
+
* const { quality, reasons } = await client.realtime.checkConnectivity();
|
|
112
|
+
* if (quality === "critical") showFallbackUI(reasons);
|
|
113
|
+
*
|
|
114
|
+
* // Accurate, measured glass-to-glass verdict
|
|
115
|
+
* const probe = await client.realtime.checkConnectivity({ deep: true, model: models.realtime("lucy-restyle-2") });
|
|
116
|
+
* console.log(probe.metrics.g2gMs);
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
97
119
|
checkConnectivity: realtime.checkConnectivity
|
|
98
120
|
},
|
|
121
|
+
/**
|
|
122
|
+
* Client for synchronous image generation.
|
|
123
|
+
* Only image models support the sync/process API.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const client = createDecartClient({ apiKey: "your-api-key" });
|
|
128
|
+
* const result = await client.process({
|
|
129
|
+
* model: models.image("lucy-pro-i2i"),
|
|
130
|
+
* prompt: "Transform into anime style",
|
|
131
|
+
* data: imageBlob
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
99
135
|
process,
|
|
136
|
+
/**
|
|
137
|
+
* Client for queue-based async video generation.
|
|
138
|
+
* Only video models support the queue API.
|
|
139
|
+
* Jobs are submitted and processed asynchronously.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* const client = createDecartClient({ apiKey: "your-api-key" });
|
|
144
|
+
*
|
|
145
|
+
* // Option 1: Submit and poll automatically
|
|
146
|
+
* const result = await client.queue.submitAndPoll({
|
|
147
|
+
* model: models.video("lucy-pro-v2v"),
|
|
148
|
+
* prompt: "Transform into anime style",
|
|
149
|
+
* data: videoBlob,
|
|
150
|
+
* onStatusChange: (job) => console.log(`Job ${job.job_id}: ${job.status}`)
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Option 2: Submit and poll manually
|
|
154
|
+
* const job = await client.queue.submit({
|
|
155
|
+
* model: models.video("lucy-pro-v2v"),
|
|
156
|
+
* prompt: "Transform into anime style",
|
|
157
|
+
* data: videoBlob
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* // Poll until completion
|
|
161
|
+
* while (true) {
|
|
162
|
+
* const status = await client.queue.status(job.job_id);
|
|
163
|
+
* console.log(`Job ${status.job_id}: ${status.status}`);
|
|
164
|
+
*
|
|
165
|
+
* if (status.status === "completed") {
|
|
166
|
+
* const blob = await client.queue.result(job.job_id);
|
|
167
|
+
* break;
|
|
168
|
+
* }
|
|
169
|
+
* if (status.status === "failed") {
|
|
170
|
+
* throw new Error("Job failed");
|
|
171
|
+
* }
|
|
172
|
+
* await new Promise(resolve => setTimeout(resolve, 1500));
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
100
176
|
queue,
|
|
177
|
+
/**
|
|
178
|
+
* Client for creating client tokens.
|
|
179
|
+
* Client tokens are short-lived API keys safe for client-side use.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* // Server-side: Create a client token
|
|
184
|
+
* const serverClient = createDecartClient({ apiKey: process.env.DECART_API_KEY });
|
|
185
|
+
* const token = await serverClient.tokens.create();
|
|
186
|
+
* // Returns: { apiKey: "ek_...", expiresAt: "2024-12-15T12:10:00Z" }
|
|
187
|
+
*
|
|
188
|
+
* // Client-side: Use the client token
|
|
189
|
+
* const client = createDecartClient({ apiKey: token.apiKey });
|
|
190
|
+
* const realtimeClient = await client.realtime.connect(stream, options);
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
101
193
|
tokens,
|
|
194
|
+
/**
|
|
195
|
+
* Upload files once and reuse them across generations.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* const ref = await client.files.upload(blob);
|
|
200
|
+
* await rt.set({ image: ref.id, prompt: "make it cinematic" });
|
|
201
|
+
* await rt.set({ image: ref.id, prompt: "now in noir" });
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
102
204
|
files
|
|
103
205
|
};
|
|
104
206
|
};
|
package/dist/files/types.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
//#region src/files/types.ts
|
|
2
|
+
/** Prefix on every uploaded-file id; disambiguates a ref string from base64. */
|
|
3
|
+
const FILE_REF_PREFIX = "file_";
|
|
1
4
|
/** True if `value` is a `"file_..."` reference id from `client.files.upload(...)`. */
|
|
2
5
|
const isFileRefId = (value) => typeof value === "string" && value.startsWith("file_");
|
|
3
6
|
//#endregion
|
|
4
|
-
export { isFileRefId };
|
|
7
|
+
export { FILE_REF_PREFIX, isFileRefId };
|
package/dist/package.js
ADDED
package/dist/process/types.d.ts
CHANGED
|
@@ -224,4 +224,4 @@ type ProcessOptions<T extends ImageModelDefinition = ImageModelDefinition> = {
|
|
|
224
224
|
signal?: AbortSignal;
|
|
225
225
|
} & MergeDocumentedInputs<T>;
|
|
226
226
|
//#endregion
|
|
227
|
-
export { FileInput, InferModelInputs, ModelSpecificInputs, ProcessInputs, ProcessOptions, ReactNativeFile };
|
|
227
|
+
export { FileInput, ImageEditingInputs, ImageGenerationInputs, InferModelInputs, ModelSpecificInputs, ProcessInputs, ProcessOptions, PromptInput, ReactNativeFile, VideoEdit2Inputs, VideoEditInputs, VideoModelInputs, VideoRestyleInputs };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region src/realtime/browser/frame-metadata-diagnostics.ts
|
|
2
|
+
const LATENCY_WINDOW = 300;
|
|
3
|
+
const MID_STREAM_WARMUP_MS = 2e3;
|
|
4
|
+
const MAX_PLAUSIBLE_MS = 6e4;
|
|
5
|
+
/**
|
|
6
|
+
* Collects glass-to-glass latency from LiveKit frame metadata. Both the
|
|
7
|
+
* publisher timestamp and the receiver synchronization-source timestamp are
|
|
8
|
+
* wall-clock values, so they can be compared without client/server clock sync.
|
|
9
|
+
*/
|
|
10
|
+
var FrameMetadataTracker = class {
|
|
11
|
+
latencies = [];
|
|
12
|
+
startMs = null;
|
|
13
|
+
firstFrameMs = null;
|
|
14
|
+
ttffMs = null;
|
|
15
|
+
markStart(nowMs) {
|
|
16
|
+
this.reset();
|
|
17
|
+
this.startMs = nowMs;
|
|
18
|
+
}
|
|
19
|
+
recordFrame(userTimestampUs, playoutTimeMs) {
|
|
20
|
+
if (userTimestampUs <= 0n) return;
|
|
21
|
+
const latencyMs = playoutTimeMs - Number(userTimestampUs) / 1e3;
|
|
22
|
+
if (!Number.isFinite(latencyMs) || latencyMs < 0 || latencyMs > MAX_PLAUSIBLE_MS) return;
|
|
23
|
+
if (this.firstFrameMs === null) {
|
|
24
|
+
this.firstFrameMs = playoutTimeMs;
|
|
25
|
+
if (this.startMs !== null) this.ttffMs = Math.round(playoutTimeMs - this.startMs);
|
|
26
|
+
}
|
|
27
|
+
if (playoutTimeMs < this.firstFrameMs + MID_STREAM_WARMUP_MS) return;
|
|
28
|
+
this.latencies.push(latencyMs);
|
|
29
|
+
if (this.latencies.length > LATENCY_WINDOW) this.latencies.shift();
|
|
30
|
+
}
|
|
31
|
+
snapshot() {
|
|
32
|
+
const sorted = [...this.latencies].sort((a, b) => a - b);
|
|
33
|
+
const n = sorted.length;
|
|
34
|
+
const medianMs = n === 0 ? null : n % 2 === 0 ? Math.round((sorted[n / 2 - 1] + sorted[n / 2]) / 2) : Math.round(sorted[(n - 1) / 2]);
|
|
35
|
+
const p90Ms = n === 0 ? null : Math.round(sorted[Math.min(n - 1, Math.floor(.9 * n))]);
|
|
36
|
+
return {
|
|
37
|
+
ttffMs: this.ttffMs,
|
|
38
|
+
medianMs,
|
|
39
|
+
p90Ms,
|
|
40
|
+
sampleCount: n,
|
|
41
|
+
dropRatio: null
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
reset() {
|
|
45
|
+
this.latencies.length = 0;
|
|
46
|
+
this.startMs = null;
|
|
47
|
+
this.firstFrameMs = null;
|
|
48
|
+
this.ttffMs = null;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const TIME_SYNC_UPDATE = "timeSyncUpdate";
|
|
52
|
+
function createFrameReader(tracker) {
|
|
53
|
+
let attachedTrack = null;
|
|
54
|
+
const onTimeSyncUpdate = ({ timestamp, rtpTimestamp }) => {
|
|
55
|
+
const frameMetadata = attachedTrack?.lookupFrameMetadata({ rtpTimestamp });
|
|
56
|
+
if (frameMetadata) tracker.recordFrame(frameMetadata.userTimestamp, performance.timeOrigin + timestamp);
|
|
57
|
+
};
|
|
58
|
+
const detach = () => {
|
|
59
|
+
attachedTrack?.off(TIME_SYNC_UPDATE, onTimeSyncUpdate);
|
|
60
|
+
attachedTrack = null;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
attach: (track) => {
|
|
64
|
+
if (track === attachedTrack) return;
|
|
65
|
+
detach();
|
|
66
|
+
attachedTrack = track;
|
|
67
|
+
track.on(TIME_SYNC_UPDATE, onTimeSyncUpdate);
|
|
68
|
+
},
|
|
69
|
+
detach,
|
|
70
|
+
dispose: detach
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function createBrowserFrameMetadataDiagnostics() {
|
|
74
|
+
const tracker = new FrameMetadataTracker();
|
|
75
|
+
const reader = createFrameReader(tracker);
|
|
76
|
+
return {
|
|
77
|
+
attachRemoteVideoTrack: (track) => reader.attach(track),
|
|
78
|
+
markStart: () => {
|
|
79
|
+
reader.detach();
|
|
80
|
+
tracker.markStart(performance.timeOrigin + performance.now());
|
|
81
|
+
},
|
|
82
|
+
snapshot: () => tracker.snapshot(),
|
|
83
|
+
dispose: () => reader.dispose()
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function createFrameMetadataWorker() {
|
|
87
|
+
return new Worker(new URL("./frame-metadata-worker.js", import.meta.url));
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
export { FrameMetadataTracker, createBrowserFrameMetadataDiagnostics, createFrameMetadataWorker };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t){if(!e)throw new Error(t)}function t(e){if("number"!=typeof e)throw new Error("invalid int 32: "+typeof e);if(!Number.isInteger(e)||e>2147483647||e<-2147483648)throw new Error("invalid int 32: "+e)}function n(e){if("number"!=typeof e)throw new Error("invalid uint 32: "+typeof e);if(!Number.isInteger(e)||e>4294967295||e<0)throw new Error("invalid uint 32: "+e)}function r(e){if("number"!=typeof e)throw new Error("invalid float 32: "+typeof e);if(Number.isFinite(e)&&(e>34028234663852886e22||e<-34028234663852886e22))throw new Error("invalid float 32: "+e)}const i=Symbol("@bufbuild/protobuf/enum-type");function a(t){const n=t[i];return e(n,"missing enum type on enum object"),n}function o(e,t,n,r){e[i]=s(t,n.map((t=>({no:t.no,name:t.name,localName:e[t.no]}))))}function s(e,t,n){const r=Object.create(null),i=Object.create(null),a=[];for(const e of t){const t=u(e);a.push(t),r[e.name]=t,i[e.no]=t}return{typeName:e,values:a,findName:e=>r[e],findNumber:e=>i[e]}}function c(e,t,n){const r={};for(const e of t){const t=u(e);r[t.localName]=t.no,r[t.no]=t.localName}return o(r,e,t),r}function u(e){return"localName"in e?e:Object.assign(Object.assign({},e),{localName:e.name})}class l{equals(e){return this.getType().runtime.util.equals(this.getType(),this,e)}clone(){return this.getType().runtime.util.clone(this)}fromBinary(e,t){const n=this.getType().runtime.bin,r=n.makeReadOptions(t);return n.readMessage(this,r.readerFactory(e),e.byteLength,r),this}fromJson(e,t){const n=this.getType(),r=n.runtime.json,i=r.makeReadOptions(t);return r.readMessage(n,e,i,this),this}fromJsonString(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error("cannot decode ".concat(this.getType().typeName," from JSON: ").concat(e instanceof Error?e.message:String(e)))}return this.fromJson(n,t)}toBinary(e){const t=this.getType().runtime.bin,n=t.makeWriteOptions(e),r=n.writerFactory();return t.writeMessage(this,r,n),r.finish()}toJson(e){const t=this.getType().runtime.json,n=t.makeWriteOptions(e);return t.writeMessage(this,n)}toJsonString(e){var t;const n=this.toJson(e);return JSON.stringify(n,null,null!==(t=null==e?void 0:e.prettySpaces)&&void 0!==t?t:0)}toJSON(){return this.toJson({emitDefaultValues:!0})}getType(){return Object.getPrototypeOf(this).constructor}}function d(){let e=0,t=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,!(128&r))return this.assertBounds(),[e,t]}let n=this.buf[this.pos++];if(e|=(15&n)<<28,t=(112&n)>>4,!(128&n))return this.assertBounds(),[e,t];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,!(128&r))return this.assertBounds(),[e,t]}throw new Error("invalid varint")}function f(e,t,n){for(let r=0;r<28;r+=7){const i=e>>>r,a=!(i>>>7==0&&0==t),o=255&(a?128|i:i);if(n.push(o),!a)return}const r=e>>>28&15|(7&t)<<4,i=!!(t>>3);if(n.push(255&(i?128|r:r)),i){for(let e=3;e<31;e+=7){const r=t>>>e,i=!(r>>>7==0),a=255&(i?128|r:r);if(n.push(a),!i)return}n.push(t>>>31&1)}}const h=4294967296;function p(e){const t="-"===e[0];t&&(e=e.slice(1));const n=1e6;let r=0,i=0;function a(t,a){const o=Number(e.slice(t,a));i*=n,r=r*n+o,r>=h&&(i+=r/h|0,r%=h)}return a(-24,-18),a(-18,-12),a(-12,-6),a(-6),t?b(r,i):g(r,i)}function m(e,t){var n=function(e,t){return{lo:e>>>0,hi:t>>>0}}(e,t);if(e=n.lo,(t=n.hi)<=2097151)return String(h*t+e);const r=16777215&(e>>>24|t<<8),i=t>>16&65535;let a=(16777215&e)+6777216*r+6710656*i,o=r+8147497*i,s=2*i;const c=1e7;return a>=c&&(o+=Math.floor(a/c),a%=c),o>=c&&(s+=Math.floor(o/c),o%=c),s.toString()+y(o)+y(a)}function g(e,t){return{lo:0|e,hi:0|t}}function b(e,t){return t=~t,e?e=1+~e:t+=1,g(e,t)}const y=e=>{const t=String(e);return"0000000".slice(t.length)+t};function v(e,t){if(e>=0){for(;e>127;)t.push(127&e|128),e>>>=7;t.push(e)}else{for(let n=0;n<9;n++)t.push(127&e|128),e>>=7;t.push(1)}}function k(){let e=this.buf[this.pos++],t=127&e;if(!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<7,!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<14,!(128&e))return this.assertBounds(),t;if(e=this.buf[this.pos++],t|=(127&e)<<21,!(128&e))return this.assertBounds(),t;e=this.buf[this.pos++],t|=(15&e)<<28;for(let t=5;128&e&&t<10;t++)e=this.buf[this.pos++];if(128&e)throw new Error("invalid varint");return this.assertBounds(),t>>>0}const w=function(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&("object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error("int64 invalid: ".concat(t));return r},uParse(e){const t="bigint"==typeof e?e:BigInt(e);if(t>i||t<r)throw new Error("uint64 invalid: ".concat(e));return t},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}const n=t=>e(/^-?[0-9]+$/.test(t),"int64 invalid: ".concat(t)),r=t=>e(/^[0-9]+$/.test(t),"uint64 invalid: ".concat(t));return{zero:"0",supported:!1,parse:e=>("string"!=typeof e&&(e=e.toString()),n(e),e),uParse:e=>("string"!=typeof e&&(e=e.toString()),r(e),e),enc:e=>("string"!=typeof e&&(e=e.toString()),n(e),p(e)),uEnc:e=>("string"!=typeof e&&(e=e.toString()),r(e),p(e)),dec:(e,t)=>function(e,t){let n=g(e,t);const r=2147483648&n.hi;r&&(n=b(n.lo,n.hi));const i=m(n.lo,n.hi);return r?"-"+i:i}(e,t),uDec:(e,t)=>m(e,t)}}();var T,S,E;function N(e,t,n){if(t===n)return!0;if(e==T.BYTES){if(!(t instanceof Uint8Array&&n instanceof Uint8Array))return!1;if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e]!==n[e])return!1;return!0}switch(e){case T.UINT64:case T.FIXED64:case T.INT64:case T.SFIXED64:case T.SINT64:return t==n}return!1}function I(e,t){switch(e){case T.BOOL:return!1;case T.UINT64:case T.FIXED64:case T.INT64:case T.SFIXED64:case T.SINT64:return 0==t?w.zero:"0";case T.DOUBLE:case T.FLOAT:return 0;case T.BYTES:return new Uint8Array(0);case T.STRING:return"";default:return 0}}function O(e,t){switch(e){case T.BOOL:return!1===t;case T.STRING:return""===t;case T.BYTES:return t instanceof Uint8Array&&!t.byteLength;default:return 0==t}}function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function A(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a,o,s=[],c=!0,u=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw i}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return C(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}!function(e){e[e.DOUBLE=1]="DOUBLE",e[e.FLOAT=2]="FLOAT",e[e.INT64=3]="INT64",e[e.UINT64=4]="UINT64",e[e.INT32=5]="INT32",e[e.FIXED64=6]="FIXED64",e[e.FIXED32=7]="FIXED32",e[e.BOOL=8]="BOOL",e[e.STRING=9]="STRING",e[e.BYTES=12]="BYTES",e[e.UINT32=13]="UINT32",e[e.SFIXED32=15]="SFIXED32",e[e.SFIXED64=16]="SFIXED64",e[e.SINT32=17]="SINT32",e[e.SINT64=18]="SINT64"}(T||(T={})),function(e){e[e.BIGINT=0]="BIGINT",e[e.STRING=1]="STRING"}(S||(S={})),function(e){e[e.Varint=0]="Varint",e[e.Bit64=1]="Bit64",e[e.LengthDelimited=2]="LengthDelimited",e[e.StartGroup=3]="StartGroup",e[e.EndGroup=4]="EndGroup",e[e.Bit32=5]="Bit32"}(E||(E={}));class U{constructor(e){this.stack=[],this.textEncoder=null!=e?e:new TextEncoder,this.chunks=[],this.buf=[]}finish(){this.chunks.push(new Uint8Array(this.buf));let e=0;for(let t=0;t<this.chunks.length;t++)e+=this.chunks[t].length;let t=new Uint8Array(e),n=0;for(let e=0;e<this.chunks.length;e++)t.set(this.chunks[e],n),n+=this.chunks[e].length;return this.chunks=[],t}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let e=this.finish(),t=this.stack.pop();if(!t)throw new Error("invalid state, fork stack empty");return this.chunks=t.chunks,this.buf=t.buf,this.uint32(e.byteLength),this.raw(e)}tag(e,t){return this.uint32((e<<3|t)>>>0)}raw(e){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(e),this}uint32(e){for(n(e);e>127;)this.buf.push(127&e|128),e>>>=7;return this.buf.push(e),this}int32(e){return t(e),v(e,this.buf),this}bool(e){return this.buf.push(e?1:0),this}bytes(e){return this.uint32(e.byteLength),this.raw(e)}string(e){let t=this.textEncoder.encode(e);return this.uint32(t.byteLength),this.raw(t)}float(e){r(e);let t=new Uint8Array(4);return new DataView(t.buffer).setFloat32(0,e,!0),this.raw(t)}double(e){let t=new Uint8Array(8);return new DataView(t.buffer).setFloat64(0,e,!0),this.raw(t)}fixed32(e){n(e);let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e,!0),this.raw(t)}sfixed32(e){t(e);let n=new Uint8Array(4);return new DataView(n.buffer).setInt32(0,e,!0),this.raw(n)}sint32(e){return t(e),v(e=(e<<1^e>>31)>>>0,this.buf),this}sfixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=w.enc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}fixed64(e){let t=new Uint8Array(8),n=new DataView(t.buffer),r=w.uEnc(e);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(t)}int64(e){let t=w.enc(e);return f(t.lo,t.hi,this.buf),this}sint64(e){let t=w.enc(e),n=t.hi>>31;return f(t.lo<<1^n,(t.hi<<1|t.lo>>>31)^n,this.buf),this}uint64(e){let t=w.uEnc(e);return f(t.lo,t.hi,this.buf),this}}class L{constructor(e,t){this.varint64=d,this.uint32=k,this.buf=e,this.len=e.length,this.pos=0,this.view=new DataView(e.buffer,e.byteOffset,e.byteLength),this.textDecoder=null!=t?t:new TextDecoder}tag(){let e=this.uint32(),t=e>>>3,n=7&e;if(t<=0||n<0||n>5)throw new Error("illegal tag: field no "+t+" wire type "+n);return[t,n]}skip(e,t){let n=this.pos;switch(e){case E.Varint:for(;128&this.buf[this.pos++];);break;case E.Bit64:this.pos+=4;case E.Bit32:this.pos+=4;break;case E.LengthDelimited:let n=this.uint32();this.pos+=n;break;case E.StartGroup:for(;;){const e=A(this.tag(),2),n=e[0],r=e[1];if(r===E.EndGroup){if(void 0!==t&&n!==t)throw new Error("invalid end group tag");break}this.skip(r,n)}break;default:throw new Error("cant skip wire type "+e)}return this.assertBounds(),this.buf.subarray(n,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let e=this.uint32();return e>>>1^-(1&e)}int64(){return w.dec(...this.varint64())}uint64(){return w.uDec(...this.varint64())}sint64(){let e=A(this.varint64(),2),t=e[0],n=e[1],r=-(1&t);return t=(t>>>1|(1&n)<<31)^r,n=n>>>1^r,w.dec(t,n)}bool(){let e=A(this.varint64(),2),t=e[0],n=e[1];return 0!==t||0!==n}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return w.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return w.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let e=this.uint32(),t=this.pos;return this.pos+=e,this.assertBounds(),this.buf.subarray(t,t+e)}string(){return this.textDecoder.decode(this.bytes())}}function F(e){const t=e.field.localName,n=Object.create(null);return n[t]=function(e){const t=e.field;if(t.repeated)return[];if(void 0!==t.default)return t.default;switch(t.kind){case"enum":return t.T.values[0].no;case"scalar":return I(t.T,t.L);case"message":const e=t.T,n=new e;return e.fieldWrapper?e.fieldWrapper.unwrapField(n):n;case"map":throw"map fields are not allowed to be extensions"}}(e),[n,()=>n[t]]}let D="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),R=[];for(let e=0;e<D.length;e++)R[D[e].charCodeAt(0)]=e;R["-".charCodeAt(0)]=D.indexOf("+"),R["_".charCodeAt(0)]=D.indexOf("/");const B={dec(e){let t=3*e.length/4;"="==e[e.length-2]?t-=2:"="==e[e.length-1]&&(t-=1);let n,r=new Uint8Array(t),i=0,a=0,o=0;for(let t=0;t<e.length;t++){if(n=R[e.charCodeAt(t)],void 0===n)switch(e[t]){case"=":a=0;case"\n":case"\r":case"\t":case" ":continue;default:throw Error("invalid base64 string.")}switch(a){case 0:o=n,a=1;break;case 1:r[i++]=o<<2|(48&n)>>4,o=n,a=2;break;case 2:r[i++]=(15&o)<<4|(60&n)>>2,o=n,a=3;break;case 3:r[i++]=(3&o)<<6|n,a=0}}if(1==a)throw Error("invalid base64 string.");return r.subarray(0,i)},enc(e){let t,n="",r=0,i=0;for(let a=0;a<e.length;a++)switch(t=e[a],r){case 0:n+=D[t>>2],i=(3&t)<<4,r=1;break;case 1:n+=D[i|t>>4],i=(15&t)<<2,r=2;break;case 2:n+=D[i|t>>6],n+=D[63&t],r=0}return r&&(n+=D[i],n+="=",1==r&&(n+="=")),n}};function P(e,t,n){M(t,e);const r=t.runtime.bin.makeReadOptions(n),i=function(e,t){if(!t.repeated&&("enum"==t.kind||"scalar"==t.kind)){for(let n=e.length-1;n>=0;--n)if(e[n].no==t.no)return[e[n]];return[]}return e.filter((e=>e.no===t.no))}(e.getType().runtime.bin.listUnknownFields(e),t.field),a=A(F(t),2),o=a[0],s=a[1];for(const e of i)t.runtime.bin.readField(o,r.readerFactory(e.data),t.field,e.wireType,r);return s()}function x(e,t,n,r){M(t,e);const i=t.runtime.bin.makeReadOptions(r),a=t.runtime.bin.makeWriteOptions(r);if(j(e,t)){const n=e.getType().runtime.bin.listUnknownFields(e).filter((e=>e.no!=t.field.no));e.getType().runtime.bin.discardUnknownFields(e);for(const t of n)e.getType().runtime.bin.onUnknownField(e,t.no,t.wireType,t.data)}const o=a.writerFactory();let s=t.field;s.opt||s.repeated||"enum"!=s.kind&&"scalar"!=s.kind||(s=Object.assign(Object.assign({},t.field),{opt:!0})),t.runtime.bin.writeField(s,n,o,a);const c=i.readerFactory(o.finish());for(;c.pos<c.len;){const t=A(c.tag(),2),n=t[0],r=t[1],i=c.skip(r,n);e.getType().runtime.bin.onUnknownField(e,n,r,i)}}function j(e,t){const n=e.getType();return t.extendee.typeName===n.typeName&&!!n.runtime.bin.listUnknownFields(e).find((e=>e.no==t.field.no))}function M(t,n){e(t.extendee.typeName==n.getType().typeName,"extension ".concat(t.typeName," can only be applied to message ").concat(t.extendee.typeName))}function V(e,t){const n=e.localName;if(e.repeated)return t[n].length>0;if(e.oneof)return t[e.oneof.localName].case===n;switch(e.kind){case"enum":case"scalar":return e.opt||e.req?void 0!==t[n]:"enum"==e.kind?t[n]!==e.T.values[0].no:!O(e.T,t[n]);case"message":return void 0!==t[n];case"map":return Object.keys(t[n]).length>0}}function _(e,t){const n=e.localName,r=!e.opt&&!e.req;if(e.repeated)t[n]=[];else if(e.oneof)t[e.oneof.localName]={case:void 0};else switch(e.kind){case"map":t[n]={};break;case"enum":t[n]=r?e.T.values[0].no:void 0;break;case"scalar":t[n]=r?I(e.T,e.L):void 0;break;case"message":t[n]=void 0}}function J(e,t){if(null===e||"object"!=typeof e)return!1;if(!Object.getOwnPropertyNames(l.prototype).every((t=>t in e&&"function"==typeof e[t])))return!1;const n=e.getType();return null!==n&&"function"==typeof n&&"typeName"in n&&"string"==typeof n.typeName&&(void 0===t||n.typeName==t.typeName)}function G(e,t){return J(t)||!e.fieldWrapper?t:e.fieldWrapper.wrapField(t)}T.DOUBLE,T.FLOAT,T.INT64,T.UINT64,T.INT32,T.UINT32,T.BOOL,T.STRING,T.BYTES;const X={ignoreUnknownFields:!1},q={emitDefaultValues:!1,enumAsInteger:!1,useProtoFieldName:!1,prettySpaces:0};function W(e){return e?Object.assign(Object.assign({},X),e):X}function H(e){return e?Object.assign(Object.assign({},q),e):q}const Y=Symbol(),K=Symbol();function Q(e){if(null===e)return"null";switch(typeof e){case"object":return Array.isArray(e)?"array":"object";case"string":return e.length>100?"string":'"'.concat(e.split('"').join('\\"'),'"');default:return String(e)}}function z(t,n,r,i,a){let o=r.localName;if(r.repeated){if(e("map"!=r.kind),null===n)return;if(!Array.isArray(n))throw new Error("cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(n)));const s=t[o];for(const e of n){if(null===e)throw new Error("cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(e)));switch(r.kind){case"message":s.push(r.T.fromJson(e,i));break;case"enum":const t=ee(r.T,e,i.ignoreUnknownFields,!0);t!==K&&s.push(t);break;case"scalar":try{s.push(Z(r.T,e,r.L,!0))}catch(t){let n="cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(e));throw t instanceof Error&&t.message.length>0&&(n+=": ".concat(t.message)),new Error(n)}}}}else if("map"==r.kind){if(null===n)return;if("object"!=typeof n||Array.isArray(n))throw new Error("cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(n)));const e=t[o];for(const t of Object.entries(n)){var s=A(t,2);const o=s[0],c=s[1];if(null===c)throw new Error("cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: map value null"));let u;try{u=$(r.K,o)}catch(e){let t="cannot decode map key for field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(n));throw e instanceof Error&&e.message.length>0&&(t+=": ".concat(e.message)),new Error(t)}switch(r.V.kind){case"message":e[u]=r.V.T.fromJson(c,i);break;case"enum":const t=ee(r.V.T,c,i.ignoreUnknownFields,!0);t!==K&&(e[u]=t);break;case"scalar":try{e[u]=Z(r.V.T,c,S.BIGINT,!0)}catch(e){let t="cannot decode map value for field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(n));throw e instanceof Error&&e.message.length>0&&(t+=": ".concat(e.message)),new Error(t)}}}}else switch(r.oneof&&(t=t[r.oneof.localName]={case:o},o="value"),r.kind){case"message":const e=r.T;if(null===n&&"google.protobuf.Value"!=e.typeName)return;let s=t[o];J(s)?s.fromJson(n,i):(t[o]=s=e.fromJson(n,i),e.fieldWrapper&&!r.oneof&&(t[o]=e.fieldWrapper.unwrapField(s)));break;case"enum":const c=ee(r.T,n,i.ignoreUnknownFields,!1);switch(c){case Y:_(r,t);break;case K:break;default:t[o]=c}break;case"scalar":try{const e=Z(r.T,n,r.L,!1);if(e===Y)_(r,t);else t[o]=e}catch(e){let t="cannot decode field ".concat(a.typeName,".").concat(r.name," from JSON: ").concat(Q(n));throw e instanceof Error&&e.message.length>0&&(t+=": ".concat(e.message)),new Error(t)}}}function $(e,t){if(e===T.BOOL)switch(t){case"true":t=!0;break;case"false":t=!1}return Z(e,t,S.BIGINT,!0).toString()}function Z(e,i,a,o){if(null===i)return o?I(e,a):Y;switch(e){case T.DOUBLE:case T.FLOAT:if("NaN"===i)return Number.NaN;if("Infinity"===i)return Number.POSITIVE_INFINITY;if("-Infinity"===i)return Number.NEGATIVE_INFINITY;if(""===i)break;if("string"==typeof i&&i.trim().length!==i.length)break;if("string"!=typeof i&&"number"!=typeof i)break;const o=Number(i);if(Number.isNaN(o))break;if(!Number.isFinite(o))break;return e==T.FLOAT&&r(o),o;case T.INT32:case T.FIXED32:case T.SFIXED32:case T.SINT32:case T.UINT32:let s;if("number"==typeof i?s=i:"string"==typeof i&&i.length>0&&i.trim().length===i.length&&(s=Number(i)),void 0===s)break;return e==T.UINT32||e==T.FIXED32?n(s):t(s),s;case T.INT64:case T.SFIXED64:case T.SINT64:if("number"!=typeof i&&"string"!=typeof i)break;const c=w.parse(i);return a?c.toString():c;case T.FIXED64:case T.UINT64:if("number"!=typeof i&&"string"!=typeof i)break;const u=w.uParse(i);return a?u.toString():u;case T.BOOL:if("boolean"!=typeof i)break;return i;case T.STRING:if("string"!=typeof i)break;try{encodeURIComponent(i)}catch(e){throw new Error("invalid UTF8")}return i;case T.BYTES:if(""===i)return new Uint8Array(0);if("string"!=typeof i)break;return B.dec(i)}throw new Error}function ee(e,t,n,r){if(null===t)return"google.protobuf.NullValue"==e.typeName?0:r?e.values[0].no:Y;switch(typeof t){case"number":if(Number.isInteger(t))return t;break;case"string":const r=e.findName(t);if(void 0!==r)return r.no;if(n)return K}throw new Error("cannot decode enum ".concat(e.typeName," from JSON: ").concat(Q(t)))}function te(e){return!(!e.repeated&&"map"!=e.kind)||!e.oneof&&("message"!=e.kind&&(!e.opt&&!e.req))}function ne(t,n,r){if("map"==t.kind){e("object"==typeof n&&null!=n);const s={},c=Object.entries(n);switch(t.V.kind){case"scalar":for(const e of c){var i=A(e,2);const n=i[0],r=i[1];s[n.toString()]=ie(t.V.T,r)}break;case"message":for(const e of c){var a=A(e,2);const t=a[0],n=a[1];s[t.toString()]=n.toJson(r)}break;case"enum":const e=t.V.T;for(const t of c){var o=A(t,2);const n=o[0],i=o[1];s[n.toString()]=re(e,i,r.enumAsInteger)}}return r.emitDefaultValues||c.length>0?s:void 0}if(t.repeated){e(Array.isArray(n));const i=[];switch(t.kind){case"scalar":for(let e=0;e<n.length;e++)i.push(ie(t.T,n[e]));break;case"enum":for(let e=0;e<n.length;e++)i.push(re(t.T,n[e],r.enumAsInteger));break;case"message":for(let e=0;e<n.length;e++)i.push(n[e].toJson(r))}return r.emitDefaultValues||i.length>0?i:void 0}switch(t.kind){case"scalar":return ie(t.T,n);case"enum":return re(t.T,n,r.enumAsInteger);case"message":return G(t.T,n).toJson(r)}}function re(t,n,r){var i;if(e("number"==typeof n),"google.protobuf.NullValue"==t.typeName)return null;if(r)return n;const a=t.findNumber(n);return null!==(i=null==a?void 0:a.name)&&void 0!==i?i:n}function ie(t,n){switch(t){case T.INT32:case T.SFIXED32:case T.SINT32:case T.FIXED32:case T.UINT32:return e("number"==typeof n),n;case T.FLOAT:case T.DOUBLE:return e("number"==typeof n),Number.isNaN(n)?"NaN":n===Number.POSITIVE_INFINITY?"Infinity":n===Number.NEGATIVE_INFINITY?"-Infinity":n;case T.STRING:return e("string"==typeof n),n;case T.BOOL:return e("boolean"==typeof n),n;case T.UINT64:case T.FIXED64:case T.INT64:case T.SFIXED64:case T.SINT64:return e("bigint"==typeof n||"string"==typeof n||"number"==typeof n),n.toString();case T.BYTES:return e(n instanceof Uint8Array),B.enc(n)}}const ae=Symbol("@bufbuild/protobuf/unknown-fields"),oe={readUnknownFields:!0,readerFactory:e=>new L(e)},se={writeUnknownFields:!0,writerFactory:()=>new U};function ce(e){return e?Object.assign(Object.assign({},oe),e):oe}function ue(e){return e?Object.assign(Object.assign({},se),e):se}function le(e,t,n,r,i){let a=n.repeated,o=n.localName;switch(n.oneof&&((e=e[n.oneof.localName]).case!=o&&delete e.value,e.case=o,o="value"),n.kind){case"scalar":case"enum":const s="enum"==n.kind?T.INT32:n.T;let c=he;if("scalar"==n.kind&&n.L>0&&(c=fe),a){let n=e[o];if(r==E.LengthDelimited&&s!=T.STRING&&s!=T.BYTES){let e=t.uint32()+t.pos;for(;t.pos<e;)n.push(c(t,s))}else n.push(c(t,s))}else e[o]=c(t,s);break;case"message":const u=n.T;a?e[o].push(de(t,new u,i,n)):J(e[o])?de(t,e[o],i,n):(e[o]=de(t,new u,i,n),!u.fieldWrapper||n.oneof||n.repeated||(e[o]=u.fieldWrapper.unwrapField(e[o])));break;case"map":let l=function(e,t,n){const r=t.uint32(),i=t.pos+r;let a,o;for(;t.pos<i;){switch(A(t.tag(),1)[0]){case 1:a=he(t,e.K);break;case 2:switch(e.V.kind){case"scalar":o=he(t,e.V.T);break;case"enum":o=t.int32();break;case"message":o=de(t,new e.V.T,n,void 0)}}}void 0===a&&(a=I(e.K,S.BIGINT));"string"!=typeof a&&"number"!=typeof a&&(a=a.toString());if(void 0===o)switch(e.V.kind){case"scalar":o=I(e.V.T,S.BIGINT);break;case"enum":o=e.V.T.values[0].no;break;case"message":o=new e.V.T}return[a,o]}(n,t,i),d=A(l,2),f=d[0],h=d[1];e[o][f]=h}}function de(e,t,n,r){const i=t.getType().runtime.bin,a=null==r?void 0:r.delimited;return i.readMessage(t,e,a?r.no:e.uint32(),n,a),t}function fe(e,t){const n=he(e,t);return"bigint"==typeof n?n.toString():n}function he(e,t){switch(t){case T.STRING:return e.string();case T.BOOL:return e.bool();case T.DOUBLE:return e.double();case T.FLOAT:return e.float();case T.INT32:return e.int32();case T.INT64:return e.int64();case T.UINT64:return e.uint64();case T.FIXED64:return e.fixed64();case T.BYTES:return e.bytes();case T.FIXED32:return e.fixed32();case T.SFIXED32:return e.sfixed32();case T.SFIXED64:return e.sfixed64();case T.SINT64:return e.sint64();case T.UINT32:return e.uint32();case T.SINT32:return e.sint32()}}function pe(t,n,r,i){e(void 0!==n);const a=t.repeated;switch(t.kind){case"scalar":case"enum":let s="enum"==t.kind?T.INT32:t.T;if(a)if(e(Array.isArray(n)),t.packed)!function(e,t,n,r){if(!r.length)return;e.tag(n,E.LengthDelimited).fork();let i=A(ye(t),2)[1];for(let t=0;t<r.length;t++)e[i](r[t]);e.join()}(r,s,t.no,n);else for(const e of n)be(r,s,t.no,e);else be(r,s,t.no,n);break;case"message":if(a){e(Array.isArray(n));for(const e of n)ge(r,i,t,e)}else ge(r,i,t,n);break;case"map":e("object"==typeof n&&null!=n);for(const e of Object.entries(n)){var o=A(e,2);me(r,i,t,o[0],o[1])}}}function me(t,n,r,i,a){t.tag(r.no,E.LengthDelimited),t.fork();let o=i;switch(r.K){case T.INT32:case T.FIXED32:case T.UINT32:case T.SFIXED32:case T.SINT32:o=Number.parseInt(i);break;case T.BOOL:e("true"==i||"false"==i),o="true"==i}switch(be(t,r.K,1,o),r.V.kind){case"scalar":be(t,r.V.T,2,a);break;case"enum":be(t,T.INT32,2,a);break;case"message":e(void 0!==a),t.tag(2,E.LengthDelimited).bytes(a.toBinary(n))}t.join()}function ge(e,t,n,r){const i=G(n.T,r);n.delimited?e.tag(n.no,E.StartGroup).raw(i.toBinary(t)).tag(n.no,E.EndGroup):e.tag(n.no,E.LengthDelimited).bytes(i.toBinary(t))}function be(t,n,r,i){e(void 0!==i);let a=A(ye(n),2),o=a[0],s=a[1];t.tag(r,o)[s](i)}function ye(e){let t=E.Varint;switch(e){case T.BYTES:case T.STRING:t=E.LengthDelimited;break;case T.DOUBLE:case T.FIXED64:case T.SFIXED64:t=E.Bit64;break;case T.FIXED32:case T.SFIXED32:case T.FLOAT:t=E.Bit32}return[t,T[e].toLowerCase()]}function ve(e){if(void 0===e)return e;if(J(e))return e.clone();if(e instanceof Uint8Array){const t=new Uint8Array(e.byteLength);return t.set(e),t}return e}function ke(e){return e instanceof Uint8Array?e:new Uint8Array(e)}class we{constructor(e,t){this._fields=e,this._normalizer=t}findJsonName(e){if(!this.jsonNames){const e={};for(const t of this.list())e[t.jsonName]=e[t.name]=t;this.jsonNames=e}return this.jsonNames[e]}find(e){if(!this.numbers){const e={};for(const t of this.list())e[t.no]=t;this.numbers=e}return this.numbers[e]}list(){return this.all||(this.all=this._normalizer(this._fields)),this.all}byNumber(){return this.numbersAsc||(this.numbersAsc=this.list().concat().sort(((e,t)=>e.no-t.no))),this.numbersAsc}byMember(){if(!this.members){this.members=[];const e=this.members;let t;for(const n of this.list())n.oneof?n.oneof!==t&&(t=n.oneof,e.push(t)):e.push(n)}return this.members}}function Te(e,t){const n=Ee(e);return t?n:Ae(Ce(n))}const Se=Ee;function Ee(e){let t=!1;const n=[];for(let r=0;r<e.length;r++){let i=e.charAt(r);switch(i){case"_":t=!0;break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":n.push(i),t=!1;break;default:t&&(t=!1,i=i.toUpperCase()),n.push(i)}}return n.join("")}const Ne=new Set(["constructor","toString","toJSON","valueOf"]),Ie=new Set(["getType","clone","equals","fromBinary","fromJson","fromJsonString","toBinary","toJson","toJsonString","toObject"]),Oe=e=>"".concat(e,"$"),Ce=e=>Ie.has(e)?Oe(e):e,Ae=e=>Ne.has(e)?Oe(e):e;class Ue{constructor(e){this.kind="oneof",this.repeated=!1,this.packed=!1,this.opt=!1,this.req=!1,this.default=void 0,this.fields=[],this.name=e,this.localName=Te(e,!1)}addField(t){e(t.oneof===this,"field ".concat(t.name," not one of ").concat(this.name)),this.fields.push(t)}findField(e){if(!this._lookup){this._lookup=Object.create(null);for(let e=0;e<this.fields.length;e++)this._lookup[this.fields[e].localName]=this.fields[e]}return this._lookup[e]}}const Le=(Fe=e=>new we(e,(e=>function(e){var t,n,r,i,a,o;const s=[];let c;for(const u of"function"==typeof e?e():e){const e=u;if(e.localName=Te(u.name,void 0!==u.oneof),e.jsonName=null!==(t=u.jsonName)&&void 0!==t?t:Se(u.name),e.repeated=null!==(n=u.repeated)&&void 0!==n&&n,"scalar"==u.kind&&(e.L=null!==(r=u.L)&&void 0!==r?r:S.BIGINT),e.delimited=null!==(i=u.delimited)&&void 0!==i&&i,e.req=null!==(a=u.req)&&void 0!==a&&a,e.opt=null!==(o=u.opt)&&void 0!==o&&o,void 0===u.packed&&(e.packed="enum"==u.kind||"scalar"==u.kind&&u.T!=T.BYTES&&u.T!=T.STRING),void 0!==u.oneof){const t="string"==typeof u.oneof?u.oneof:u.oneof.name;c&&c.name==t||(c=new Ue(t)),e.oneof=c,c.addField(e)}s.push(e)}return s}(e))),De=e=>{for(const t of e.getType().fields.byMember()){if(t.opt)continue;const n=t.localName,r=e;if(t.repeated)r[n]=[];else switch(t.kind){case"oneof":r[n]={case:void 0};break;case"enum":r[n]=0;break;case"map":r[n]={};break;case"scalar":r[n]=I(t.T,t.L)}}},{syntax:"proto3",json:{makeReadOptions:W,makeWriteOptions:H,readMessage(e,t,n,r){if(null==t||Array.isArray(t)||"object"!=typeof t)throw new Error("cannot decode message ".concat(e.typeName," from JSON: ").concat(Q(t)));r=null!=r?r:new e;const i=new Map,a=n.typeRegistry;for(const s of Object.entries(t)){var o=A(s,2);const t=o[0],c=o[1],u=e.fields.findJsonName(t);if(u){if(u.oneof){if(null===c&&"scalar"==u.kind)continue;const n=i.get(u.oneof);if(void 0!==n)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: multiple keys for oneof "').concat(u.oneof.name,'" present: "').concat(n,'", "').concat(t,'"'));i.set(u.oneof,t)}z(r,c,u,n,e)}else{let i=!1;if((null==a?void 0:a.findExtension)&&t.startsWith("[")&&t.endsWith("]")){const o=a.findExtension(t.substring(1,t.length-1));if(o&&o.extendee.typeName==e.typeName){i=!0;const e=A(F(o),2),t=e[0],a=e[1];z(t,c,o.field,n,o),x(r,o,a(),n)}}if(!i&&!n.ignoreUnknownFields)throw new Error("cannot decode message ".concat(e.typeName,' from JSON: key "').concat(t,'" is unknown'))}}return r},writeMessage(e,t){const n=e.getType(),r={};let i;try{for(i of n.fields.byNumber()){if(!V(i,e)){if(i.req)throw"required field not set";if(!t.emitDefaultValues)continue;if(!te(i))continue}const n=ne(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t);void 0!==n&&(r[t.useProtoFieldName?i.name:i.jsonName]=n)}const a=t.typeRegistry;if(null==a?void 0:a.findExtensionFor)for(const i of n.runtime.bin.listUnknownFields(e)){const o=a.findExtensionFor(n.typeName,i.no);if(o&&j(e,o)){const n=P(e,o,t),i=ne(o.field,n,t);void 0!==i&&(r[o.field.jsonName]=i)}}}catch(e){const t=i?"cannot encode field ".concat(n.typeName,".").concat(i.name," to JSON"):"cannot encode message ".concat(n.typeName," to JSON"),r=e instanceof Error?e.message:String(e);throw new Error(t+(r.length>0?": ".concat(r):""))}return r},readScalar:(e,t,n)=>Z(e,t,null!=n?n:S.BIGINT,!0),writeScalar(e,t,n){if(void 0!==t)return n||O(e,t)?ie(e,t):void 0},debug:Q},bin:{makeReadOptions:ce,makeWriteOptions:ue,listUnknownFields(e){var t;return null!==(t=e[ae])&&void 0!==t?t:[]},discardUnknownFields(e){delete e[ae]},writeUnknownFields(e,t){const n=e[ae];if(n)for(const e of n)t.tag(e.no,e.wireType).raw(e.data)},onUnknownField(e,t,n,r){const i=e;Array.isArray(i[ae])||(i[ae]=[]),i[ae].push({no:t,wireType:n,data:r})},readMessage(e,t,n,r,i){const a=e.getType(),o=i?t.len:t.pos+n;let s,c;for(;t.pos<o;){var u=A(t.tag(),2);if(s=u[0],c=u[1],!0===i&&c==E.EndGroup)break;const n=a.fields.find(s);if(n)le(e,t,n,c,r);else{const n=t.skip(c,s);r.readUnknownFields&&this.onUnknownField(e,s,c,n)}}if(i&&(c!=E.EndGroup||s!==n))throw new Error("invalid end group tag")},readField:le,writeMessage(e,t,n){const r=e.getType();for(const i of r.fields.byNumber())if(V(i,e))pe(i,i.oneof?e[i.oneof.localName].value:e[i.localName],t,n);else if(i.req)throw new Error("cannot encode field ".concat(r.typeName,".").concat(i.name," to binary: required field not set"));return n.writeUnknownFields&&this.writeUnknownFields(e,t),t},writeField(e,t,n,r){void 0!==t&&pe(e,t,n,r)}},util:Object.assign(Object.assign({},{setEnumType:o,initPartial(e,t){if(void 0===e)return;const n=t.getType();for(const i of n.fields.byMember()){const n=i.localName,a=t,o=e;if(null!=o[n])switch(i.kind){case"oneof":const e=o[n].case;if(void 0===e)continue;const t=i.findField(e);let s=o[n].value;t&&"message"==t.kind&&!J(s,t.T)?s=new t.T(s):t&&"scalar"===t.kind&&t.T===T.BYTES&&(s=ke(s)),a[n]={case:e,value:s};break;case"scalar":case"enum":let c=o[n];i.T===T.BYTES&&(c=i.repeated?c.map(ke):ke(c)),a[n]=c;break;case"map":switch(i.V.kind){case"scalar":case"enum":if(i.V.T===T.BYTES)for(const e of Object.entries(o[n])){var r=A(e,2);const t=r[0],i=r[1];a[n][t]=ke(i)}else Object.assign(a[n],o[n]);break;case"message":const e=i.V.T;for(const t of Object.keys(o[n])){let r=o[n][t];e.fieldWrapper||(r=new e(r)),a[n][t]=r}}break;case"message":const u=i.T;if(i.repeated)a[n]=o[n].map((e=>J(e,u)?e:new u(e)));else{const e=o[n];u.fieldWrapper?"google.protobuf.BytesValue"===u.typeName?a[n]=ke(e):a[n]=e:a[n]=J(e,u)?e:new u(e)}}}},equals:(e,t,n)=>t===n||!(!t||!n)&&e.fields.byMember().every((e=>{const r=t[e.localName],i=n[e.localName];if(e.repeated){if(r.length!==i.length)return!1;switch(e.kind){case"message":return r.every(((t,n)=>e.T.equals(t,i[n])));case"scalar":return r.every(((t,n)=>N(e.T,t,i[n])));case"enum":return r.every(((e,t)=>N(T.INT32,e,i[t])))}throw new Error("repeated cannot contain ".concat(e.kind))}switch(e.kind){case"message":let t=r,n=i;return e.T.fieldWrapper&&(void 0===t||J(t)||(t=e.T.fieldWrapper.wrapField(t)),void 0===n||J(n)||(n=e.T.fieldWrapper.wrapField(n))),e.T.equals(t,n);case"enum":return N(T.INT32,r,i);case"scalar":return N(e.T,r,i);case"oneof":if(r.case!==i.case)return!1;const a=e.findField(r.case);if(void 0===a)return!0;switch(a.kind){case"message":return a.T.equals(r.value,i.value);case"enum":return N(T.INT32,r.value,i.value);case"scalar":return N(a.T,r.value,i.value)}throw new Error("oneof cannot contain ".concat(a.kind));case"map":const o=Object.keys(r).concat(Object.keys(i));switch(e.V.kind){case"message":const t=e.V.T;return o.every((e=>t.equals(r[e],i[e])));case"enum":return o.every((e=>N(T.INT32,r[e],i[e])));case"scalar":const n=e.V.T;return o.every((e=>N(n,r[e],i[e])))}}})),clone(e){const t=e.getType(),n=new t,r=n;for(const n of t.fields.byMember()){const t=e[n.localName];let a;if(n.repeated)a=t.map(ve);else if("map"==n.kind){a=r[n.localName];for(const e of Object.entries(t)){var i=A(e,2);const t=i[0],n=i[1];a[t]=ve(n)}}else a="oneof"==n.kind?n.findField(t.case)?{case:t.case,value:ve(t.value)}:{case:void 0}:ve(t);r[n.localName]=a}for(const n of t.runtime.bin.listUnknownFields(e))t.runtime.bin.onUnknownField(r,n.no,n.wireType,n.data);return n}}),{newFieldList:Fe,initFields:De}),makeMessageType(e,t,n){return function(e,t,n,r){var i;const a=null!==(i=null==r?void 0:r.localName)&&void 0!==i?i:t.substring(t.lastIndexOf(".")+1),o={[a]:function(t){e.util.initFields(this),e.util.initPartial(t,this)}}[a];return Object.setPrototypeOf(o.prototype,new l),Object.assign(o,{runtime:e,typeName:t,fields:e.util.newFieldList(n),fromBinary:(e,t)=>(new o).fromBinary(e,t),fromJson:(e,t)=>(new o).fromJson(e,t),fromJsonString:(e,t)=>(new o).fromJsonString(e,t),equals:(t,n)=>e.util.equals(o,t,n)}),o}(this,e,t,n)},makeEnum:c,makeEnumType:s,getEnumType:a,makeExtension(e,t,n){return function(e,t,n,r){let i;return{typeName:t,extendee:n,get field(){if(!i){const n="function"==typeof r?r():r;n.name=t.split(".").pop(),n.jsonName="[".concat(t,"]"),i=e.util.newFieldList([n]).list()[0]}return i},runtime:e}}(this,e,t,n)}});var Fe,De;const Re=Le.makeEnum("livekit.TrackType",[{no:0,name:"AUDIO"},{no:1,name:"VIDEO"},{no:2,name:"DATA"}]),Be=Le.makeEnum("livekit.TrackSource",[{no:0,name:"UNKNOWN"},{no:1,name:"CAMERA"},{no:2,name:"MICROPHONE"},{no:3,name:"SCREEN_SHARE"},{no:4,name:"SCREEN_SHARE_AUDIO"}]),Pe=Le.makeEnum("livekit.StreamState",[{no:0,name:"ACTIVE"},{no:1,name:"PAUSED"}]);function xe(e,t,n,r){return new(n||(n=Promise))((function(i,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,s)}c((r=r.apply(e,t||[])).next())}))}var je,Me;"function"==typeof SuppressedError&&SuppressedError;class Ve extends(Me=Promise){constructor(e){super(e)}catch(e){return super.catch(e)}static reject(e){return super.reject(e)}static all(e){return super.all(e)}static race(e){return super.race(e)}}je=Ve,Ve.resolve=e=>Reflect.get(Me,"resolve",je).call(je,e);const _e=/version\/(\d+(\.?_?\d+)+)/i;let Je;function Ge(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("undefined"==typeof navigator)return;const n=navigator.userAgent.toLowerCase();if(void 0===Je||t){const e=Xe.find((e=>e.test.test(n)));Je=null==e?void 0:e.describe(n)}return Je}const Xe=[{test:/firefox|iceweasel|fxios/i,describe:e=>({name:"Firefox",version:qe(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("fxios")?"iOS":void 0,osVersion:We(e)})},{test:/chrom|crios|crmo/i,describe:e=>({name:"Chrome",version:qe(/(?:chrome|chromium|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e),os:e.toLowerCase().includes("crios")?"iOS":void 0,osVersion:We(e)})},{test:/safari|applewebkit/i,describe:e=>({name:"Safari",version:qe(_e,e),os:e.includes("mobile/")?"iOS":"macOS",osVersion:We(e)})}];function qe(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;const r=t.match(e);return r&&r.length>=n&&r[n]||""}function We(e){return e.includes("mac os")?qe(/\(.+?(\d+_\d+(:?_\d+)?)/,e,1).replace(/_/g,"."):void 0}var He,Ye,Ke;!function(e){e[e.NotAllowed=0]="NotAllowed",e[e.ServerUnreachable=1]="ServerUnreachable",e[e.InternalError=2]="InternalError",e[e.Cancelled=3]="Cancelled",e[e.LeaveRequest=4]="LeaveRequest",e[e.Timeout=5]="Timeout",e[e.WebSocket=6]="WebSocket",e[e.ServiceNotFound=7]="ServiceNotFound"}(He||(He={})),function(e){e[e.AlreadyOpened=0]="AlreadyOpened",e[e.AbnormalEnd=1]="AbnormalEnd",e[e.DecodeFailed=2]="DecodeFailed",e[e.LengthExceeded=3]="LengthExceeded",e[e.Incomplete=4]="Incomplete",e[e.HandlerAlreadyRegistered=7]="HandlerAlreadyRegistered",e[e.EncryptionTypeMismatch=8]="EncryptionTypeMismatch"}(Ye||(Ye={})),function(e){e.PermissionDenied="PermissionDenied",e.NotFound="NotFound",e.DeviceInUse="DeviceInUse",e.Other="Other"}(Ke||(Ke={})),function(e){e.getFailure=function(t){if(t&&"name"in t)return"NotFoundError"===t.name||"DevicesNotFoundError"===t.name?e.NotFound:"NotAllowedError"===t.name||"PermissionDeniedError"===t.name?e.PermissionDenied:"NotReadableError"===t.name||"TrackStartError"===t.name?e.DeviceInUse:e.Other}}(Ke||(Ke={}));var Qe,ze={exports:{}};var $e,Ze=function(){if(Qe)return ze.exports;Qe=1;var e,t="object"==typeof Reflect?Reflect:null,n=t&&"function"==typeof t.apply?t.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var r=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}ze.exports=i,ze.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}p(e,t,a,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&p(e,"error",t,n)}(e,i,{once:!0})}))},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function o(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function s(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,a,c,u;if(o(n),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),a=e._events),c=a[t]),void 0===c)c=a[t]=n,++e._eventsCount;else if("function"==typeof c?c=a[t]=r?[n,c]:[c,n]:r?c.unshift(n):c.push(n),(i=s(e))>0&&c.length>i&&!c.warned){c.warned=!0;var l=new Error("Possible EventEmitter memory leak detected. "+c.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");l.name="MaxListenersExceededWarning",l.emitter=e,l.type=t,l.count=c.length,u=l,console&&console.warn&&console.warn(u)}return e}function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=u.bind(r);return i.listener=n,r.wrapFn=i,i}function d(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):h(i,i.length)}function f(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function h(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function p(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(a){r.once&&e.removeEventListener(t,i),n(a)}))}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||r(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return s(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var i="error"===e,a=this._events;if(void 0!==a)i=i&&void 0===a.error;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var c=a[e];if(void 0===c)return!1;if("function"==typeof c)n(c,this,t);else{var u=c.length,l=h(c,u);for(r=0;r<u;++r)n(l[r],this,t)}return!0},i.prototype.addListener=function(e,t){return c(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return c(this,e,t,!0)},i.prototype.once=function(e,t){return o(t),this.on(e,l(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return o(t),this.prependListener(e,l(this,e,t)),this},i.prototype.removeListener=function(e,t){var n,r,i,a,s;if(o(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){s=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},i.prototype.listeners=function(e){return d(this,e,!0)},i.prototype.rawListeners=function(e){return d(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):f.call(e,t)},i.prototype.listenerCount=f,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},ze.exports}(),et={exports:{}};var tt,nt,rt,it,at,ot=($e||($e=1,nt=et.exports,rt=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),r=["trace","debug","info","warn","error"],i={},a=null;function o(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function s(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function c(){for(var n=this.getLevel(),i=0;i<r.length;i++){var a=r[i];this[a]=i<n?e:this.methodFactory(a,n,this.name)}if(this.log=this.debug,typeof console===t&&n<this.levels.SILENT)return"No console available for logging"}function u(e){return function(){typeof console!==t&&(c.call(this),this[e].apply(this,arguments))}}function l(r,i,a){return function(r){return"debug"===r&&(r="log"),typeof console!==t&&("trace"===r&&n?s:void 0!==console[r]?o(console,r):void 0!==console.log?o(console,"log"):e)}(r)||u.apply(this,arguments)}function d(e,n){var o,s,u,d=this,f="loglevel";function h(){var e;if(typeof window!==t&&f){try{e=window.localStorage[f]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,r=encodeURIComponent(f),i=n.indexOf(r+"=");-1!==i&&(e=/^([^;]+)/.exec(n.slice(i+r.length+1))[1])}catch(e){}return void 0===d.levels[e]&&(e=void 0),e}}function p(e){var t=e;if("string"==typeof t&&void 0!==d.levels[t.toUpperCase()]&&(t=d.levels[t.toUpperCase()]),"number"==typeof t&&t>=0&&t<=d.levels.SILENT)return t;throw new TypeError("log.setLevel() called with invalid level: "+e)}"string"==typeof e?f+=":"+e:"symbol"==typeof e&&(f=void 0),d.name=e,d.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},d.methodFactory=n||l,d.getLevel=function(){return null!=u?u:null!=s?s:o},d.setLevel=function(e,n){return u=p(e),!1!==n&&function(e){var n=(r[e]||"silent").toUpperCase();if(typeof window!==t&&f){try{return void(window.localStorage[f]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(f)+"="+n+";"}catch(e){}}}(u),c.call(d)},d.setDefaultLevel=function(e){s=p(e),h()||d.setLevel(e,!1)},d.resetLevel=function(){u=null,function(){if(typeof window!==t&&f){try{window.localStorage.removeItem(f)}catch(e){}try{window.document.cookie=encodeURIComponent(f)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}(),c.call(d)},d.enableAll=function(e){d.setLevel(d.levels.TRACE,e)},d.disableAll=function(e){d.setLevel(d.levels.SILENT,e)},d.rebuild=function(){if(a!==d&&(o=p(a.getLevel())),c.call(d),a===d)for(var e in i)i[e].rebuild()},o=p(a?a.getLevel():"WARN");var m=h();null!=m&&(u=p(m)),c.call(d)}(a=new d).getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=i[e];return t||(t=i[e]=new d(e,a.methodFactory)),t};var f=typeof window!==t?window.log:void 0;return a.noConflict=function(){return typeof window!==t&&window.log===a&&(window.log=f),a},a.getLoggers=function(){return i},a.default=a,a},(tt=et).exports?tt.exports=rt():nt.log=rt()),et.exports);!function(e){e[e.trace=0]="trace",e[e.debug=1]="debug",e[e.info=2]="info",e[e.warn=3]="warn",e[e.error=4]="error",e[e.silent=5]="silent"}(it||(it={})),function(e){e.Default="livekit",e.Room="livekit-room",e.TokenSource="livekit-token-source",e.Participant="livekit-participant",e.Track="livekit-track",e.Publication="livekit-track-publication",e.Engine="livekit-engine",e.Signal="livekit-signal",e.PCManager="livekit-pc-manager",e.PCTransport="livekit-pc-transport",e.E2EE="lk-e2ee",e.DataTracks="livekit-data-tracks"}(at||(at={}));let st=ot.getLogger(at.Default);function ct(e,t){const n=ot.getLogger(e);return n.setDefaultLevel(st.getLevel()),n}var ut,lt,dt,ft,ht,pt;Object.values(at).map((e=>ot.getLogger(e))),st.setDefaultLevel(it.info),ot.getLogger(at.E2EE),function(e){e.Connected="connected",e.Reconnecting="reconnecting",e.SignalReconnecting="signalReconnecting",e.Reconnected="reconnected",e.Disconnected="disconnected",e.ConnectionStateChanged="connectionStateChanged",e.Moved="moved",e.MediaDevicesChanged="mediaDevicesChanged",e.ParticipantConnected="participantConnected",e.ParticipantDisconnected="participantDisconnected",e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalAudioSilenceDetected="localAudioSilenceDetected",e.ActiveSpeakersChanged="activeSpeakersChanged",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.ParticipantAttributesChanged="participantAttributesChanged",e.ParticipantActive="participantActive",e.RoomMetadataChanged="roomMetadataChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.AudioPlaybackStatusChanged="audioPlaybackChanged",e.VideoPlaybackStatusChanged="videoPlaybackChanged",e.MediaDevicesError="mediaDevicesError",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.SignalConnected="signalConnected",e.RecordingStatusChanged="recordingStatusChanged",e.ParticipantEncryptionStatusChanged="participantEncryptionStatusChanged",e.EncryptionError="encryptionError",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ActiveDeviceChanged="activeDeviceChanged",e.ChatMessage="chatMessage",e.LocalTrackSubscribed="localTrackSubscribed",e.MetricsReceived="metricsReceived",e.DataTrackPublished="dataTrackPublished",e.DataTrackUnpublished="dataTrackUnpublished",e.LocalDataTrackPublished="localDataTrackPublished",e.LocalDataTrackUnpublished="localDataTrackUnpublished"}(ut||(ut={})),function(e){e.TrackPublished="trackPublished",e.TrackSubscribed="trackSubscribed",e.TrackSubscriptionFailed="trackSubscriptionFailed",e.TrackUnpublished="trackUnpublished",e.TrackUnsubscribed="trackUnsubscribed",e.TrackMuted="trackMuted",e.TrackUnmuted="trackUnmuted",e.LocalTrackPublished="localTrackPublished",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackCpuConstrained="localTrackCpuConstrained",e.LocalSenderCreated="localSenderCreated",e.ParticipantMetadataChanged="participantMetadataChanged",e.ParticipantNameChanged="participantNameChanged",e.DataReceived="dataReceived",e.SipDTMFReceived="sipDTMFReceived",e.TranscriptionReceived="transcriptionReceived",e.IsSpeakingChanged="isSpeakingChanged",e.ConnectionQualityChanged="connectionQualityChanged",e.TrackStreamStateChanged="trackStreamStateChanged",e.TrackSubscriptionPermissionChanged="trackSubscriptionPermissionChanged",e.TrackSubscriptionStatusChanged="trackSubscriptionStatusChanged",e.TrackCpuConstrained="trackCpuConstrained",e.MediaDevicesError="mediaDevicesError",e.AudioStreamAcquired="audioStreamAcquired",e.ParticipantPermissionsChanged="participantPermissionsChanged",e.PCTrackAdded="pcTrackAdded",e.AttributesChanged="attributesChanged",e.LocalTrackSubscribed="localTrackSubscribed",e.ChatMessage="chatMessage",e.Active="active"}(lt||(lt={})),function(e){e.TransportsCreated="transportsCreated",e.Connected="connected",e.Disconnected="disconnected",e.Resuming="resuming",e.Resumed="resumed",e.Restarting="restarting",e.Restarted="restarted",e.SignalResumed="signalResumed",e.SignalRestarted="signalRestarted",e.Closing="closing",e.MediaTrackAdded="mediaTrackAdded",e.ActiveSpeakersUpdate="activeSpeakersUpdate",e.DataPacketReceived="dataPacketReceived",e.RTPVideoMapUpdate="rtpVideoMapUpdate",e.DCBufferStatusChanged="dcBufferStatusChanged",e.ParticipantUpdate="participantUpdate",e.RoomUpdate="roomUpdate",e.SpeakersChanged="speakersChanged",e.StreamStateChanged="streamStateChanged",e.ConnectionQualityUpdate="connectionQualityUpdate",e.SubscriptionError="subscriptionError",e.SubscriptionPermissionUpdate="subscriptionPermissionUpdate",e.RemoteMute="remoteMute",e.SubscribedQualityUpdate="subscribedQualityUpdate",e.LocalTrackUnpublished="localTrackUnpublished",e.LocalTrackSubscribed="localTrackSubscribed",e.Offline="offline",e.SignalRequestResponse="signalRequestResponse",e.SignalConnected="signalConnected",e.RoomMoved="roomMoved",e.PublishDataTrackResponse="publishDataTrackResponse",e.UnPublishDataTrackResponse="unPublishDataTrackResponse",e.DataTrackSubscriberHandles="dataTrackSubscriberHandles",e.DataTrackPacketReceived="dataTrackPacketReceived",e.Joined="joined",e.TokenRefreshed="tokenRefreshed",e.ServerRegionsReported="serverRegionsReported"}(dt||(dt={})),function(e){e.Message="message",e.Muted="muted",e.Unmuted="unmuted",e.Restarted="restarted",e.Ended="ended",e.Subscribed="subscribed",e.Unsubscribed="unsubscribed",e.CpuConstrained="cpuConstrained",e.UpdateSettings="updateSettings",e.UpdateSubscription="updateSubscription",e.AudioPlaybackStarted="audioPlaybackStarted",e.AudioPlaybackFailed="audioPlaybackFailed",e.AudioSilenceDetected="audioSilenceDetected",e.VisibilityChanged="visibilityChanged",e.VideoDimensionsChanged="videoDimensionsChanged",e.VideoPlaybackStarted="videoPlaybackStarted",e.VideoPlaybackFailed="videoPlaybackFailed",e.ElementAttached="elementAttached",e.ElementDetached="elementDetached",e.UpstreamPaused="upstreamPaused",e.UpstreamResumed="upstreamResumed",e.SubscriptionPermissionChanged="subscriptionPermissionChanged",e.SubscriptionStatusChanged="subscriptionStatusChanged",e.SubscriptionFailed="subscriptionFailed",e.TrackProcessorUpdate="trackProcessorUpdate",e.AudioTrackFeatureUpdate="audioTrackFeatureUpdate",e.TranscriptionReceived="transcriptionReceived",e.TimeSyncUpdate="timeSyncUpdate",e.PreConnectBufferFlushed="preConnectBufferFlushed"}(ft||(ft={}));class mt{constructor(e,t,n,r,i){if("object"==typeof e)this.width=e.width,this.height=e.height,this.aspectRatio=e.aspectRatio,this.encoding={maxBitrate:e.maxBitrate,maxFramerate:e.maxFramerate,priority:e.priority};else{if(void 0===t||void 0===n)throw new TypeError("Unsupported options: provide at least width, height and maxBitrate");this.width=e,this.height=t,this.aspectRatio=e/t,this.encoding={maxBitrate:n,maxFramerate:r,priority:i}}}get resolution(){return{width:this.width,height:this.height,frameRate:this.encoding.maxFramerate,aspectRatio:this.aspectRatio}}}function gt(e){return"mediaStreamTrack"in e?{trackID:e.sid,source:e.source,muted:e.isMuted,enabled:e.mediaStreamTrack.enabled,kind:e.kind,streamID:e.mediaStreamID,streamTrackID:e.mediaStreamTrack.id}:{trackID:e.trackSid,enabled:e.isEnabled,muted:e.isMuted,trackInfo:Object.assign({mimeType:e.mimeType,name:e.trackName,encrypted:e.isEncrypted,kind:e.kind,source:e.source},e.track?gt(e.track):{})}}!function(e){e[e.PREFER_REGRESSION=0]="PREFER_REGRESSION",e[e.SIMULCAST=1]="SIMULCAST",e[e.REGRESSION=2]="REGRESSION"}(ht||(ht={})),function(e){e.telephone={maxBitrate:12e3},e.speech={maxBitrate:24e3},e.music={maxBitrate:48e3},e.musicStereo={maxBitrate:64e3},e.musicHighQuality={maxBitrate:96e3},e.musicHighQualityStereo={maxBitrate:128e3}}(pt||(pt={})),new mt(160,90,9e4,20),new mt(320,180,16e4,20),new mt(384,216,18e4,20),new mt(640,360,45e4,20),new mt(960,540,8e5,25),new mt(1280,720,17e5,30),new mt(1920,1080,3e6,30),new mt(2560,1440,5e6,30),new mt(3840,2160,8e6,30),new mt(160,120,7e4,20),new mt(240,180,125e3,20),new mt(320,240,14e4,20),new mt(480,360,33e4,20),new mt(640,480,5e5,20),new mt(720,540,6e5,25),new mt(960,720,13e5,30),new mt(1440,1080,23e5,30),new mt(1920,1440,38e5,30),new mt(640,360,2e5,3,"medium"),new mt(640,360,4e5,15,"medium"),new mt(1280,720,8e5,5,"medium"),new mt(1280,720,15e5,15,"medium"),new mt(1280,720,2e6,30,"medium"),new mt(1920,1080,25e5,15,"medium"),new mt(1920,1080,5e6,30,"medium"),new mt(0,0,7e6,30,"medium");const bt=[];var yt;!function(e){e[e.LOW=0]="LOW",e[e.MEDIUM=1]="MEDIUM",e[e.HIGH=2]="HIGH"}(yt||(yt={}));class vt extends Ze.EventEmitter{get streamState(){return this._streamState}setStreamState(e){this._streamState=e}constructor(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};var r;super(),this.attachedElements=[],this.isMuted=!1,this._streamState=vt.StreamState.Active,this.isInBackground=!1,this._currentBitrate=0,this.log=st,this.appVisibilityChangedListener=()=>{this.backgroundTimeout&&clearTimeout(this.backgroundTimeout),"hidden"===document.visibilityState?this.backgroundTimeout=setTimeout((()=>this.handleAppVisibilityChanged()),5e3):this.handleAppVisibilityChanged()},this.log=ct(null!==(r=n.loggerName)&&void 0!==r?r:at.Track),this.loggerContextCb=n.loggerContextCb,this.setMaxListeners(100),this.kind=t,this._mediaStreamTrack=e,this._mediaStreamID=e.id,this.source=vt.Source.Unknown}get logContext(){var e;return Object.assign(Object.assign({},null===(e=this.loggerContextCb)||void 0===e?void 0:e.call(this)),gt(this))}get currentBitrate(){return this._currentBitrate}get mediaStreamTrack(){return this._mediaStreamTrack}get mediaStreamID(){return this._mediaStreamID}attach(e){let t="audio";this.kind===vt.Kind.Video&&(t="video"),0===this.attachedElements.length&&this.kind===vt.Kind.Video&&this.addAppVisibilityListener(),e||("audio"===t&&(bt.forEach((t=>{null!==t.parentElement||e||(e=t)})),e&&bt.splice(bt.indexOf(e),1)),e||(e=document.createElement(t))),this.attachedElements.includes(e)||this.attachedElements.push(e),function(e,t){let n,r;n=t.srcObject instanceof MediaStream?t.srcObject:new MediaStream;r="audio"===e.kind?n.getAudioTracks():n.getVideoTracks();r.includes(e)||(r.forEach((e=>{n.removeTrack(e)})),n.addTrack(e));wt()&&t instanceof HTMLVideoElement||(t.autoplay=!0);t.muted=0===n.getAudioTracks().length,t instanceof HTMLVideoElement&&(t.playsInline=!0);t.srcObject!==n&&(t.srcObject=n,(wt()||function(){var e;return"Firefox"===(null===(e=Ge())||void 0===e?void 0:e.name)}())&&t instanceof HTMLVideoElement&&setTimeout((()=>{t.srcObject=n,t.play().catch((()=>{}))}),0))}(this.mediaStreamTrack,e);const n=e.srcObject.getTracks(),r=n.some((e=>"audio"===e.kind));return e.play().then((()=>{this.emit(r?ft.AudioPlaybackStarted:ft.VideoPlaybackStarted)})).catch((t=>{"NotAllowedError"===t.name?this.emit(r?ft.AudioPlaybackFailed:ft.VideoPlaybackFailed,t):"AbortError"===t.name?st.debug("".concat(r?"audio":"video"," playback aborted, likely due to new play request")):st.warn("could not playback ".concat(r?"audio":"video"),t),r&&e&&n.some((e=>"video"===e.kind))&&"NotAllowedError"===t.name&&(e.muted=!0,e.play().catch((()=>{})))})),this.emit(ft.ElementAttached,e),e}detach(e){try{if(e){kt(this.mediaStreamTrack,e);const t=this.attachedElements.indexOf(e);return t>=0&&(this.attachedElements.splice(t,1),this.recycleElement(e),this.emit(ft.ElementDetached,e)),e}const t=[];return this.attachedElements.forEach((e=>{kt(this.mediaStreamTrack,e),t.push(e),this.recycleElement(e),this.emit(ft.ElementDetached,e)})),this.attachedElements=[],t}finally{0===this.attachedElements.length&&this.removeAppVisibilityListener()}}stop(){this.stopMonitor(),this._mediaStreamTrack.stop()}enable(){this._mediaStreamTrack.enabled=!0}disable(){this._mediaStreamTrack.enabled=!1}stopMonitor(){this.monitorInterval&&clearInterval(this.monitorInterval),this.timeSyncHandle&&cancelAnimationFrame(this.timeSyncHandle)}updateLoggerOptions(e){e.loggerName&&(this.log=ct(e.loggerName)),e.loggerContextCb&&(this.loggerContextCb=e.loggerContextCb)}recycleElement(e){if(e instanceof HTMLAudioElement){let t=!0;e.pause(),bt.forEach((e=>{e.parentElement||(t=!1)})),t&&bt.push(e)}}handleAppVisibilityChanged(){return xe(this,void 0,void 0,(function*(){this.isInBackground="hidden"===document.visibilityState,this.isInBackground||this.kind!==vt.Kind.Video||setTimeout((()=>this.attachedElements.forEach((e=>e.play().catch((()=>{}))))),0)}))}addAppVisibilityListener(){Tt()?(this.isInBackground="hidden"===document.visibilityState,document.addEventListener("visibilitychange",this.appVisibilityChangedListener)):this.isInBackground=!1}removeAppVisibilityListener(){Tt()&&document.removeEventListener("visibilitychange",this.appVisibilityChangedListener)}}function kt(e,t){if(t.srcObject instanceof MediaStream){const n=t.srcObject;n.removeTrack(e),n.getTracks().length>0?t.srcObject=n:t.srcObject=null}}function wt(){var e;return"Safari"===(null===(e=Ge())||void 0===e?void 0:e.name)}function Tt(){return"undefined"!=typeof document}function St(e){return!(!(null==e?void 0:e.timestamp)&&!(null==e?void 0:e.frameId))}!function(e){let t,n,r;!function(e){e.Audio="audio",e.Video="video",e.Unknown="unknown"}(t=e.Kind||(e.Kind={})),function(e){e.Camera="camera",e.Microphone="microphone",e.ScreenShare="screen_share",e.ScreenShareAudio="screen_share_audio",e.Unknown="unknown"}(n=e.Source||(e.Source={})),function(e){e.Active="active",e.Paused="paused",e.Unknown="unknown"}(r=e.StreamState||(e.StreamState={})),e.kindToProto=function(e){switch(e){case t.Audio:return Re.AUDIO;case t.Video:return Re.VIDEO;default:return Re.DATA}},e.kindFromProto=function(e){switch(e){case Re.AUDIO:return t.Audio;case Re.VIDEO:return t.Video;default:return t.Unknown}},e.sourceToProto=function(e){switch(e){case n.Camera:return Be.CAMERA;case n.Microphone:return Be.MICROPHONE;case n.ScreenShare:return Be.SCREEN_SHARE;case n.ScreenShareAudio:return Be.SCREEN_SHARE_AUDIO;default:return Be.UNKNOWN}},e.sourceFromProto=function(e){switch(e){case Be.CAMERA:return n.Camera;case Be.MICROPHONE:return n.Microphone;case Be.SCREEN_SHARE:return n.ScreenShare;case Be.SCREEN_SHARE_AUDIO:return n.ScreenShareAudio;default:return n.Unknown}},e.streamStateFromProto=function(e){switch(e){case Pe.ACTIVE:return r.Active;case Pe.PAUSED:return r.Paused;default:return r.Unknown}}}(vt||(vt={}));const Et=Uint8Array.from(["L".charCodeAt(0),"K".charCodeAt(0),"T".charCodeAt(0),"S".charCodeAt(0)]);function Nt(e,t,n){const r=t!==BigInt(0),i=0!==n;if(!r&&!i)return e;const a=(r?10:0)+(i?6:0)+5,o=new Uint8Array(e.length+a);let s=0;return o.set(e,s),s+=e.length,r&&(o[s++]=254,o[s++]=247,function(e,t,n){const r=Number(n>>BigInt(32)&BigInt(4294967295)),i=Number(n&BigInt(4294967295));e[t]=r>>>24^255,e[t+1]=r>>>16&255^255,e[t+2]=r>>>8&255^255,e[t+3]=255&r^255,e[t+4]=i>>>24^255,e[t+5]=i>>>16&255^255,e[t+6]=i>>>8&255^255,e[t+7]=255&i^255}(o,s,t),s+=8),i&&(o[s++]=253,o[s++]=251,function(e,t,n){for(let r=3;r>=0;r-=1)e[t+(3-r)]=n>>8*r&255^255}(o,s,n),s+=4),o[s++]=255^a,o.set(Et,s),o}function It(e){const t=e instanceof Uint8Array?e:new Uint8Array(e);if(t.length<5)return{data:t};if(!function(e,t){for(let n=0;n<Et.length;n+=1)if(e[t+n]!==Et[n])return!1;return!0}(t,t.length-Et.length))return{data:t};const n=255^t[t.length-5];if(n<5||n>t.length)return{data:t};const r=t.length-n,i=t.length-5,a=t.subarray(0,r);let o=r,s=!1;const c={userTimestamp:BigInt(0),frameId:0};for(;o+2<=i;){const e=255^t[o++],n=255^t[o++];if(o+n>i)break;if(1===e&&8===n)c.userTimestamp=Ot(t,o),s=!0;else if(2===e&&4===n)c.frameId=Ct(t,o,n),s=!0;else if(3===e){const e=new Uint8Array(n);for(let r=0;r<n;r+=1)e[r]=255^t[o+r];c.userData=e,s=!0}o+=n}return s?{data:a,metadata:c}:{data:t}}function Ot(e,t){const n=BigInt(((255^e[t])<<24|(255^e[t+1])<<16|(255^e[t+2])<<8|255^e[t+3])>>>0),r=BigInt(((255^e[t+4])<<24|(255^e[t+5])<<16|(255^e[t+6])<<8|255^e[t+7])>>>0);return n<<BigInt(32)|r}function Ct(e,t,n){let r=0;for(let i=0;i<n;i+=1)r=r<<8|255^e[t+i];return r>>>0}function At(e){try{const t=e.getMetadata();if("number"==typeof t.synchronizationSource)return t.synchronizationSource}catch(e){}return 0}const Ut=new Map;function Lt(e,t,n,r){const i={trackId:n,hasPacketTrailer:r};Ut.set(n,i);const a=new TransformStream({transform(e,t){try{if(i.hasPacketTrailer){const t=function(e,t){if(0===e.data.byteLength)return{};const n=It(e.data);if(!n.metadata)return{};const r=n.data.buffer.slice(n.data.byteOffset,n.data.byteOffset+n.data.byteLength),i=function(e){try{const t=e.getMetadata();if("number"==typeof t.rtpTimestamp)return t.rtpTimestamp;if("number"==typeof t.timestamp)return t.timestamp}catch(e){}if("number"==typeof e.timestamp)return e.timestamp}(e);return void 0!==i&&t?{data:r,payload:{trackId:t,rtpTimestamp:i,ssrc:At(e),metadata:n.metadata}}:{data:r}}(e,i.trackId);if(t.data&&(e.data=t.data),t.payload){const e={kind:"metadata",data:t.payload};postMessage(e)}}}catch(e){}t.enqueue(e)}});e.pipeThrough(a).pipeTo(t).catch((()=>{Ut.delete(i.trackId)}))}function Ft(e,t,n){if(!St(n))return void e.pipeTo(t).catch((()=>{}));let r=0;const i=new TransformStream({transform(e,t){try{(null==n?void 0:n.frameId)&&(r=4294967295===r?1:r+1),function(e,t,n){if(!St(t)||0===e.data.byteLength)return!1;const r=(null==t?void 0:t.timestamp)?BigInt(Date.now())*BigInt(1e3):BigInt(0),i=(null==t?void 0:t.frameId)?n:0,a=new Uint8Array(e.data),o=Nt(a,r,i);o.byteLength!==a.byteLength&&(e.data=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength))}(e,n,r)}catch(e){}t.enqueue(e)}});e.pipeThrough(i).pipeTo(t).catch((()=>{}))}onmessage=e=>{const t=e.data;switch(t.kind){case"init":postMessage({kind:"initAck"});break;case"decode":Lt(t.data.readableStream,t.data.writableStream,t.data.trackId,t.data.hasPacketTrailer);break;case"encode":Ft(t.data.readableStream,t.data.writableStream,t.data.packetTrailer);break;case"updateTrackId":!function(e,t,n){const r=Ut.get(e);r&&(r.trackId=t,r.hasPacketTrailer=n,Ut.delete(e),Ut.set(t,r))}(t.data.oldTrackId,t.data.newTrackId,t.data.hasPacketTrailer)}},self.RTCTransformEvent&&(self.onrtctransform=e=>{const t=e.transformer,n=t.options;"encode"===n.kind?Ft(t.readable,t.writable,n.packetTrailer):Lt(t.readable,t.writable,n.trackId,!0)})}));
|
|
2
|
+
//# sourceMappingURL=livekit-client.fm.worker.js.map
|
|
@@ -122,4 +122,4 @@ function createWithCanvas(sourceVideo, audioTracks, fps, transform) {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
//#endregion
|
|
125
|
-
export { createFrameTransformPump, createMirroredStream, shouldMirrorTrack };
|
|
125
|
+
export { createFrameTransformPump, createMirroredStream, isMediaStreamTrackProcessorSupported, shouldMirrorTrack };
|
|
@@ -30,9 +30,9 @@ function classifyActiveProbe(metrics, thresholds) {
|
|
|
30
30
|
if (q !== "good") reasons.push(`Mid-stream glass-to-glass latency is ~${metrics.g2gMs}ms (good ≤ ${g.goodMs}ms); the real-time experience may feel laggy.`);
|
|
31
31
|
}
|
|
32
32
|
if (metrics.ttffMs == null && metrics.g2gMs == null) if (metrics.rttMs != null) {
|
|
33
|
-
reasons.push("Could not measure glass-to-glass latency during the probe (no
|
|
33
|
+
reasons.push("Could not measure glass-to-glass latency during the probe (no frame metadata); using network RTT instead.");
|
|
34
34
|
dims.push(scoreLowerBetter(metrics.rttMs, thresholds.rtt.goodMs, thresholds.rtt.fairMs, thresholds.rtt.poorMs));
|
|
35
|
-
} else reasons.push("The probe connected but could not measure latency (no
|
|
35
|
+
} else reasons.push("The probe connected but could not measure latency (no frame metadata and no RTT sample).");
|
|
36
36
|
if (metrics.g2gDropRatio != null) {
|
|
37
37
|
const d = thresholds.g2gDrop;
|
|
38
38
|
const q = scoreLowerBetter(metrics.g2gDropRatio, d.good, d.fair, d.poor);
|
|
@@ -81,10 +81,9 @@ function activeMetricsFromStats(stats) {
|
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
* Animated synthetic video source — no camera permission needed
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* out of where the server reads it (breaking the round trip).
|
|
84
|
+
* Animated synthetic video source — no camera permission needed. It uses the
|
|
85
|
+
* model's input dimensions to exercise the same encode/inference path as a real
|
|
86
|
+
* session without unnecessary server-side resizing.
|
|
88
87
|
*/
|
|
89
88
|
function createSyntheticSource(width, height, fps) {
|
|
90
89
|
if (typeof document === "undefined") throw new Error("deep connectivity probe requires a DOM environment (document is undefined)");
|
|
@@ -214,4 +213,4 @@ const createPreflight = ({ logger, connect }) => {
|
|
|
214
213
|
return { checkConnectivity };
|
|
215
214
|
};
|
|
216
215
|
//#endregion
|
|
217
|
-
export { createPreflight };
|
|
216
|
+
export { classifyActiveProbe, createPreflight };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RealtimeObservability } from "../observability/realtime-observability.js";
|
|
2
2
|
import { isDesktopSafari } from "../../utils/platform.js";
|
|
3
3
|
import { createLiveKitMediaChannel } from "../media-channel.js";
|
|
4
|
+
import { createBrowserFrameMetadataDiagnostics, createFrameMetadataWorker } from "./frame-metadata-diagnostics.js";
|
|
4
5
|
import { createMirroredStream, shouldMirrorTrack } from "./mirror-stream.js";
|
|
5
|
-
import { createBrowserGlassToGlassDiagnostics } from "./glass-to-glass-diagnostics.js";
|
|
6
6
|
//#region src/realtime/browser/prepare-connection.ts
|
|
7
7
|
const prepareBrowserConnection = ({ stream, mirror, debugQuality, preferredVideoCodec, fps, logger, observability: observabilityOptions }) => {
|
|
8
8
|
let inputStream = stream ?? new MediaStream();
|
|
@@ -17,22 +17,40 @@ const prepareBrowserConnection = ({ stream, mirror, debugQuality, preferredVideo
|
|
|
17
17
|
} catch (error) {
|
|
18
18
|
logger.warn("Failed to mirror input stream; falling back to un-mirrored input", { error: error instanceof Error ? error.message : String(error) });
|
|
19
19
|
}
|
|
20
|
+
let pendingWorker;
|
|
21
|
+
if (debugQuality) try {
|
|
22
|
+
pendingWorker = createFrameMetadataWorker();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logger.warn("Frame-metadata worker unavailable; glass-to-glass latency measurement disabled", { error: error instanceof Error ? error.message : String(error) });
|
|
25
|
+
}
|
|
26
|
+
const frameTiming = pendingWorker !== void 0;
|
|
27
|
+
const takeFrameMetadataWorker = () => {
|
|
28
|
+
if (pendingWorker) {
|
|
29
|
+
const worker = pendingWorker;
|
|
30
|
+
pendingWorker = void 0;
|
|
31
|
+
return worker;
|
|
32
|
+
}
|
|
33
|
+
return createFrameMetadataWorker();
|
|
34
|
+
};
|
|
20
35
|
const observability = new RealtimeObservability({
|
|
21
36
|
...observabilityOptions,
|
|
22
|
-
glassToGlass:
|
|
37
|
+
glassToGlass: frameTiming ? createBrowserFrameMetadataDiagnostics() : void 0
|
|
23
38
|
});
|
|
24
|
-
if (debugQuality) inputStream = observability.attachOutgoingStream(inputStream, fps);
|
|
25
39
|
const safariCodec = isDesktopSafari() ? "vp8" : void 0;
|
|
26
40
|
return {
|
|
27
41
|
stream: inputStream,
|
|
28
42
|
observability,
|
|
43
|
+
frameTiming,
|
|
29
44
|
videoCodec: safariCodec ?? preferredVideoCodec,
|
|
30
|
-
queryParams: {
|
|
31
|
-
|
|
32
|
-
...
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
dispose:
|
|
45
|
+
queryParams: { ...safariCodec ? { livekit_server_codec: safariCodec } : {} },
|
|
46
|
+
createMediaChannel: (config) => createLiveKitMediaChannel({
|
|
47
|
+
...config,
|
|
48
|
+
createFrameMetadataWorker: frameTiming ? takeFrameMetadataWorker : void 0
|
|
49
|
+
}),
|
|
50
|
+
dispose: () => {
|
|
51
|
+
disposeMirroring();
|
|
52
|
+
pendingWorker?.terminate();
|
|
53
|
+
}
|
|
36
54
|
};
|
|
37
55
|
};
|
|
38
56
|
//#endregion
|
package/dist/realtime/client.js
CHANGED
|
@@ -20,11 +20,19 @@ const realTimeClientConnectOptionsSchema = z.object({
|
|
|
20
20
|
queryParams: z.record(z.string(), z.string()).optional(),
|
|
21
21
|
mirror: z.union([z.literal("auto"), z.boolean()]).optional(),
|
|
22
22
|
resolution: z.enum(["720p", "1080p"]).optional(),
|
|
23
|
+
/** Local track publish codec. Desktop Safari is always pinned to vp8 and ignores this value. */
|
|
23
24
|
preferredVideoCodec: z.enum([
|
|
24
25
|
"h264",
|
|
25
26
|
"vp8",
|
|
26
27
|
"vp9"
|
|
27
28
|
]).optional(),
|
|
29
|
+
/**
|
|
30
|
+
* Opt-in quality measurement using LiveKit frame metadata. The capture
|
|
31
|
+
* timestamp is propagated through inference and matched to output playout to
|
|
32
|
+
* surface true glass-to-glass `g2gMs` / `ttffMs` on the `stats` and
|
|
33
|
+
* `connectionQuality` signals. Browser-only and experimental because it
|
|
34
|
+
* relies on LiveKit's frame-metadata worker and encoded transforms.
|
|
35
|
+
*/
|
|
28
36
|
debugQuality: z.boolean().optional()
|
|
29
37
|
});
|
|
30
38
|
const createRealTimeClient = (opts) => {
|
|
@@ -80,6 +88,7 @@ const createRealTimeClient = (opts) => {
|
|
|
80
88
|
}).toString()}`,
|
|
81
89
|
integration,
|
|
82
90
|
observability,
|
|
91
|
+
frameTiming: preparedConnection.frameTiming,
|
|
83
92
|
localStream: preparedConnection.stream,
|
|
84
93
|
initialImage,
|
|
85
94
|
initialImageRef,
|