Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1.3: Add support for expiry and onTracksUpdated() #1

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This Android library exposes the `DailyVoiceClient` class, to connect to a Daily
Add the following dependency to your `build.gradle` file:

```
implementation "ai.rtvi:rtvi-client-android-daily:0.1.2"
implementation "ai.rtvi:rtvi-client-android-daily:0.1.3"
```

Instantiate from your code:
Expand Down
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
[versions]
agp = "8.5.1"
daily-android-client = "0.22.1"
daily-android-client = "0.23.0"
kotlin = "2.0.0"
coreKtx = "1.13.1"
appcompat = "1.7.0"
kotlinxCoroutinesTest = "1.8.1"
kotlinxSerializationJson = "1.7.1"
kotlinxSerializationPlugin = "2.0.0"
dokka = "1.9.20"
androidxTest = "1.6.1"
rtviClient = "0.1.1"
rtviClient = "0.1.2"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-rules = { module = "androidx.test:rules", version.ref = "androidxTest" }
androidx-runner = { module = "androidx.test:runner", version.ref = "androidxTest" }
daily-android-client = { module = "co.daily:client", version.ref = "daily-android-client" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutinesTest" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
rtvi-client = { module = "ai.rtvi:client", version.ref = "rtviClient" }
Expand Down
12 changes: 6 additions & 6 deletions rtvi-client-android-daily/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ android {

dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.kotlinx.serialization.json)
implementation(libs.daily.android.client)

//api(project(":rtvi-client-android"))
api(libs.daily.android.client)
api(libs.rtvi.client)

androidTestImplementation(libs.androidx.runner)
Expand All @@ -66,7 +64,7 @@ publishing {
register<MavenPublication>("release") {
groupId = "ai.rtvi"
artifactId = "client-daily"
version = "0.1.2"
version = "0.1.3"

pom {
name.set("RTVI Client Daily Transport")
Expand Down Expand Up @@ -105,6 +103,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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ class DailyTransport(

private var call: CallClient? = null

private var expiry: Long? = null

private val callListener = object : CallClientListener {

val participants = mutableMapOf<ParticipantId, Participant>()
var botUser: Participant? = null
var clientReady: Boolean = false
var tracks: Tracks? = null

override fun onLocalAudioLevel(audioLevel: Float) {
transportContext.callbacks.onUserAudioLevel(audioLevel)
Expand All @@ -88,37 +91,45 @@ class DailyTransport(

override fun onParticipantJoined(participant: co.daily.model.Participant) {
updateParticipant(participant)
updateBotUser()
updateBotUserAndTracks()
}

override fun onParticipantLeft(
participant: co.daily.model.Participant,
reason: ParticipantLeftReason
) {
participants.remove(participant.id.toRtvi())
updateBotUser()
updateBotUserAndTracks()
}

override fun onParticipantUpdated(participant: co.daily.model.Participant) {
updateParticipant(participant)
updateBotUser()
updateBotUserAndTracks()

if (!clientReady && participant.id.toRtvi() == botUser?.id) {
if (participant.media?.microphone?.state == MediaState.playable) {

Log.i(TAG, "Sending client-ready")

clientReady = true
sendMessage(MsgClientToServer(
type = "client-ready",
data = null
))
sendMessage(
MsgClientToServer(
type = "client-ready",
data = null
)
)
}
}
}

private fun updateBotUser() {
private fun updateBotUserAndTracks() {
botUser = participants.values.firstOrNull { !it.local }
val newTracks = tracks()

if (newTracks != tracks) {
tracks = newTracks
transportContext.callbacks.onTracksUpdated(newTracks)
}
}

private fun updateParticipant(participant: co.daily.model.Participant) {
Expand All @@ -131,7 +142,7 @@ class DailyTransport(
CallState.joining -> {}
CallState.joined -> {
call?.participants()?.all?.values?.forEach(::updateParticipant)
updateBotUser()
updateBotUserAndTracks()
}

CallState.leaving -> {}
Expand Down Expand Up @@ -261,6 +272,13 @@ class DailyTransport(
return@join
}

expiry = it.success?.callConfig?.let { config ->
listOfNotNull(
config.roomExpiration,
config.tokenExpiration
).minOrNull()
}

setState(TransportState.Connected)
transportContext.callbacks.onConnected()
promise.resolveOk(Unit)
Expand Down Expand Up @@ -366,6 +384,8 @@ class DailyTransport(
}
}

override fun expiry() = thread.assertCurrent { expiry }

override fun enableCam(enable: Boolean): Future<Unit, VoiceError> =
thread.runOnThreadReturningFuture {
withCall { callClient ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ai.rtvi.client.daily

import ai.rtvi.client.types.MediaTrackId
import android.content.Context
import android.util.AttributeSet
import co.daily.model.MediaStreamTrack
import co.daily.view.VideoView

/**
* Overrides the Daily [VideoView] to allow [MediaTrackId] tracks from the VoiceClient to be
* rendered.
*/
class VoiceClientVideoView @JvmOverloads constructor(
viewContext: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : VideoView(viewContext, attrs, defStyleAttr, defStyleRes) {

/**
* Displays the specified [MediaTrackId] in this view.
*/
var voiceClientTrack: MediaTrackId?
get() = track?.id?.let(::MediaTrackId)
set(value) {
track = value?.id?.let(::MediaStreamTrack)
}
}
Loading