Repository navigation
Conversation
- `handleDataPacket` had `packet.participantIdentity` but dropped it before passing to `handleUserPacket` - added as required param internally, optional trailing arg on `RoomEventCallbacks.dataReceived` - allows callers to buffer and replay messages when the sender hasn't joined yet (data channel / participant join race)
🦋 Changeset detectedLatest commit: 85d5dcd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
thanks for the PR. This race shouldn't occur anymore in practice as the server is buffering messages for some time until a participant becomes active. |
Are you refering to this commit? I was running livekit-server 1.13.2 when implementing a client side buffering of messages with unknown remote participant senders. The original scenario was caused by our application's internal protocol. Participants would only accept messages from certain other participants. Without being able to check the sender (message sent directly after join, received before the sender was known as a remote participant), the messages were just discarded. Edit: The race we hit is purely on the client side: the data channel message (WebRTC) arrives before the participant update (join) signal (WebSocket) and the We can reproduce it by having a participant send a data message immediately on connected, before the receiving participant has had a chance to process the join signal. Our solution is a client side buffering of messages with no known remote participant - requiring this PRs change. We already observed and implemented something similar on the server component side: |
lukasIO
left a comment
There was a problem hiding this comment.
thanks for the reproduction.
This makes sense to add and your implementation looks good
Port of [livekit/client-sdk-js#2092](livekit/client-sdk-js#2092). ## The gap `DataReceivedEvent.participant` is null whenever the sender is not in `remoteParticipants`. The engine has the sender's identity on the packet but dropped it when building the event, so in that case the receiver could not tell who sent the data. This happens in normal use, not just edge cases: - **Join race.** The server announces a participant to its peers only once it is active, but the joiner's data channel is already open. Anything it sends in that window arrives before the `ParticipantUpdate` that would let the receiver resolve it. [livekit/rust-sdks#1574](livekit/rust-sdks#1574) measured about two seconds on a local server. - **Sender already left.** Data that arrives after the sender's disconnect has been processed. ## The fix Add `participantIdentity` to `DataReceivedEvent`, filled from the packet for every event, whether or not the sender resolves to a `RemoteParticipant`. Apps can use it to attribute or buffer data from a sender the room does not know yet. It is empty for data sent through the Server API (`SendDataRequest` has no identity field) and for data sent by hidden participants, because the server clears the identity in both cases. `toString()` now includes the identity. ## API The new constructor parameter defaults to `''`, so the constructor stays source compatible and this ships as a patch. `Room` is the only producer and always passes the identity. A TODO marks the constructor to become `@internal`, with the parameter `required`, in the next major release. ## Verification `test/core/data_received_identity_test.dart` delivers a packet from an identity that is not a room participant and checks that `participant` is null while the identity still arrives. A second case covers a known participant. Removing the identity from the event in `Room` makes both cases fail. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>
* Expose participantIdentity on RoomEvent.DataReceived DataReceived carries a nullable RemoteParticipant, which is null whenever the sender is not in the room - data sent through the Server API, or by a participant that has already left. In that case the receiver had no way to tell who sent the data. The identity was discarded before the event was built: the engine passed only the inner UserPacket to onUserPacket, while the authoritative participantIdentity lives on the enclosing DataPacket. Forward it through the listener and report it on every DataReceived event. Port of livekit/client-sdk-js#2092. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Keep the old DataReceived constructor signature and document the new field Addresses review feedback: - A Kotlin default argument emits the full-arity constructor plus a synthetic one, so the previous five-argument JVM signature would have disappeared and modules compiled against an earlier SDK would fail to link. Add an explicit five-argument secondary constructor. - AGENTS.md asks for a short example with a new public API, so show attributing data when `participant` is null. - Update the copyright year range that spotless requires. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: davidliu <davidliu@deviange.net>

handleDataPackethadpacket.participantIdentitybut dropped it before passing tohandleUserPacketRoomEventCallbacks.dataReceived