-
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 12 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 |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ | |
| ], | ||
| "files": [ | ||
| "./src", | ||
| "./dist", | ||
| "README.md", | ||
| "tsconfig.json" | ||
| ], | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,12 @@ import type * as Path from "./path"; | |||||||||||||||||||||
| import { Stream } from "./stream"; | ||||||||||||||||||||||
| import * as Hex from "./util/hex"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Check if we need to load the WebSocket polyfill. | ||||||||||||||||||||||
| let polyfill: Promise<typeof import("@kixelated/web-transport-ws")>; | ||||||||||||||||||||||
| if (typeof globalThis !== "undefined" && !("WebTransport" in globalThis)) { | ||||||||||||||||||||||
| polyfill = import("@kixelated/web-transport-ws"); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| export interface Connection { | ||||||||||||||||||||||
| readonly url: URL; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -26,33 +32,45 @@ export async function connect(url: URL): Promise<Connection> { | |||||||||||||||||||||
| const options: WebTransportOptions = { | ||||||||||||||||||||||
| allowPooling: false, | ||||||||||||||||||||||
| congestionControl: "low-latency", | ||||||||||||||||||||||
| requireUnreliable: true, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let adjustedUrl = url; | ||||||||||||||||||||||
| let finalUrl = url; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| let quic: WebTransport; | ||||||||||||||||||||||
| if (polyfill) { | ||||||||||||||||||||||
| console.warn("Using web-transport-ws polyfill; user experience may suffer during congestion."); | ||||||||||||||||||||||
| const WebTransportWs = (await polyfill).default; | ||||||||||||||||||||||
| quic = new WebTransportWs(finalUrl, options); | ||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| // Only perform certificate fetch and URL rewrite when polyfill is not needed | ||||||||||||||||||||||
| // This is needed because WebTransport is a butt to work with in local development. | ||||||||||||||||||||||
| if (url.protocol === "http:") { | ||||||||||||||||||||||
| const fingerprintUrl = new URL(url); | ||||||||||||||||||||||
| fingerprintUrl.pathname = "/certificate.sha256"; | ||||||||||||||||||||||
| fingerprintUrl.search = ""; | ||||||||||||||||||||||
| console.warn( | ||||||||||||||||||||||
| fingerprintUrl.toString(), | ||||||||||||||||||||||
| "performing an insecure fingerprint fetch; use https:// in production", | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (url.protocol === "http:") { | ||||||||||||||||||||||
| const fingerprintUrl = new URL(url); | ||||||||||||||||||||||
| fingerprintUrl.pathname = "/certificate.sha256"; | ||||||||||||||||||||||
| fingerprintUrl.search = ""; | ||||||||||||||||||||||
| console.warn(fingerprintUrl.toString(), "performing an insecure fingerprint fetch; use https:// in production"); | ||||||||||||||||||||||
| // Fetch the fingerprint from the server. | ||||||||||||||||||||||
| const fingerprint = await fetch(fingerprintUrl); | ||||||||||||||||||||||
| const fingerprintText = await fingerprint.text(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
||||||||||||||||||||||
| // Fetch the fingerprint from the server. | |
| const fingerprint = await fetch(fingerprintUrl); | |
| const fingerprintText = await fingerprint.text(); | |
| // Fetch the fingerprint from the server. | |
| - const fingerprint = await fetch(fingerprintUrl); | |
| const res = await fetch(fingerprintUrl); | |
| if (!res.ok) { | |
| throw new Error(`fingerprint fetch failed: ${res.status} ${res.statusText}`); | |
| } | |
| const fingerprintText = (await res.text()).trim(); |
🤖 Prompt for AI Agents
In js/moq/src/connection.ts around lines 56 to 59, the code fetches the
fingerprint but doesn't validate the HTTP status or trim whitespace; update the
fetch to check response.ok (or status === 200) and if not, read the response
text and throw an error including the HTTP status and response body to avoid
opaque failures on 404/HTML, then call .text(), trim the result (e.g.
fingerprintText.trim()) and use the trimmed fingerprint; ensure any thrown
errors include context (URL and status) for easier debugging.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.