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:
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
_ => (),
|
||||
|
Reference in New Issue
Block a user