Skip to content

Commit

Permalink
Implement RPC (#578)
Browse files Browse the repository at this point in the history
* Update protocol

* fix build errors

* Implement RPC

* tests

* spotless

* comment fixes
  • Loading branch information
davidliu authored Jan 9, 2025
1 parent 4f4432b commit 3319733
Show file tree
Hide file tree
Showing 13 changed files with 1,006 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-snails-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"client-sdk-android": minor
---

Implement RPC
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -273,6 +273,9 @@ enum class DisconnectReason {
MIGRATION,
SIGNAL_CLOSE,
ROOM_CLOSED,
USER_UNAVAILABLE,
USER_REJECTED,
SIP_TRUNK_FAILURE,
}

/**
Expand All @@ -290,6 +293,9 @@ fun LivekitModels.DisconnectReason?.convert(): DisconnectReason {
LivekitModels.DisconnectReason.MIGRATION -> DisconnectReason.MIGRATION
LivekitModels.DisconnectReason.SIGNAL_CLOSE -> DisconnectReason.SIGNAL_CLOSE
LivekitModels.DisconnectReason.ROOM_CLOSED -> DisconnectReason.ROOM_CLOSED
LivekitModels.DisconnectReason.USER_UNAVAILABLE -> DisconnectReason.USER_UNAVAILABLE
LivekitModels.DisconnectReason.USER_REJECTED -> DisconnectReason.USER_REJECTED
LivekitModels.DisconnectReason.SIP_TRUNK_FAILURE -> DisconnectReason.SIP_TRUNK_FAILURE
LivekitModels.DisconnectReason.UNKNOWN_REASON,
LivekitModels.DisconnectReason.UNRECOGNIZED,
null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@ package io.livekit.android.room
import android.os.SystemClock
import androidx.annotation.VisibleForTesting
import com.google.protobuf.ByteString
import com.vdurmont.semver4j.Semver
import io.livekit.android.ConnectOptions
import io.livekit.android.RoomOptions
import io.livekit.android.dagger.InjectionNames
Expand Down Expand Up @@ -148,6 +149,9 @@ internal constructor(
private var lastRoomOptions: RoomOptions? = null
private var participantSid: String? = null

internal val serverVersion: Semver?
get() = client.serverVersion

private val publisherObserver = PublisherTransportObserver(this, client)
private val subscriberObserver = SubscriberTransportObserver(this, client)

Expand Down Expand Up @@ -777,6 +781,7 @@ internal constructor(
fun onLocalTrackUnpublished(trackUnpublished: LivekitRtc.TrackUnpublishedResponse)
fun onTranscriptionReceived(transcription: LivekitModels.Transcription)
fun onLocalTrackSubscribed(trackSubscribed: LivekitRtc.TrackSubscribed)
fun onRpcPacketReceived(dp: LivekitModels.DataPacket)
}

companion object {
Expand All @@ -792,7 +797,7 @@ internal constructor(
*/
@VisibleForTesting
const val LOSSY_DATA_CHANNEL_LABEL = "_lossy"
internal const val MAX_DATA_PACKET_SIZE = 15000
internal const val MAX_DATA_PACKET_SIZE = 15360 // 15 KB
private const val MAX_RECONNECT_RETRIES = 10
private const val MAX_RECONNECT_TIMEOUT = 60 * 1000
private const val MAX_ICE_CONNECT_TIMEOUT_MS = 20000
Expand Down Expand Up @@ -1040,13 +1045,21 @@ internal constructor(
LivekitModels.DataPacket.ValueCase.RPC_ACK,
LivekitModels.DataPacket.ValueCase.RPC_RESPONSE,
-> {
// TODO
listener?.onRpcPacketReceived(dp)
}
LivekitModels.DataPacket.ValueCase.VALUE_NOT_SET,
null,
-> {
LKLog.v { "invalid value for data packet" }
}

LivekitModels.DataPacket.ValueCase.STREAM_HEADER -> {
// TODO
}

LivekitModels.DataPacket.ValueCase.STREAM_CHUNK -> {
// TODO
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -648,6 +648,8 @@ constructor(

mutableRemoteParticipants = newParticipants
eventBus.postEvent(RoomEvent.ParticipantDisconnected(this, removedParticipant), coroutineScope)

localParticipant.handleParticipantDisconnect(identity)
}

fun getParticipantBySid(sid: String): Participant? {
Expand Down Expand Up @@ -1195,6 +1197,10 @@ constructor(
publication?.onTranscriptionReceived(event)
}

override fun onRpcPacketReceived(dp: LivekitModels.DataPacket) {
localParticipant.handleDataPacket(dp)
}

/**
* @suppress
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,7 +84,7 @@ constructor(
private var currentWs: WebSocket? = null
private var isReconnecting: Boolean = false
var listener: Listener? = null
private var serverVersion: Semver? = null
internal var serverVersion: Semver? = null
private var lastUrl: String? = null
private var lastOptions: ConnectOptions? = null
private var lastRoomOptions: RoomOptions? = null
Expand Down Expand Up @@ -841,6 +841,7 @@ constructor(
lastUrl = null
lastOptions = null
lastRoomOptions = null
serverVersion = null
}

interface Listener {
Expand Down
Loading

0 comments on commit 3319733

Please sign in to comment.