wsprism_gateway/services/
echo_binary.rs1use async_trait::async_trait;
2
3use wsprism_core::error::Result;
4use wsprism_core::protocol::hot::HotFrame;
5
6use crate::dispatch::BinaryService;
7use crate::realtime::{Outgoing, Payload, QoS, RealtimeCtx};
8
9pub struct EchoBinaryService {
13 svc_id: u8,
14}
15
16impl EchoBinaryService {
17 pub fn new(svc_id: u8) -> Self {
18 Self { svc_id }
19 }
20}
21
22#[async_trait]
23impl BinaryService for EchoBinaryService {
24 fn svc_id(&self) -> u8 {
25 self.svc_id
26 }
27
28 async fn handle_binary(&self, ctx: RealtimeCtx, frame: HotFrame) -> Result<()> {
29 let out = Outgoing {
30 qos: QoS::Lossy,
31 payload: Payload::Binary(frame.payload.clone()),
32 };
33
34 if let Some(room) = ctx.active_room() {
35 ctx.publish_room_lossy(room, out)?;
37 Ok(())
38 } else {
39 ctx.send_to_session(out)?;
41 Ok(())
42 }
43 }
44}