pub struct Session { /* private fields */ }Expand description
An active session with the Gemini Live API.
Cheaply Cloneable — all clones share the same underlying connection
and runner task. Each clone has its own event cursor, so events are
never “stolen” between consumers.
Created via Session::connect.
Implementations§
Source§impl Session
impl Session
Sourcepub async fn connect(config: SessionConfig) -> Result<Self, SessionError>
pub async fn connect(config: SessionConfig) -> Result<Self, SessionError>
Connect to the Gemini Live API and complete the setup handshake.
On success the session is immediately usable — setupComplete has
already been received. A background runner task is spawned to
manage the connection and handle reconnection.
Sourcepub fn status(&self) -> SessionStatus
pub fn status(&self) -> SessionStatus
Current session status.
Sourcepub async fn send_audio(&self, pcm_i16_le: &[u8]) -> Result<(), SessionError>
pub async fn send_audio(&self, pcm_i16_le: &[u8]) -> Result<(), SessionError>
Stream audio. Accepts raw i16 little-endian PCM bytes — base64
encoding and realtimeInput wrapping are handled internally.
Performance note: allocates a new String for base64 on every
call (roadmap.md P-1). For zero-allocation streaming, use
AudioEncoder with send_raw.
Sourcepub async fn send_audio_at_rate(
&self,
pcm_i16_le: &[u8],
sample_rate: u32,
) -> Result<(), SessionError>
pub async fn send_audio_at_rate( &self, pcm_i16_le: &[u8], sample_rate: u32, ) -> Result<(), SessionError>
Stream audio at a specific sample rate.
Like send_audio but lets you specify the sample
rate (e.g. for mic capture at the device’s native rate). The server
resamples as needed.
Performance note: allocates a new String for base64 on every
call (roadmap.md P-1). For zero-allocation streaming, use
AudioEncoder with send_raw.
Sourcepub async fn send_video(
&self,
data: &[u8],
mime: &str,
) -> Result<(), SessionError>
pub async fn send_video( &self, data: &[u8], mime: &str, ) -> Result<(), SessionError>
Stream a video frame. Accepts encoded JPEG/PNG bytes.
Sourcepub async fn send_text(&self, text: &str) -> Result<(), SessionError>
pub async fn send_text(&self, text: &str) -> Result<(), SessionError>
Send text via the real-time input channel.
Sourcepub async fn send_client_content(
&self,
content: ClientContent,
) -> Result<(), SessionError>
pub async fn send_client_content( &self, content: ClientContent, ) -> Result<(), SessionError>
Send conversation history or incremental content.
Sourcepub async fn activity_start(&self) -> Result<(), SessionError>
pub async fn activity_start(&self) -> Result<(), SessionError>
Manual VAD: signal that user activity (speech) has started.
Sourcepub async fn activity_end(&self) -> Result<(), SessionError>
pub async fn activity_end(&self) -> Result<(), SessionError>
Manual VAD: signal that user activity has ended.
Sourcepub async fn audio_stream_end(&self) -> Result<(), SessionError>
pub async fn audio_stream_end(&self) -> Result<(), SessionError>
Notify the server that the audio stream has ended (auto VAD mode).
Sourcepub async fn send_tool_response(
&self,
responses: Vec<FunctionResponse>,
) -> Result<(), SessionError>
pub async fn send_tool_response( &self, responses: Vec<FunctionResponse>, ) -> Result<(), SessionError>
Reply to one or more server-initiated function calls.
Sourcepub async fn send_raw(&self, msg: ClientMessage) -> Result<(), SessionError>
pub async fn send_raw(&self, msg: ClientMessage) -> Result<(), SessionError>
Send an arbitrary ClientMessage (escape hatch for future types).
Sourcepub fn events(&self) -> impl Stream<Item = ServerEvent>
pub fn events(&self) -> impl Stream<Item = ServerEvent>
Create a new event Stream.
Each call produces an independent subscription — multiple streams can coexist without stealing events.
Sourcepub async fn next_event(&mut self) -> Option<ServerEvent>
pub async fn next_event(&mut self) -> Option<ServerEvent>
Wait for the next event on this handle’s cursor.
Returns None when the session is permanently closed.
Sourcepub async fn next_observed_event(&mut self) -> Option<SessionObservation>
pub async fn next_observed_event(&mut self) -> Option<SessionObservation>
Wait for the next observable item on this handle’s cursor.
Unlike Session::next_event, this does not hide lagged broadcast
notifications. Callers can therefore surface lost-event state directly
in their own runtime or UI layer.
Sourcepub async fn close(self) -> Result<(), SessionError>
pub async fn close(self) -> Result<(), SessionError>
Gracefully close the session.
Sends a WebSocket close frame and shuts down the background runner.
Other clones of this session will observe SessionStatus::Closed.
This only enqueues the close request; it does not await runner-task completion yet.