Skip to main content

flowcat_core/serializer/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2//
3//! Per-carrier WebSocket framing. **Pure** (no I/O): turns inbound frames into
4//! normalized [`SerIn`] events and encodes outbound audio/clears into [`WsOut`].
5//!
6//! See DESIGN.md "Trait contracts". The one concrete serializer is `plivo`
7//! (Plivo `<Stream>` JSON+base64). SIP/RTP carriers do not use a WS-media
8//! serializer — they ride native SIP/RTP ([`crate::sip`]), so the former
9//! FreeSWITCH `gateway` serializer was removed (see SIP-DESIGN.md §4).
10
11pub mod plivo;
12
13use crate::types::{AudioChunk, SerIn, WsIn, WsOut};
14
15pub use plivo::PlivoSerializer;
16
17/// Carrier-specific WS framing. Implementations are pure functions over frames
18/// (no sockets, no async) so they are trivially unit-testable.
19pub trait MediaSerializer: Send {
20    /// Normalize one inbound frame into a [`SerIn`] event.
21    fn on_message(&mut self, msg: &WsIn) -> SerIn;
22
23    /// Encode an outbound audio chunk into a frame to send back to the carrier.
24    fn encode_audio(&self, chunk: &AudioChunk) -> WsOut;
25
26    /// Encode a "clear/flush queued audio" control frame for barge-in, if the
27    /// carrier supports one.
28    fn encode_clear(&self) -> Option<WsOut>;
29
30    /// The carrier-side audio sample rate (e.g. 8000 for telephony μ-law).
31    fn carrier_rate(&self) -> u32;
32}