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