From 9100b7cf7196ea86f4c06376f4be652ca83de7d5 Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:18:22 +0100 Subject: [PATCH 1/4] Adding `expiry` field to VoiceClient/Transport --- .../src/main/java/ai/rtvi/client/VoiceClient.kt | 7 +++++++ .../src/main/java/ai/rtvi/client/transport/Transport.kt | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt index 37dac1a..abfca18 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt @@ -466,6 +466,13 @@ open class VoiceClient( val isCamEnabled get() = transport.isCamEnabled() + /** + * The expiry time for the transport session, if applicable. Measured in seconds + * since the UNIX epoch (UTC). + */ + val expiry + get() = transport.expiry() + /** * Returns a list of participant media tracks. */ diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/transport/Transport.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/transport/Transport.kt index 9287ac6..904bd79 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/transport/Transport.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/transport/Transport.kt @@ -34,6 +34,12 @@ abstract class Transport { abstract fun isCamEnabled(): Boolean abstract fun isMicEnabled(): Boolean + /** + * The expiry time for the transport session, if applicable. Measured in seconds + * since the UNIX epoch (UTC). + */ + abstract fun expiry(): Long? + abstract fun sendMessage(message: MsgClientToServer): Future abstract fun state(): TransportState From 74c6fe91a49b2f833e414ef2239bd3f258408adc Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:18:53 +0100 Subject: [PATCH 2/4] Increasing version number to 0.1.2 --- README.md | 2 +- rtvi-client-android/build.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a88ed0..49a3ed5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ packages.) The base `VoiceClient` has no transport included. Add the following dependency to your `build.gradle` file: ``` -implementation "ai.rtvi:client:0.1.1" +implementation "ai.rtvi:client:0.1.2" ``` Then instantiate the `VoiceClient` from your code, specifying the backend `baseUrl` and transport. diff --git a/rtvi-client-android/build.gradle.kts b/rtvi-client-android/build.gradle.kts index 744cc51..853e83e 100644 --- a/rtvi-client-android/build.gradle.kts +++ b/rtvi-client-android/build.gradle.kts @@ -60,7 +60,7 @@ publishing { register("release") { groupId = "ai.rtvi" artifactId = "client" - version = "0.1.1" + version = "0.1.2" pom { name.set("RTVI Client") From ddb381c2478f3bbcbabc783b20ddfbbc789f2b03 Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:14:30 +0100 Subject: [PATCH 3/4] Adding onTracksUpdated callback --- rtvi-client-android/build.gradle.kts | 6 ++++-- .../main/java/ai/rtvi/client/VoiceEventCallbacks.kt | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/rtvi-client-android/build.gradle.kts b/rtvi-client-android/build.gradle.kts index 853e83e..2ee6d0a 100644 --- a/rtvi-client-android/build.gradle.kts +++ b/rtvi-client-android/build.gradle.kts @@ -99,6 +99,8 @@ signing { val signingKey = System.getenv("RTVI_GPG_SIGNING_KEY") val signingPassphrase = System.getenv("RTVI_GPG_SIGNING_PASSPHRASE") - useInMemoryPgpKeys(signingKey, signingPassphrase) - sign(publishing.publications) + if (!signingKey.isNullOrEmpty() || !signingPassphrase.isNullOrEmpty()) { + useInMemoryPgpKeys(signingKey, signingPassphrase) + sign(publishing.publications) + } } \ No newline at end of file diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceEventCallbacks.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceEventCallbacks.kt index 2554ae4..f0fed77 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceEventCallbacks.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceEventCallbacks.kt @@ -5,6 +5,7 @@ import ai.rtvi.client.types.MediaDeviceInfo import ai.rtvi.client.types.Participant import ai.rtvi.client.types.PipecatMetrics import ai.rtvi.client.types.ServiceConfig +import ai.rtvi.client.types.Tracks import ai.rtvi.client.types.Transcript import ai.rtvi.client.types.TransportState @@ -127,6 +128,11 @@ abstract class VoiceEventCallbacks { * Invoked when the state of the input devices changes. */ open fun onInputsUpdated(camera: Boolean, mic: Boolean) {} + + /** + * Invoked when the set of available cam/mic tracks changes. + */ + open fun onTracksUpdated(tracks: Tracks) {} } internal class CallbackInterceptor(vararg listeners: VoiceEventCallbacks): VoiceEventCallbacks() { @@ -224,4 +230,8 @@ internal class CallbackInterceptor(vararg listeners: VoiceEventCallbacks): Voice override fun onInputsUpdated(camera: Boolean, mic: Boolean) { callbacks.forEach { it.onInputsUpdated(camera = camera, mic = mic) } } + + override fun onTracksUpdated(tracks: Tracks) { + callbacks.forEach { it.onTracksUpdated(tracks) } + } } \ No newline at end of file From ca8571ba42593bc2f4fdbb29556cb34652d41f59 Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Wed, 21 Aug 2024 17:22:35 +0100 Subject: [PATCH 4/4] Custom body params --- .../main/java/ai/rtvi/client/VoiceClient.kt | 13 ++++++------- .../java/ai/rtvi/client/VoiceClientOptions.kt | 8 +++++++- .../ai/rtvi/client/utils/ConnectionBundle.kt | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt index abfca18..41cd7ed 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClient.kt @@ -229,13 +229,12 @@ open class VoiceClient( // Send POST request to the provided base_url to connect and start the bot - val body = JSON_INSTANCE.encodeToString( - ConnectionBundle.serializer(), - ConnectionBundle( - services = options.services.associate { it.service to it.value }, - config = options.config - ) - ).toRequestBody("application/json".toMediaType()) + val body = ConnectionBundle( + services = options.services.associate { it.service to it.value }, + config = options.config + ) + .serializeWithCustomParams(options.customBodyParams) + .toRequestBody("application/json".toMediaType()) val currentConnection = Connection().apply { connection = this } diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClientOptions.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClientOptions.kt index 69b0e5e..3939748 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClientOptions.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/VoiceClientOptions.kt @@ -2,6 +2,7 @@ package ai.rtvi.client import ai.rtvi.client.types.ServiceConfig import ai.rtvi.client.types.ServiceRegistration +import ai.rtvi.client.types.Value /** * Configuration options when instantiating a [VoiceClient]. @@ -34,5 +35,10 @@ data class VoiceClientOptions( /** * Custom HTTP headers to be sent with the POST request to baseUrl. */ - val customHeaders: List> = emptyList() + val customHeaders: List> = emptyList(), + + /** + * Custom parameters to add to the auth request body. + */ + val customBodyParams: List> = emptyList() ) \ No newline at end of file diff --git a/rtvi-client-android/src/main/java/ai/rtvi/client/utils/ConnectionBundle.kt b/rtvi-client-android/src/main/java/ai/rtvi/client/utils/ConnectionBundle.kt index b8a285f..886a351 100644 --- a/rtvi-client-android/src/main/java/ai/rtvi/client/utils/ConnectionBundle.kt +++ b/rtvi-client-android/src/main/java/ai/rtvi/client/utils/ConnectionBundle.kt @@ -1,10 +1,26 @@ package ai.rtvi.client.utils import ai.rtvi.client.types.ServiceConfig +import ai.rtvi.client.types.Value import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.encodeToJsonElement +import kotlinx.serialization.json.jsonObject @Serializable internal data class ConnectionBundle( val services: Map, val config: List -) \ No newline at end of file +) { + + fun serializeWithCustomParams(customBodyParams: List>): String { + + val customMap = + customBodyParams.associate { it.first to JSON_INSTANCE.encodeToJsonElement(it.second) } + + val result = JsonObject(JSON_INSTANCE.encodeToJsonElement(this).jsonObject + customMap) + + return JSON_INSTANCE.encodeToString(JsonObject.serializer(), result) + } +} \ No newline at end of file