Skip to content

wsocket-io/sdk-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wSocket Rust SDK

Official Rust SDK for wSocket — Realtime Pub/Sub over WebSockets.

Crates.io docs.rs License: MIT

Installation

Add to your Cargo.toml:

[dependencies]
wsocket-io = "0.1.0"

Quick Start

use wsocket_io::Client;

#[tokio::main]
async fn main() {
    let client = Client::connect("wss://node00.wsocket.online", "your-api-key")
        .await
        .unwrap();

    let chat = client.channel("chat:general").await;

    chat.subscribe(|data, meta| {
        println!("[{}] {}", meta.channel, data);
    }).await;

    chat.publish(serde_json::json!({"text": "Hello from Rust!"})).await;

    client.wait().await;
}

Features

  • Pub/Sub — Subscribe and publish to channels in real-time
  • Presence — Track who is online in a channel
  • History — Retrieve past messages
  • Connection Recovery — Automatic reconnection with message replay
  • Async — Built on tokio and tokio-tungstenite

Presence

let chat = client.channel("chat:general").await;

chat.presence().on_enter(|m| {
    println!("joined: {}", m.client_id);
}).await;

chat.presence().on_leave(|m| {
    println!("left: {}", m.client_id);
}).await;

chat.presence().enter(serde_json::json!({"name": "Alice"})).await;
let members = chat.presence().get().await;

History

chat.on_history(|result| {
    for msg in &result.messages {
        println!("[{}] {}", msg.timestamp, msg.data);
    }
}).await;

chat.history(HistoryOptions { limit: Some(50), ..Default::default() }).await;

Requirements

  • Rust edition 2021+
  • tokio, tokio-tungstenite, serde, serde_json

Development

cargo build
cargo test

License

MIT

About

wSocket Rust SDK — Realtime Pub/Sub client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages