Skip to content

Commit 3319733

Browse files
authored
Implement RPC (#578)
* Update protocol * fix build errors * Implement RPC * tests * spotless * comment fixes
1 parent 4f4432b commit 3319733

File tree

13 files changed

+1006
-21
lines changed

13 files changed

+1006
-21
lines changed

.changeset/good-snails-switch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": minor
3+
---
4+
5+
Implement RPC

livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 LiveKit, Inc.
2+
* Copyright 2023-2025 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -273,6 +273,9 @@ enum class DisconnectReason {
273273
MIGRATION,
274274
SIGNAL_CLOSE,
275275
ROOM_CLOSED,
276+
USER_UNAVAILABLE,
277+
USER_REJECTED,
278+
SIP_TRUNK_FAILURE,
276279
}
277280

278281
/**
@@ -290,6 +293,9 @@ fun LivekitModels.DisconnectReason?.convert(): DisconnectReason {
290293
LivekitModels.DisconnectReason.MIGRATION -> DisconnectReason.MIGRATION
291294
LivekitModels.DisconnectReason.SIGNAL_CLOSE -> DisconnectReason.SIGNAL_CLOSE
292295
LivekitModels.DisconnectReason.ROOM_CLOSED -> DisconnectReason.ROOM_CLOSED
296+
LivekitModels.DisconnectReason.USER_UNAVAILABLE -> DisconnectReason.USER_UNAVAILABLE
297+
LivekitModels.DisconnectReason.USER_REJECTED -> DisconnectReason.USER_REJECTED
298+
LivekitModels.DisconnectReason.SIP_TRUNK_FAILURE -> DisconnectReason.SIP_TRUNK_FAILURE
293299
LivekitModels.DisconnectReason.UNKNOWN_REASON,
294300
LivekitModels.DisconnectReason.UNRECOGNIZED,
295301
null,

livekit-android-sdk/src/main/java/io/livekit/android/room/RTCEngine.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 LiveKit, Inc.
2+
* Copyright 2023-2025 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package io.livekit.android.room
1919
import android.os.SystemClock
2020
import androidx.annotation.VisibleForTesting
2121
import com.google.protobuf.ByteString
22+
import com.vdurmont.semver4j.Semver
2223
import io.livekit.android.ConnectOptions
2324
import io.livekit.android.RoomOptions
2425
import io.livekit.android.dagger.InjectionNames
@@ -148,6 +149,9 @@ internal constructor(
148149
private var lastRoomOptions: RoomOptions? = null
149150
private var participantSid: String? = null
150151

152+
internal val serverVersion: Semver?
153+
get() = client.serverVersion
154+
151155
private val publisherObserver = PublisherTransportObserver(this, client)
152156
private val subscriberObserver = SubscriberTransportObserver(this, client)
153157

@@ -777,6 +781,7 @@ internal constructor(
777781
fun onLocalTrackUnpublished(trackUnpublished: LivekitRtc.TrackUnpublishedResponse)
778782
fun onTranscriptionReceived(transcription: LivekitModels.Transcription)
779783
fun onLocalTrackSubscribed(trackSubscribed: LivekitRtc.TrackSubscribed)
784+
fun onRpcPacketReceived(dp: LivekitModels.DataPacket)
780785
}
781786

782787
companion object {
@@ -792,7 +797,7 @@ internal constructor(
792797
*/
793798
@VisibleForTesting
794799
const val LOSSY_DATA_CHANNEL_LABEL = "_lossy"
795-
internal const val MAX_DATA_PACKET_SIZE = 15000
800+
internal const val MAX_DATA_PACKET_SIZE = 15360 // 15 KB
796801
private const val MAX_RECONNECT_RETRIES = 10
797802
private const val MAX_RECONNECT_TIMEOUT = 60 * 1000
798803
private const val MAX_ICE_CONNECT_TIMEOUT_MS = 20000
@@ -1040,13 +1045,21 @@ internal constructor(
10401045
LivekitModels.DataPacket.ValueCase.RPC_ACK,
10411046
LivekitModels.DataPacket.ValueCase.RPC_RESPONSE,
10421047
-> {
1043-
// TODO
1048+
listener?.onRpcPacketReceived(dp)
10441049
}
10451050
LivekitModels.DataPacket.ValueCase.VALUE_NOT_SET,
10461051
null,
10471052
-> {
10481053
LKLog.v { "invalid value for data packet" }
10491054
}
1055+
1056+
LivekitModels.DataPacket.ValueCase.STREAM_HEADER -> {
1057+
// TODO
1058+
}
1059+
1060+
LivekitModels.DataPacket.ValueCase.STREAM_CHUNK -> {
1061+
// TODO
1062+
}
10501063
}
10511064
}
10521065

livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 LiveKit, Inc.
2+
* Copyright 2023-2025 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -648,6 +648,8 @@ constructor(
648648

649649
mutableRemoteParticipants = newParticipants
650650
eventBus.postEvent(RoomEvent.ParticipantDisconnected(this, removedParticipant), coroutineScope)
651+
652+
localParticipant.handleParticipantDisconnect(identity)
651653
}
652654

653655
fun getParticipantBySid(sid: String): Participant? {
@@ -1195,6 +1197,10 @@ constructor(
11951197
publication?.onTranscriptionReceived(event)
11961198
}
11971199

1200+
override fun onRpcPacketReceived(dp: LivekitModels.DataPacket) {
1201+
localParticipant.handleDataPacket(dp)
1202+
}
1203+
11981204
/**
11991205
* @suppress
12001206
*/

livekit-android-sdk/src/main/java/io/livekit/android/room/SignalClient.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 LiveKit, Inc.
2+
* Copyright 2023-2025 LiveKit, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@ constructor(
8484
private var currentWs: WebSocket? = null
8585
private var isReconnecting: Boolean = false
8686
var listener: Listener? = null
87-
private var serverVersion: Semver? = null
87+
internal var serverVersion: Semver? = null
8888
private var lastUrl: String? = null
8989
private var lastOptions: ConnectOptions? = null
9090
private var lastRoomOptions: RoomOptions? = null
@@ -841,6 +841,7 @@ constructor(
841841
lastUrl = null
842842
lastOptions = null
843843
lastRoomOptions = null
844+
serverVersion = null
844845
}
845846

846847
interface Listener {

0 commit comments

Comments
 (0)