From 9d675655170ac26fcba23bcf653bee5efc7d3e78 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 8 Feb 2021 17:34:20 +0100 Subject: [PATCH] Start to create WebSocket actor --- src/controllers/rtc_relay_controller.rs | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/controllers/rtc_relay_controller.rs b/src/controllers/rtc_relay_controller.rs index aca03c3..8a8c950 100644 --- a/src/controllers/rtc_relay_controller.rs +++ b/src/controllers/rtc_relay_controller.rs @@ -2,8 +2,33 @@ //! //! @author Pierre Hubert +use actix::{ActorContext, StreamHandler}; +use actix_web_actors::ws::{Message, ProtocolError}; + use crate::data::config::conf; +struct RtcRelayActor {} + +impl actix::Actor for RtcRelayActor { + type Context = actix_web_actors::ws::WebsocketContext; +} + +impl StreamHandler> for RtcRelayActor { + fn handle(&mut self, msg: Result, ctx: &mut Self::Context) { + let msg = match msg { + Err(_) => { + ctx.stop(); + return; + } + Ok(msg) => msg + }; + + if conf().verbose_mode { + println!("RTC RELAY WS MESSAGE: {:?}", msg); + } + } +} + /// Establish a new connection with the RTC relay /// /// Debug with @@ -38,5 +63,6 @@ pub async fn open_ws(req: actix_web::HttpRequest, return Ok(actix_web::HttpResponse::Unauthorized().body("Invalid token!")); } - unreachable!(); + // Start the actor + actix_web_actors::ws::start(RtcRelayActor {}, &req, stream) } \ No newline at end of file