-
Notifications
You must be signed in to change notification settings - Fork 146
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
How about impl AsyncRead/AsyncWrite for WebSocket? #25
Comments
Thanks for the report! I've transferred this over to the |
@alexcrichton ok, that's cool. Currently what I'm looking at is using the I would have to expose something that has I also wonder, if I understood well, data from javascript has to be copied into the wasm memory. Is there a way to avoid this extra copy on the data that comes in from the websocket? |
See also #7 |
I'm making good progress on this I think, but I need a bit of advice. There isn't all that much example code or docs for this stuff. I can build streams that yield MessageEvent, but then the only way I see from the docs to get the data out of there and in rust is by using into_serde. This will use json stringify... I doubt that's what we want. There seem to be ways to share memory pointers from javascript like with WebAssembly.Memory and such, but what is the best way to get a bytearray out of a websocket connection into rust with wasm-bindgen, wasm-pack? Do I just write custom javascript for this? Given that this is a rust library, how do we ship the js? |
Never mind, I found how to make a UInt8Array out of it and use |
In the spirit of abstraction it might be pretty cool to get a stream of I'm not too familiar with the websocket interface, but if you can specify a buffer to fill in then you can fill in wasm memory directly, otherwise you'll have to copy it in afterwards |
Currently I have a sink/stream working that takes and yields |
Ok, it took a few days longer than I had hoped, but here it is: https://github.com/najamelan/wasm_websocket_stream It would be nice if people could review this code. There are review questions in the readme. Please open issues on the repository for review feedback. |
Motivation
Would allow frontend and backend code to communicate in an abstract manner on an async Stream. It allows code reuse and prevents every application to have to implement this on top of the existing websocket api
Proposed Solution
Add impl AsyncRead/AsyncWrite to websocket
Alternatives
Allow upgrading an Http connection to an AsyncRead/AsyncWrite without websockets. I have no idea what the implementation of this would look like, and if it's even possible without websockets.
That being said, this alternative would be preferable I think. It means we don't need WS on the server either, just an upgraded http connection.
Additional Context
I kind of need this. If need be I don't mind attempting to implement this myself. If this is deemed a good solution, is there any mentoring possible to hint the way?
The text was updated successfully, but these errors were encountered: