SessionHandle

Struct SessionHandle 

Source
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

Source

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.

Source

pub fn set_task(&self, handle: JoinHandle<()>)

Store the connection loop task handle.

Called by the transport layer after spawning the connection loop.

Source

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.

Source

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

Subscribe to session events.

Source

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

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

Source

pub fn phase(&self) -> SessionPhase

Current session phase.

Source

pub fn session_id(&self) -> &str

Session ID.

Source

pub async fn wait_for_phase(&self, target: SessionPhase)

Wait for the session to reach a specific phase.

Source

pub async fn send_audio(&self, data: Vec<u8>) -> Result<(), SessionError>

Send audio data (raw PCM16 bytes).

Source

pub async fn send_text( &self, text: impl Into<String>, ) -> Result<(), SessionError>

Send a text message.

Source

pub async fn send_tool_response( &self, responses: Vec<FunctionResponse>, ) -> Result<(), SessionError>

Send tool responses.

Source

pub async fn send_video(&self, jpeg_data: Vec<u8>) -> Result<(), SessionError>

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

Source

pub async fn update_instruction( &self, instruction: impl Into<String>, ) -> Result<(), SessionError>

Update the system instruction mid-session.

Source

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

Signal activity start (user started speaking).

Source

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

Signal activity end (user stopped speaking).

Source

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.

Source

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

Gracefully disconnect the session.

Trait Implementations§

Source§

impl Clone for SessionHandle

Source§

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
Source§

impl Debug for SessionHandle

Source§

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

Formats the value using the given formatter. Read more
Source§

impl SessionReader for SessionHandle

Source§

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

Subscribe to the session event broadcast stream.
Source§

fn phase(&self) -> SessionPhase

Returns the current session phase.
Source§

fn session_id(&self) -> &str

Returns the unique session ID.
Source§

impl SessionWriter for SessionHandle

Source§

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

Send raw PCM16 audio bytes.
Source§

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

Send a text message.
Source§

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

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

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 Self: 'async_trait, 'life0: 'async_trait,

Send client content (conversation history or context).
Source§

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

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

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

Update the system instruction mid-session.
Source§

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

Signal that user speech activity has started.
Source§

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

Signal that user speech activity has ended.
Source§

fn disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), SessionError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: '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> 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