Class AsyncSession
-
- All Implemented Interfaces:
public final class AsyncSessionAsyncSession manages sending and receiving messages over a WebSocket connection for a live session. The live module is experimental.
-
-
Method Summary
Modifier and Type Method Description CompletableFuture<Void>sendClientContent(LiveSendClientContentParameters clientContent)Sends client content to the live session. CompletableFuture<Void>sendRealtimeInput(LiveSendRealtimeInputParameters realtimeInput)Sends realtime input to the live session. CompletableFuture<Void>sendToolResponse(LiveSendToolResponseParameters toolResponse)Sends tool response to the live session. CompletableFuture<Void>receive(Consumer<LiveServerMessage> onMessage)Registers a callback to receive messages from the live session. CompletableFuture<Void>close()Closes the WebSocket connection. StringsessionId()Gets the session ID of the live session. -
-
Method Detail
-
sendClientContent
CompletableFuture<Void> sendClientContent(LiveSendClientContentParameters clientContent)
Sends client content to the live session.
- Parameters:
clientContent- A LiveSendClientContentParameters 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
CompletableFuture<Void> sendRealtimeInput(LiveSendRealtimeInputParameters realtimeInput)
Sends realtime input to the live session.
- Parameters:
realtimeInput- A LiveSendRealtimeInputParameters 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
CompletableFuture<Void> sendToolResponse(LiveSendToolResponseParameters toolResponse)
Sends tool response to the live session.
- Parameters:
toolResponse- A LiveSendToolResponseParameters 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
CompletableFuture<Void> receive(Consumer<LiveServerMessage> onMessage)
Registers a callback to receive messages from the live session. Only one callback can be registered at a time.
- Parameters:
onMessage- A Consumer that will be called for each LiveServerMessage 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
CompletableFuture<Void> close()
Closes the WebSocket connection.
- Returns:
A CompletableFuture that completes when the connection has been closed.
-
-
-
-