正在显示
3 个修改的文件
包含
8 行增加
和
5 行删除
| @@ -140,8 +140,11 @@ sealed class RoomEvent(val room: Room) : Event() { | @@ -140,8 +140,11 @@ sealed class RoomEvent(val room: Room) : Event() { | ||
| 140 | 140 | ||
| 141 | /** | 141 | /** |
| 142 | * Received data published by another participant | 142 | * Received data published by another participant |
| 143 | + * | ||
| 144 | + * @param data the published data | ||
| 145 | + * @param participant the participant if available | ||
| 143 | */ | 146 | */ |
| 144 | - class DataReceived(room: Room, val data: ByteArray, val participant: RemoteParticipant) : RoomEvent(room) | 147 | + class DataReceived(room: Room, val data: ByteArray, val participant: RemoteParticipant?) : RoomEvent(room) |
| 145 | 148 | ||
| 146 | /** | 149 | /** |
| 147 | * The connection quality for a participant has changed. | 150 | * The connection quality for a participant has changed. |
| @@ -699,12 +699,12 @@ constructor( | @@ -699,12 +699,12 @@ constructor( | ||
| 699 | * @suppress | 699 | * @suppress |
| 700 | */ | 700 | */ |
| 701 | override fun onUserPacket(packet: LivekitModels.UserPacket, kind: LivekitModels.DataPacket.Kind) { | 701 | override fun onUserPacket(packet: LivekitModels.UserPacket, kind: LivekitModels.DataPacket.Kind) { |
| 702 | - val participant = remoteParticipants[packet.participantSid] ?: return | 702 | + val participant = remoteParticipants[packet.participantSid] |
| 703 | val data = packet.payload.toByteArray() | 703 | val data = packet.payload.toByteArray() |
| 704 | 704 | ||
| 705 | listener?.onDataReceived(data, participant, this) | 705 | listener?.onDataReceived(data, participant, this) |
| 706 | eventBus.postEvent(RoomEvent.DataReceived(this, data, participant), coroutineScope) | 706 | eventBus.postEvent(RoomEvent.DataReceived(this, data, participant), coroutineScope) |
| 707 | - participant.onDataReceived(data) | 707 | + participant?.onDataReceived(data) |
| 708 | } | 708 | } |
| 709 | 709 | ||
| 710 | /** | 710 | /** |
| @@ -1027,7 +1027,7 @@ interface RoomListener { | @@ -1027,7 +1027,7 @@ interface RoomListener { | ||
| 1027 | /** | 1027 | /** |
| 1028 | * Received data published by another participant | 1028 | * Received data published by another participant |
| 1029 | */ | 1029 | */ |
| 1030 | - fun onDataReceived(data: ByteArray, participant: RemoteParticipant, room: Room) {} | 1030 | + fun onDataReceived(data: ByteArray, participant: RemoteParticipant?, room: Room) {} |
| 1031 | 1031 | ||
| 1032 | /** | 1032 | /** |
| 1033 | * The connection quality for a participant has changed. | 1033 | * The connection quality for a participant has changed. |
| @@ -108,7 +108,7 @@ class CallViewModel( | @@ -108,7 +108,7 @@ class CallViewModel( | ||
| 108 | when (it) { | 108 | when (it) { |
| 109 | is RoomEvent.FailedToConnect -> mutableError.value = it.error | 109 | is RoomEvent.FailedToConnect -> mutableError.value = it.error |
| 110 | is RoomEvent.DataReceived -> { | 110 | is RoomEvent.DataReceived -> { |
| 111 | - val identity = it.participant.identity ?: "" | 111 | + val identity = it.participant?.identity ?: "server" |
| 112 | val message = it.data.toString(Charsets.UTF_8) | 112 | val message = it.data.toString(Charsets.UTF_8) |
| 113 | mutableDataReceived.emit("$identity: $message") | 113 | mutableDataReceived.emit("$identity: $message") |
| 114 | } | 114 | } |
-
请 注册 或 登录 后发表评论