Convenient WebSockets in Rust WASM

I just released ws_stream_wasm. This crate builds a idiomatic convenience layer in front of web_sys::WebSocket which is unwieldy to use in it's raw form. You can now comfortably use websockets in rust WASM.

The crate also provides a futures 0.3 Sink/Stream for websocket messages and it provides AsyncRead/AsyncWrite, which allows framing the websocket connection with arbitrary codecs.

I tried to provide all useful functionality. Upon connection you get 2 objects, one for interacting with the connection metadata and one for the Stream/Sink/AsyncWrite/AsyncRead. This way, when you consume the stream with futures combinators, you can still interact with the meta object. The meta object is also observable through pharos so you can listen to events like (connection closed) without having to set JavaScript event handlers.

The examples directory is a bit empty right now, but there is extensive integration tests covering all features of the library. I will add a chat example when I can make time.

Note that there is no server websocket crate that provides AsyncRead/AsyncWrite at the moment. I'm developing a sister crate called ws_stream for that, but it's not ready for publication on I won't be available for programming next week, but I plan to wrap up ws_stream the first week of August. In the mean time it is functional, eg for running the integration tests from ws_stream_wasm, and can be cloned from github, but there will be most likely breaking changes before release.

This allows communication to WASM of any systems that work on AsyncRead/AsyncWrite. I'm working on an actor library which has remote actors functionning in this way. As soon as I have time to connect it all together this will mean remote actors in the browser that communicate with servers in exactly the same way other processes will be able to exchange actor messages over any AsyncRead/Write.

update: futures-codec is fixed, and ci tests are passing :wink:


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.