Package com.google.genai
Class AsyncSession
java.lang.Object
com.google.genai.AsyncSession
AsyncSession manages sending and receiving messages over a WebSocket connection for a live
session. The live module is experimental.
-
Method Summary
Modifier and TypeMethodDescriptionclose()
Closes the WebSocket connection.receive
(Consumer<LiveServerMessage> onMessage) Registers a callback to receive messages from the live session.sendClientContent
(LiveSendClientContentParameters clientContent) Sends client content to the live session.sendRealtimeInput
(LiveSendRealtimeInputParameters realtimeInput) Sends realtime input to the live session.sendToolResponse
(LiveSendToolResponseParameters toolResponse) Sends tool response to the live session.
-
Method Details
-
sendClientContent
Sends client content to the live session.- Parameters:
clientContent
- ALiveSendClientContentParameters
to send.- Returns:
- A
CompletableFuture
that completes when the client content has been sent. The future will fail if the client content cannot be sent.
-
sendRealtimeInput
Sends realtime input to the live session.- Parameters:
realtimeInput
- ALiveSendRealtimeInputParameters
to send.- Returns:
- A
CompletableFuture
that completes when the realtime input has been sent. The future will fail if the realtime input cannot be sent.
-
sendToolResponse
Sends tool response to the live session.- Parameters:
toolResponse
- ALiveSendToolResponseParameters
to send.- Returns:
- A
CompletableFuture
that completes when the tool response has been sent. The future will fail if the tool response cannot be sent.
-
receive
Registers a callback to receive messages from the live session. Only one callback can be registered at a time.- Parameters:
onMessage
- AConsumer
that will be called for eachLiveServerMessage
received.- Returns:
- A
CompletableFuture
that completes when the callback has been registered. Note: This future doesn't represent the entire lifecycle of receiving messages, just the *registration* of the callback.
-
close
Closes the WebSocket connection.- Returns:
- A
CompletableFuture
that completes when the connection has been closed.
-