rsocket / rsocket-rust

RSocket Rust Implementation using Tokio
Apache License 2.0
200 stars 20 forks source link

WebAssembly support #5

Closed linux-china closed 4 years ago

linux-china commented 4 years ago

Construct transport layer and delegate the requests to Wasm Runtime, no API change for to compile Rust to WebAssembly. Now just client transport required only. For example WasmClientTransport, can accept "ws://xxx:8080/rsocket" or "tcp://xxx:42252", and requests will be delegated to Wasm runtime(Browser, Node) by calling import functions. Example as following:

RSocketFactory::connect()
        .acceptor(|| Box::new(EchoRSocket))
        .transport(WasmClientTransport::new("ws://localhost:8080/rsocket"))
        .setup(Payload::from("I am Wasm Requester!"))
        .mime_type("text/plain", "text/plain")
jjeffcaii commented 4 years ago

I'm making a plan for supporting an abstract transport layer. For any kind of transport, you just need to implement a transport trait.

pub trait ClientTransport {
    fn attach(
        self,
        incoming: Tx<Frame>,
        sending: Rx<Frame>,
    ) -> Pin<Box<dyn Sync + Send + Future<Output = Result<(), Box<dyn Error + Send + Sync>>>>>;
}

PS: incoming means frames should received and sending means frames you want to send.

jjeffcaii commented 4 years ago

WASM feature is released in v0.5.0.