1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 18:09:22 +02:00

refactor websockets handling

This commit is contained in:
Nikolay Kim
2018-02-27 10:09:24 -08:00
parent a344c3a02e
commit 5dcb558f50
10 changed files with 265 additions and 192 deletions

View File

@ -92,8 +92,7 @@ impl Handler<session::Message> for WsChatSession {
}
/// WebSocket message handler
impl Handler<ws::Message> for WsChatSession {
type Result = ();
impl StreamHandler<ws::Message, ws::WsError> for WsChatSession {
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
println!("WEBSOCKET MESSAGE: {:?}", msg);
@ -161,7 +160,7 @@ impl Handler<ws::Message> for WsChatSession {
},
ws::Message::Binary(bin) =>
println!("Unexpected binary"),
ws::Message::Close(_) | ws::Message::Error => {
ws::Message::Close(_) => {
ctx.stop();
}
}

View File

@ -12,7 +12,7 @@ use std::time::Duration;
use actix::*;
use futures::Future;
use actix_web::ws::{Message, WsClientError, WsClient, WsClientWriter};
use actix_web::ws::{Message, WsError, WsClient, WsClientWriter};
fn main() {
@ -93,7 +93,7 @@ impl Handler<ClientCommand> for ChatClient {
}
/// Handle server websocket messages
impl StreamHandler<Message, WsClientError> for ChatClient {
impl StreamHandler<Message, WsError> for ChatClient {
fn handle(&mut self, msg: Message, ctx: &mut Context<Self>) {
match msg {

View File

@ -25,8 +25,7 @@ impl Actor for MyWebSocket {
}
/// Handler for `ws::Message`
impl Handler<ws::Message> for MyWebSocket {
type Result = ();
impl StreamHandler<ws::Message, ws::WsError> for MyWebSocket {
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
// process websocket messages
@ -35,7 +34,7 @@ impl Handler<ws::Message> for MyWebSocket {
ws::Message::Ping(msg) => ctx.pong(&msg),
ws::Message::Text(text) => ctx.text(text),
ws::Message::Binary(bin) => ctx.binary(bin),
ws::Message::Close(_) | ws::Message::Error => {
ws::Message::Close(_) => {
ctx.stop();
}
_ => (),