Skip to main content

flowcat_core/transport/
socket.rs

1// SPDX-License-Identifier: Apache-2.0
2//
3//! The `MediaSocket` trait — Flowcat's transport-agnostic media seam.
4//!
5//! Flowcat does not own the socket; the host adapts whatever it has (an axum WS,
6//! a tungstenite client, a mock) to this trait. See DESIGN.md "Trait contracts".
7
8use async_trait::async_trait;
9
10use crate::error::FlowcatError;
11use crate::types::WsIn;
12
13/// A bidirectional media socket carrying text/binary WebSocket frames.
14///
15/// Implementations are driven (via [`MediaTransport`](crate::transport::MediaTransport))
16/// by the [S2S pipeline](crate::pipeline::build_s2s_task): `recv` yields inbound
17/// frames; `send_text`/`send_binary` push outbound frames.
18#[async_trait]
19pub trait MediaSocket: Send {
20    /// Receive the next inbound frame, or `None` once the socket is exhausted.
21    async fn recv(&mut self) -> Option<WsIn>;
22
23    /// Send a UTF-8 text frame.
24    async fn send_text(&mut self, s: String) -> Result<(), FlowcatError>;
25
26    /// Send a binary frame.
27    async fn send_binary(&mut self, b: Vec<u8>) -> Result<(), FlowcatError>;
28}