Skip to content
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

Implement WebSockets #11

Open
nitely opened this issue May 29, 2024 · 9 comments
Open

Implement WebSockets #11

nitely opened this issue May 29, 2024 · 9 comments

Comments

@nitely
Copy link
Owner

nitely commented May 29, 2024

Not sure how useful this is, WS over http2 seems supported by firefox and chrome at least.

For the hyperx client/server is kinda pointless, http2 supports sending any number of data frames back and forth over a single stream.

@nitely
Copy link
Owner Author

nitely commented May 29, 2024

There is also fetch streaming on browsers but for some reason they restricted it to half duplex, you either stream the request data or the response data, but not both. If full duplex is ever supported, it could replace websocket use cases. See whatwg/fetch#1254

Well, half-duplex does allow to create a stream for receiving and one for sending, but then the server needs a way to associate both streams, like some sort of ID and possibly an external pub/sub, which makes things a lot more complex than they should be.

@guest271314
Copy link

There is also fetch streaming on browsers but for some reason they restricted it to half duplex, you either stream the request data or the response data, but not both.

Technically on Chromium based browsers it is possible to full-duplex stream between a ServiceWorker and a WindowClient or Client. See https://plnkr.co/plunk/2PQK21kZTZvZ2oVi.

Well, half-duplex does allow to create a stream for receiving and one for sending, but then the server needs a way to associate both streams, like some sort of ID and possibly an external pub/sub, which makes things a lot more complex than they should be.

Not sure what is meant here. In the server, if the client uploads a ReadableStream you can process that stream and send a ReadableStream to the client using the same connection.

@nitely
Copy link
Owner Author

nitely commented Oct 20, 2024

That seems half-duplex. It does not matter that you can create a js stream out of a request/response. Full duplex allows to receive/send in a ping-pong way over one single stream, that's not supported in anyway other than websockets, AFAIK.

@guest271314
Copy link

Full duplex allows to receive/send in a ping-pong way over one single stream

That's exactly what is happening in the linked plnkr.

@guest271314
Copy link

Full duplex allows to receive/send in a ping-pong way over one single stream, that's not supported in anyway other than websockets, AFAIK.

Both Node.js and Deno support full-duplex streaming using WHATWG Fetch. The only case in the browser where that is possible that I am aware of is between a ServiceWorker and a WindowClient or Client, in Chromium-based browsers (Chromium, Chrome, Brave, Edge, Opera).

@guest271314
Copy link

that's not supported in anyway other than websockets, AFAIK.

Yes, WebSocket and WebSocketStream support that. So does WICG Direct Sockets TCPSocket and TCPServerSocket, which are both exposed in Chromium within an Isolated Web App. There are ways to implement sending and receiving those streams to any arbitrary window.

@nitely
Copy link
Owner Author

nitely commented Oct 20, 2024

I don't see how this is relevant to this issue, but good to know ig.

That's exactly what is happening in the linked plnkr.

my bad, I only read the code at first, and it's kinda iffy, but it seems to work as you say.

@guest271314
Copy link

I think you mentioned something about streaming in a Bun issue. My machine crashed in the interim, I'm running on RAM only, so I don't have the exactly link I followed. In general I'm interested in WHATWG Streams, WHATWG Fetch, standard streams, media streaming, and streaming in general is probably why I commented here.

@guest271314
Copy link

FWIW Here's how I control Node.js and Deno HTTP/2 streams over fetch() from the browser

Here's a JavaScript runtime agnostic WebSocket server run from Chromium - where we can keep a single WebSocketStream connection established and open indefinitely

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants