-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(http): upgradeWebSocketStream #20287
base: main
Are you sure you want to change the base?
Conversation
Just to explain my motivations in short; From my understanding, the long-term goal is to return a Deno already provides an unstable However, my main motivation is that how-/whenever the Going further, it might not be a crazy idea to keep both |
I am overall in favour of this or #16732, however I think the other PR is better in terms of API, as it adds less changes to the overall API surface. This one is potentially more confusing for newer people, as there are 2 similar functions and not sure which they should use. But these are all personal nitpicks |
It makes more sense to add upgradeWebSocketStream as a separate function and keep the original upgradeWebSocket for compatibility |
I just merged in |
I think adding |
The https://developer.chrome.com/docs/capabilities/web-apis/websocketstream |
@haochuan9421 I agree with your sentiment that keeping I don't know why, but in Deno's As for why the PR is on ice, I don't know, I assume it isn't a high priority, maybe because there hasn't been much movement with the I'll be happy to pull changes (into the PR branch) and get everything up to date again if I get an indication that this can move forward. |
I agree that only keep the client side async function socketReady(socket: WebSocket) {
if (socket.bufferedAmount < 4194304) {
return;
}
await new Promise((r) => setTimeout(r, 0));
return socketReady(socket);
}
Deno.serve((req) => {
if (req.headers.get("upgrade") != "websocket") {
return new Response(null, { status: 501 });
}
const { socket, response } = Deno.upgradeWebSocket(req);
socket.onopen = async () => {
try {
const file = await Deno.open('some_large_file');
for await (const chunk of file.readable) {
socket.send(chunk);
await socketReady(socket);
}
} catch (error) {
console.log("Error: ", error);
} finally {
socket.close();
}
};
return response;
}); |
@crowlKats I urgently request that this feature be reviewed and implemented in Deno as soon as possible! |
We've been checking in about the status of WebSocketStream spec and it's still not-close to being stabilized. I don't think we will land this PR until the spec stabilizes. |
Closes #14064
Added unstable
upgradeWebSocketStream
to enable server-sideWebSocketStream
usage. I took some inspiration from #16732, which seemed to have gone stale and had some issues. Idle timeout (ping interval) didn't work as[_serverHandleIdleTimeout]
was never called, and op calls were outdated.