Skip to content

Commit 772b279

Browse files
committed
add changes to future object as well
1 parent 0a53315 commit 772b279

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/java/LiveSessionFutures.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import com.google.firebase.ai.type.MediaData
2929
import com.google.firebase.ai.type.PublicPreviewAPI
3030
import com.google.firebase.ai.type.SessionAlreadyReceivingException
3131
import io.ktor.websocket.close
32+
import kotlinx.coroutines.isActive
3233
import kotlinx.coroutines.reactive.asPublisher
3334
import org.reactivestreams.Publisher
3435

@@ -51,6 +52,12 @@ public abstract class LiveSessionFutures internal constructor() {
5152
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)?
5253
): ListenableFuture<Unit>
5354

55+
/** Indicates whether the underlying websocket connection is active. */
56+
public abstract fun isActive(): ListenableFuture<Boolean>
57+
58+
/** Indicates whether an audio conversation is being used for this session object. */
59+
public abstract fun isAudioConversationActive(): ListenableFuture<Boolean>
60+
5461
/**
5562
* Starts an audio conversation with the model, which can only be stopped using
5663
* [stopAudioConversation].
@@ -169,6 +176,11 @@ public abstract class LiveSessionFutures internal constructor() {
169176
override fun startAudioConversation() =
170177
SuspendToFutureAdapter.launchFuture { session.startAudioConversation() }
171178

179+
override fun isActive() = SuspendToFutureAdapter.launchFuture { session.isActive() }
180+
181+
override fun isAudioConversationActive() =
182+
SuspendToFutureAdapter.launchFuture { session.isAudioConversationActive() }
183+
172184
override fun stopAudioConversation() =
173185
SuspendToFutureAdapter.launchFuture { session.stopAudioConversation() }
174186

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/LiveSession.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal constructor(
147147
public fun isActive(): Boolean = session.isActive
148148

149149
/** Indicates whether an audio conversation is being used for this session object. */
150-
public fun isAudioConversationRunning(): Boolean = (audioHelper != null)
150+
public fun isAudioConversationActive(): Boolean = (audioHelper != null)
151151

152152
/**
153153
* Receives responses from the model for both streaming and standard requests.

0 commit comments

Comments
 (0)