SessionHandle

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

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<()>)

Store the connection loop task handle.

Called by the transport layer after spawning the connection loop.

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>

Subscribe to session events.

pub fn event_sender(&self) -> &Sender<SessionEvent>

Get the event sender (for internal use by transport).

pub fn phase(&self) -> SessionPhase

Current session phase.

pub fn session_id(&self) -> &str

Session ID.

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>

Send audio data (raw PCM16 bytes).

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>

Send tool responses.

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>

Update the system instruction mid-session.

pub async fn signal_activity_start(&self) -> Result<(), SessionError>

Signal activity start (user started speaking).

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>

Send client content (turns + turn_complete flag). Used for injecting conversation history, context, or multi-turn text.

pub async fn disconnect(&self) -> Result<(), SessionError>

Gracefully disconnect the session.

Trait Implementations§

§

impl Clone for SessionHandle

§

fn clone(&self) -> SessionHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for SessionHandle

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl SessionReader for SessionHandle

§

fn subscribe(&self) -> Receiver<SessionEvent>

Subscribe to the session event broadcast stream.
§

fn phase(&self) -> SessionPhase

Returns the current session phase.
§

fn session_id(&self) -> &str

Returns the unique session ID.
§

impl SessionWriter for SessionHandle

§

fn send_audio<'life0, 'async_trait>( &'life0 self, data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Send raw PCM16 audio bytes.
§

fn send_text<'life0, 'async_trait>( &'life0 self, text: String, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Send a text message.
§

fn send_tool_response<'life0, 'async_trait>( &'life0 self, responses: Vec<FunctionResponse>, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Send tool/function call responses back to the model.
§

fn send_client_content<'life0, 'async_trait>( &'life0 self, turns: Vec<Content>, turn_complete: bool, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Send client content (conversation history or context).
§

fn send_video<'life0, 'async_trait>( &'life0 self, jpeg_data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Send a video/image frame (raw JPEG bytes).
§

fn update_instruction<'life0, 'async_trait>( &'life0 self, instruction: String, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Update the system instruction mid-session.
§

fn signal_activity_start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Signal that user speech activity has started.
§

fn signal_activity_end<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Signal that user speech activity has ended.
§

fn disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionHandle: 'async_trait,

Gracefully disconnect the session.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more