#websocket-client #async #wasm #tokio #api-bindings

async-wsocket

A convenience library for using websockets both in native and WASM environments! Include embedded tor client support

9 breaking releases

0.10.0 Nov 5, 2024
0.8.0 Sep 4, 2024
0.6.0 Jul 31, 2024
0.4.0 Mar 27, 2024

#36 in WebSocket

Download history 886/week @ 2024-07-29 650/week @ 2024-08-05 907/week @ 2024-08-12 908/week @ 2024-08-19 1040/week @ 2024-08-26 2624/week @ 2024-09-02 1714/week @ 2024-09-09 1995/week @ 2024-09-16 1847/week @ 2024-09-23 2708/week @ 2024-09-30 1571/week @ 2024-10-07 1068/week @ 2024-10-14 1959/week @ 2024-10-21 2028/week @ 2024-10-28 2579/week @ 2024-11-04 1911/week @ 2024-11-11

8,629 downloads per month
Used in 28 crates (2 directly)

MIT license

77KB
1.5K SLoC

Async WebSocket

A convenience library for using websockets both in native and WASM environments! Include embedded tor client support.

use std::time::Duration;

use async_wsocket::{ConnectionMode, Url, WsMessage};
use futures_util::{SinkExt, StreamExt};

const NONCE: u64 = 123456789;

#[tokio::main]
async fn main() {
    let url =
        Url::parse("ws://oxtrdevav64z64yb7x6rjg4ntzqjhedm5b5zjqulugknhzr46ny2qbad.onion").unwrap();
    let (mut tx, mut rx) =
        async_wsocket::connect(&url, ConnectionMode::tor(), Duration::from_secs(120))
            .await
            .unwrap();

    // Send ping
    let nonce = NONCE.to_be_bytes().to_vec();
    tx.send(WsMessage::Ping(nonce.clone())).await.unwrap();

    // Listen for messages
    while let Some(msg) = rx.next().await {
        if let Ok(WsMessage::Pong(bytes)) = msg {
            assert_eq!(nonce, bytes);
            println!("Pong match!");
            break;
        }
    }
}

Crate Feature Flags

The following crate feature flags are available:

Feature Default Description
socks No Enable socks proxy support
tor No Enable embedded tor client support

Minimum Supported Rust Version (MSRV)

The MSRV for this project when compiled with default features and on native targets is 1.63.0. When using tor feature, MSRV is 1.70.0. MSRV for WASM targets is 1.73.0

License

This project is distributed under the MIT software license - see the LICENSE file for details

Donations

⚡ Tips: https://getalby.com/p/yuki

⚡ Lightning Address: yuki@getalby.com

Dependencies

~3–26MB
~378K SLoC