Struct SessionHandle
pub struct SessionHandle {
pub command_tx: Sender<SessionCommand>,
pub state: Arc<SessionState>,
/* private fields */
}Expand description
The public API surface for a Gemini Live session.
Cheaply cloneable (wraps Arc). Provides methods to send commands,
subscribe to events, and observe session state.
Fields§
§command_tx: Sender<SessionCommand>Channel for sending commands to the transport layer.
state: Arc<SessionState>Shared session state.
Implementations§
§impl SessionHandle
impl SessionHandle
pub fn new(
command_tx: Sender<SessionCommand>,
event_tx: Sender<SessionEvent>,
state: Arc<SessionState>,
phase_rx: Receiver<SessionPhase>,
) -> SessionHandle
pub fn new( command_tx: Sender<SessionCommand>, event_tx: Sender<SessionEvent>, state: Arc<SessionState>, phase_rx: Receiver<SessionPhase>, ) -> SessionHandle
Create a new session handle from its components.
pub fn set_task(&self, handle: JoinHandle<()>)
pub fn set_task(&self, handle: JoinHandle<()>)
Store the connection loop task handle.
Called by the transport layer after spawning the connection loop.
pub async fn join(&self) -> Result<(), JoinError>
pub async fn join(&self) -> Result<(), JoinError>
Wait for the session connection loop to complete.
Returns Ok(()) when the session disconnects normally.
Returns Err if the connection task panicked.
Only the first call across all clones actually awaits the task;
subsequent calls return Ok(()) immediately.
pub fn subscribe(&self) -> Receiver<SessionEvent>
pub fn subscribe(&self) -> Receiver<SessionEvent>
Subscribe to session events.
pub fn event_sender(&self) -> &Sender<SessionEvent>
pub fn event_sender(&self) -> &Sender<SessionEvent>
Get the event sender (for internal use by transport).
pub fn phase(&self) -> SessionPhase
pub fn phase(&self) -> SessionPhase
Current session phase.
pub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Session ID.
pub async fn wait_for_phase(&self, target: SessionPhase)
pub async fn wait_for_phase(&self, target: SessionPhase)
Wait for the session to reach a specific phase.
pub async fn send_audio(&self, data: Vec<u8>) -> Result<(), SessionError>
pub async fn send_audio(&self, data: Vec<u8>) -> Result<(), SessionError>
Send audio data (raw PCM16 bytes).
pub async fn send_text(
&self,
text: impl Into<String>,
) -> Result<(), SessionError>
pub async fn send_text( &self, text: impl Into<String>, ) -> Result<(), SessionError>
Send a text message.
pub async fn send_tool_response(
&self,
responses: Vec<FunctionResponse>,
) -> Result<(), SessionError>
pub async fn send_tool_response( &self, responses: Vec<FunctionResponse>, ) -> Result<(), SessionError>
Send tool responses.
pub async fn send_video(&self, jpeg_data: Vec<u8>) -> Result<(), SessionError>
pub async fn send_video(&self, jpeg_data: Vec<u8>) -> Result<(), SessionError>
Send a video/image frame (raw JPEG bytes).
pub async fn update_instruction(
&self,
instruction: impl Into<String>,
) -> Result<(), SessionError>
pub async fn update_instruction( &self, instruction: impl Into<String>, ) -> Result<(), SessionError>
Update the system instruction mid-session.
pub async fn signal_activity_start(&self) -> Result<(), SessionError>
pub async fn signal_activity_start(&self) -> Result<(), SessionError>
Signal activity start (user started speaking).
pub async fn signal_activity_end(&self) -> Result<(), SessionError>
pub async fn signal_activity_end(&self) -> Result<(), SessionError>
Signal activity end (user stopped speaking).
pub async fn send_client_content(
&self,
turns: Vec<Content>,
turn_complete: bool,
) -> Result<(), SessionError>
pub async fn send_client_content( &self, turns: Vec<Content>, turn_complete: bool, ) -> Result<(), SessionError>
Send client content (turns + turn_complete flag). Used for injecting conversation history, context, or multi-turn text.
pub async fn disconnect(&self) -> Result<(), SessionError>
pub async fn disconnect(&self) -> Result<(), SessionError>
Gracefully disconnect the session.
Trait Implementations§
§impl Clone for SessionHandle
impl Clone for SessionHandle
§fn clone(&self) -> SessionHandle
fn clone(&self) -> SessionHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more