Trait backtalk::Channel
[−]
[src]
pub trait Channel: Send + Sync { fn join(&self, _: Sender, _: Option<String>, _: JsonObject); fn send(&self, _: &str, _: &JsonObject); fn handle(&self, req: Request) -> BoxFuture<Reply, Error> { ... } }
Converts a Request into a streaming Reply, and routes incoming messages to outgoing streams.
If you're using a pre-existing Channel
implementation, you probably just want to use the handle
function, which creates the streaming replies. Third-party Channel
s that implement join
and
send
get the handle
function for free.
Required Methods
fn join(&self, _: Sender, _: Option<String>, _: JsonObject)
Called when a new streamed reply is created in the handle
function. The Sender
is the object
representing the connected client — you can call sender.send
to send messages to this client.
The Option<String>
is the ID in the URL — for instance, a subscription to /cats
would
have an ID of None
, and a subscription to /cats/123
would have an ID of Some("123")
. The
JsonObject
is the params object of the request, and can be used for authenticating users.
fn send(&self, _: &str, _: &JsonObject)
Called by application code to send a new message to connected clients. Channel implementors are also free to add additional functions that send messages with additional paramaters, such as specifying which users get notified.
Provided Methods
fn handle(&self, req: Request) -> BoxFuture<Reply, Error>
Takes a Request
and returns a Reply
future with a streaming Reply
body. If you're using a
channel in your server's application code, this is the function you'll want to use.
Implementors
impl Channel for MemoryChannel