From c05442fad7c1fc17bb831ea8f56f559da34386e2 Mon Sep 17 00:00:00 2001 From: Object905 Date: Tue, 31 Mar 2026 12:09:26 +0300 Subject: [PATCH] feat: Custom command/event with json data --- src/call/active_call.rs | 12 ++++++++++++ src/call/mod.rs | 4 ++++ src/event.rs | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/src/call/active_call.rs b/src/call/active_call.rs index 7a684ba..ec8e7ae 100644 --- a/src/call/active_call.rs +++ b/src/call/active_call.rs @@ -761,6 +761,7 @@ impl ActiveCall { fade_out_ms: _, } => self.do_interrupt(passage.unwrap_or_default()).await, Command::History { speaker, text } => self.do_history(speaker, text).await, + Command::Custom { sender, data } => self.do_custom(sender, data), } } @@ -1168,6 +1169,17 @@ impl ActiveCall { .map_err(Into::into) } + fn do_custom(&self, sender: Option, data: serde_json::Value) -> Result<()> { + self.event_sender + .send(SessionEvent::Custom { + timestamp: crate::media::get_timestamp(), + sender, + data, + }) + .map(|_| ()) + .map_err(Into::into) + } + async fn do_interrupt(&self, graceful: bool) -> Result<()> { { let mut state = self.call_state.write().await; diff --git a/src/call/mod.rs b/src/call/mod.rs index a8ae4b0..ad23864 100644 --- a/src/call/mod.rs +++ b/src/call/mod.rs @@ -92,6 +92,10 @@ pub enum Command { speaker: String, text: String, }, + Custom { + sender: Option, + data: serde_json::Value, + }, } /// Routing state for managing stateful load balancing diff --git a/src/event.rs b/src/event.rs index 82bee31..015bed6 100644 --- a/src/event.rs +++ b/src/event.rs @@ -203,6 +203,11 @@ pub enum SessionEvent { timestamp: u64, payload: Option, }, + Custom { + timestamp: u64, + sender: Option, + data: serde_json::Value, + }, } impl Display for SessionEvent {