Skip to main content

mojentic/realtime/
gateway.rs

1//! Realtime voice gateway trait.
2
3use crate::realtime::config::RealtimeVoiceConfig;
4use crate::realtime::transport::TransportError;
5use async_trait::async_trait;
6use serde_json::Value;
7
8pub type ClientRealtimeEvent = Value;
9pub type ServerRealtimeEvent = Value;
10
11#[async_trait]
12pub trait RealtimeGatewaySession: Send + Sync {
13    fn session_id(&self) -> &str;
14    async fn send_event(&mut self, event: &Value) -> Result<(), TransportError>;
15    async fn next_event(&mut self) -> Option<Value>;
16    async fn close(&mut self) -> Result<(), TransportError>;
17    fn is_closed(&self) -> bool;
18}
19
20#[async_trait]
21pub trait RealtimeVoiceGateway: Send + Sync {
22    async fn open(
23        &self,
24        model: &str,
25        config: &RealtimeVoiceConfig,
26        correlation_id: Option<&str>,
27    ) -> Result<Box<dyn RealtimeGatewaySession>, TransportError>;
28}