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§
Source§impl SessionHandle
impl SessionHandle
Sourcepub fn new(
command_tx: Sender<SessionCommand>,
event_tx: Sender<SessionEvent>,
state: Arc<SessionState>,
phase_rx: Receiver<SessionPhase>,
) -> Self
pub fn new( command_tx: Sender<SessionCommand>, event_tx: Sender<SessionEvent>, state: Arc<SessionState>, phase_rx: Receiver<SessionPhase>, ) -> Self
Create a new session handle from its components.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn subscribe(&self) -> Receiver<SessionEvent>
pub fn subscribe(&self) -> Receiver<SessionEvent>
Subscribe to session events.
Sourcepub fn event_sender(&self) -> &Sender<SessionEvent>
pub fn event_sender(&self) -> &Sender<SessionEvent>
Get the event sender (for internal use by transport).
Sourcepub fn phase(&self) -> SessionPhase
pub fn phase(&self) -> SessionPhase
Current session phase.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Session ID.
Sourcepub 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.
Sourcepub 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).
Sourcepub 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.
Sourcepub 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.
Sourcepub 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).
Sourcepub 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.
Sourcepub async fn signal_activity_start(&self) -> Result<(), SessionError>
pub async fn signal_activity_start(&self) -> Result<(), SessionError>
Signal activity start (user started speaking).
Sourcepub async fn signal_activity_end(&self) -> Result<(), SessionError>
pub async fn signal_activity_end(&self) -> Result<(), SessionError>
Signal activity end (user stopped speaking).
Sourcepub 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.
Sourcepub async fn disconnect(&self) -> Result<(), SessionError>
pub async fn disconnect(&self) -> Result<(), SessionError>
Gracefully disconnect the session.
Trait Implementations§
Source§impl Clone for SessionHandle
impl Clone for SessionHandle
Source§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