Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
livekitAndroidXuningTest
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
davidliu
2023-04-17 23:29:53 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2023-04-17 23:29:53 +0900
Commit
33b98460a83eacd8d6b9cf83c88ee6331a5fd1cc
33b98460
1 parent
e53320eb
Support data packet topics (#213)
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
31 行增加
和
13 行删除
livekit-android-sdk/src/main/java/io/livekit/android/events/ParticipantEvent.kt
livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/SignalClient.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/LocalParticipant.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/RemoteParticipant.kt
livekit-android-sdk/src/main/java/io/livekit/android/events/ParticipantEvent.kt
查看文件 @
33b9846
...
...
@@ -98,7 +98,11 @@ sealed class ParticipantEvent(open val participant: Participant) : Event() {
/**
* Received data published by another participant
*/
class DataReceived(override val participant: RemoteParticipant, val data: ByteArray) : ParticipantEvent(participant)
class DataReceived(
override val participant: RemoteParticipant,
val data: ByteArray,
val topic: String?
) : ParticipantEvent(participant)
/**
* A track's stream state has changed.
...
...
livekit-android-sdk/src/main/java/io/livekit/android/events/RoomEvent.kt
查看文件 @
33b9846
...
...
@@ -145,7 +145,8 @@ sealed class RoomEvent(val room: Room) : Event() {
* @param data the published data
* @param participant the participant if available
*/
class DataReceived(room: Room, val data: ByteArray, val participant: RemoteParticipant?) : RoomEvent(room)
class DataReceived(room: Room, val data: ByteArray, val participant: RemoteParticipant?, val topic: String?) :
RoomEvent(room)
/**
* The connection quality for a participant has changed.
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
查看文件 @
33b9846
...
...
@@ -722,10 +722,15 @@ constructor(
override fun onUserPacket(packet: LivekitModels.UserPacket, kind: LivekitModels.DataPacket.Kind) {
val participant = remoteParticipants[packet.participantSid]
val data = packet.payload.toByteArray()
val topic = if (packet.hasTopic()) {
packet.topic
} else {
null
}
listener?.onDataReceived(data, participant, this)
eventBus.postEvent(RoomEvent.DataReceived(this, data, participant), coroutineScope)
participant?.onDataReceived(data)
eventBus.postEvent(RoomEvent.DataReceived(this, data, participant, topic), coroutineScope)
participant?.onDataReceived(data, topic)
}
/**
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/SignalClient.kt
查看文件 @
33b9846
...
...
@@ -270,6 +270,8 @@ constructor(
val wasConnected = isConnected
if (wasConnected) {
// onClosing/onClosed will not be called after onFailure.
// Handle websocket closure here.
handleWebSocketClose(
reason = reason ?: response?.toString() ?: t.localizedMessage ?: "websocket failure",
code = response?.code ?: CLOSE_REASON_WEBSOCKET_FAILURE
...
...
@@ -390,7 +392,7 @@ constructor(
quality = LivekitModels.VideoQuality.HIGH
}
if
(fps != null)
{
if
(fps != null)
{
setFps(fps)
}
}
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/LocalParticipant.kt
查看文件 @
33b9846
...
...
@@ -443,12 +443,14 @@ internal constructor(
* @param data payload to send
* @param reliability for delivery guarantee, use RELIABLE. for fastest delivery without guarantee, use LOSSY
* @param destination list of participant SIDs to deliver the payload, null to deliver to everyone
* @param topic the topic under which the message was published
*/
@Suppress("unused")
suspend fun publishData(
data: ByteArray,
reliability: DataPublishReliability = DataPublishReliability.RELIABLE,
destination: List<String>? = null
destination: List<String>? = null,
topic: String? = null,
) {
if (data.size > RTCEngine.MAX_DATA_PACKET_SIZE) {
throw IllegalArgumentException("cannot publish data larger than " + RTCEngine.MAX_DATA_PACKET_SIZE)
...
...
@@ -458,11 +460,15 @@ internal constructor(
DataPublishReliability.RELIABLE -> LivekitModels.DataPacket.Kind.RELIABLE
DataPublishReliability.LOSSY -> LivekitModels.DataPacket.Kind.LOSSY
}
val packetBuilder = LivekitModels.UserPacket.newBuilder()
.setPayload(ByteString.copyFrom(data))
.setParticipantSid(sid)
if (destination != null) {
packetBuilder.addAllDestinationSids(destination)
val packetBuilder = LivekitModels.UserPacket.newBuilder().apply {
payload = ByteString.copyFrom(data)
participantSid = sid
if (topic != null) {
setTopic(topic)
}
if (destination != null) {
addAllDestinationSids(destination)
}
}
val dataPacket = LivekitModels.DataPacket.newBuilder()
.setUser(packetBuilder)
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/RemoteParticipant.kt
查看文件 @
33b9846
...
...
@@ -179,9 +179,9 @@ class RemoteParticipant(
}
// Internal methods just for posting events.
internal fun onDataReceived(data: ByteArray) {
internal fun onDataReceived(data: ByteArray
, topic: String?
) {
listener?.onDataReceived(data, this)
eventBus.postEvent(ParticipantEvent.DataReceived(this, data), scope)
eventBus.postEvent(ParticipantEvent.DataReceived(this, data
, topic
), scope)
}
companion object {
...
...
请
注册
或
登录
后发表评论