roa-websocket 0.5.0-rc

websocket implementation for roa
roa-websocket-0.5.0-rc doesn't have any documentation.

Stable Test codecov Rust Docs Crate version Download Version License: MIT

Roa-websocket

This crate provides a websocket endpoint.

Example

use futures::StreamExt;
use roa_router::{Router, RouterError};
use roa_websocket::Websocket;
use roa_core::{App, SyncContext};
use roa_core::http::Method;

# fn main() -> Result<(), RouterError> {
let mut app = App::new(());
let mut router = Router::new();
router.end(
    "/chat",
    [Method::GET],
    Websocket::new(|_ctx: SyncContext<()>, stream| async move {
        let (write, read) = stream.split();
        // echo
        if let Err(err) = read.forward(write).await {
            println!("forward err: {}", err);
        }
    }),
);
app.gate(router.routes("/")?);
Ok(())
# }