-
Notifications
You must be signed in to change notification settings - Fork 133
Add WebSocket fallback support #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
114d90e
7e6cf65
ad19149
0b43858
a934f76
2b59dbc
31539a7
76aa490
365f1c4
73e2b4a
469a58f
d5b810b
83053ee
e7dc3b0
456d6a8
902f2dd
f583419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ export type Partial = "full" | "partial" | "none"; | |
|
|
||
| export type Audio = { | ||
| aac: boolean; | ||
| opus: boolean; | ||
| opus: Partial; | ||
| }; | ||
|
Comment on lines
+8
to
9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid shadowing TypeScript’s built-in Using the name Apply these diffs here, and add the new alias at the top of the file (see snippet below): - opus: Partial;
+ opus: SupportLevel;Additional changes in this file within changed lines: - webtransport: Partial;
+ webtransport: SupportLevel;- capture: Partial;
+ capture: SupportLevel;- webtransport: typeof WebTransport !== "undefined" ? "full" : "partial",
+ webtransport: typeof WebTransport !== "undefined" ? "full" : "partial",- opus: (await audioEncoderSupported("opus")) ? "full" : "partial",
+ opus: (await audioEncoderSupported("opus")) ? "full" : "partial",- opus: (await audioDecoderSupported("opus")) ? "full" : "partial",
+ opus: (await audioDecoderSupported("opus")) ? "full" : "partial",Add this alias (outside the changed hunk) to replace the conflicting name: // Rename the status type to avoid clashing with TS's Partial<T>
export type SupportLevel = "full" | "partial" | "none";Follow-ups: update any imports/usages in the repo that referenced the exported 🤖 Prompt for AI Agents |
||
|
|
||
| export type Codec = { | ||
|
|
@@ -22,7 +22,7 @@ export type Video = { | |
| }; | ||
|
|
||
| export type Full = { | ||
| webtransport: boolean; | ||
| webtransport: Partial; | ||
| audio: { | ||
| capture: boolean; | ||
| encoding: Audio | undefined; | ||
|
|
@@ -115,21 +115,21 @@ async function videoEncoderSupported(codec: keyof typeof CODECS) { | |
|
|
||
| export async function isSupported(): Promise<Full> { | ||
| return { | ||
| webtransport: typeof WebTransport !== "undefined", | ||
| webtransport: typeof WebTransport !== "undefined" ? "full" : "partial", | ||
| audio: { | ||
| capture: typeof AudioWorkletNode !== "undefined", | ||
| encoding: | ||
| typeof AudioEncoder !== "undefined" | ||
| ? { | ||
| aac: await audioEncoderSupported("aac"), | ||
| opus: await audioEncoderSupported("opus"), | ||
| opus: (await audioEncoderSupported("opus")) ? "full" : "partial", | ||
| } | ||
| : undefined, | ||
| decoding: | ||
| typeof AudioDecoder !== "undefined" | ||
| ? { | ||
| aac: await audioDecoderSupported("aac"), | ||
| opus: await audioDecoderSupported("opus"), | ||
| opus: (await audioDecoderSupported("opus")) ? "full" : "partial", | ||
| } | ||
| : undefined, | ||
| render: typeof AudioContext !== "undefined" && typeof AudioBufferSourceNode !== "undefined", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| let loading: Promise<boolean> | undefined; | ||
|
|
||
| // Returns true when the polyfill is loaded. | ||
| export async function polyfill(): Promise<boolean> { | ||
| if (globalThis.AudioEncoder && globalThis.AudioDecoder) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!loading) { | ||
| console.warn("using Opus polyfill; performance may be degraded"); | ||
|
|
||
| // Load the polyfill and the libav variant we're using. | ||
| // TODO build with AAC support. | ||
| // NOTE: we use require here to avoid tsc errors with libavjs-webcodecs-polyfill. | ||
| loading = Promise.all([require("@libav.js/variant-opus"), require("libavjs-webcodecs-polyfill")]).then( | ||
| async ([opus, libav]) => { | ||
| await libav.load({ | ||
| LibAV: opus, | ||
| polyfill: true, | ||
| }); | ||
| return true; | ||
| }, | ||
| ); | ||
| } | ||
| return await loading; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unsupported ‘transfer’ from AudioData init.
AudioDataInit does not accept a transfer list; some engines may ignore it, others may throw. It doesn’t zero-copy anyway.
const frame = new AudioData({ format: "f32-planar", sampleRate: worklet.context.sampleRate, numberOfFrames: channels[0].length, numberOfChannels: channels.length, timestamp: data.timestamp, data: joined, - transfer: [joined.buffer], });📝 Committable suggestion
🤖 Prompt for AI Agents