socketio-rust-emitter

Crates.iosocketio-rust-emitter
lib.rssocketio-rust-emitter
version0.1.2
sourcesrc
created_at2019-05-23 16:52:32.814967
updated_at2019-05-23 17:13:02.371576
descriptionA Rust implementation of socketio-emitter
homepagehttps://github.com/epli2/socketio-rust-emitter
repositoryhttps://github.com/epli2/socketio-rust-emitter
max_upload_size
id136459
size7,341
Ryo Motozawa (epli2)

documentation

README

socketio-rust-emitter

Build Status socketio-rust-emitter at crates.io socketio-rust-emitter at docs.rs

A Rust implementation of socket.io-emitter.

How to use

use chrono::Utc;
use std::thread;
use std::time::Duration;

let io = Emitter::new("127.0.0.1");
let _ = thread::spawn(move || loop {
    thread::sleep(Duration::from_millis(5000));
    io.clone().emit(vec!["time", &format!("{}", Utc::now())]);
}).join();
// Different constructor options.

//1. Initialize with host:port string
let io = Emitter::new("localhost:6379")
// 2. Initlize with host, port object.
let io = Emitter::new(EmitterOpts {
    host: "localhost".to_owned(),
    port: 6379,
    ..Default::default()
});

Examples

let io = Emitter::new(EmitterOpts { host: "127.0.0.1".to_owned(), port: 6379, ..Default::default() });

// sending to all clients
io.clone().emit(vec!["broadcast", /* ... */]);

// sending to all clients in "game" room
io.clone().to("game").emit(vec!["new-game", /* ... */]);

// sending to individual socketid (private message)
io.clone().to(<socketid>).emit(vec!["private", /* ... */]);

let nsp = io.clone().of("/admin");

// sending to all clients in "admin" namespace
nsp.clone().emit(vec!["namespace", /* ... */]);

// sending to all clients in "admin" namespace and in "notifications" room
nsp.clone().to("notifications").emit(vec!["namespace", /* ... */]);
Commit count: 51

cargo fmt