mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Start to create WebSocket actor
This commit is contained in:
parent
2ce94f19f1
commit
9d67565517
@ -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<Self>;
|
||||
}
|
||||
|
||||
impl StreamHandler<Result<actix_web_actors::ws::Message, actix_web_actors::ws::ProtocolError>> for RtcRelayActor {
|
||||
fn handle(&mut self, msg: Result<Message, ProtocolError>, 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user