Skip to content

Expose participantIdentity on RoomEvent.DataReceived - #1046

Open
xianshijing-lk wants to merge 2 commits into
mainfrom
port/js-2092-data-received-identity
Open

xianshijing-lk wants to merge 2 commits into
mainfrom
port/js-2092-data-received-identity

Conversation

@xianshijing-lk

Copy link
Copy Markdown
Contributor

Port of livekit/client-sdk-js#2092.

The gap

RoomEvent.DataReceived.participant is nullable and is null whenever the sender is not in the room — data sent through the Server API, or by a participant who has already left. In that case the receiver cannot tell who sent the data at all; the identity is absent from the event.

Unlike the JS and Flutter SDKs, the identity was not merely unused here — it was discarded one layer earlier. RTCEngine unwraps the DataPacket and hands the listener only the inner UserPacket:

listener?.onUserPacket(dp.user, dp.kind, encryptionType)

The authoritative participantIdentity lives on the enclosing dp, so Room.onUserPacket never saw it and had nothing to put on the event.

The fix

Forward dp.participantIdentity through the internal RTCEngine.Listener.onUserPacket and surface it as DataReceived.participantIdentity, populated whether or not the sender resolves to a RemoteParticipant.

Verification

Added dataReceivedReportsSenderIdentityWithoutParticipant to RoomDataMockE2ETest, delivering a packet whose sender is not a room participant and asserting participant is null while the identity still arrives. Before the change it does not compile, since the field does not exist.

:livekit-android-test:testReleaseUnitTest green (both cases in that file run).

API notes

  • participantIdentity is added as a constructor parameter with a "" default, so existing construction sites keep compiling.
  • RTCEngine.Listener.onUserPacket gains a parameter. That interface is internal to the SDK and Room is its only implementor, so no public surface changes there.

Unrelated observation

While tracing this I noticed Room.onUserPacket resolves the sender with getParticipantBySid(packet.participantSid) — the inner packet's SID — whereas the JS and Flutter SDKs resolve by the outer packet's identity. Now that the identity is plumbed through, switching the lookup to it would also be possible. I have left the lookup alone here to keep this change focused; happy to file it separately if it's worth pursuing.

🤖 Generated with Claude Code

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>
@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f191c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
client-sdk-android Patch

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

devin-ai-integration[bot]

This comment was marked as resolved.

…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>
@github-actions

Copy link
Copy Markdown
Contributor

Diffuse output:

OLD: diffuse-source-file
NEW: livekit-android-sdk-release.aar

 AAR      │ old      │ new      │ diff   
──────────┼──────────┼──────────┼────────
      jar │    3 MiB │    3 MiB │ +353 B 
 manifest │  1.5 KiB │  1.5 KiB │    0 B 
 lint-jar │ 12.7 KiB │ 12.7 KiB │    0 B 
    other │  2.4 KiB │  2.4 KiB │    0 B 
──────────┼──────────┼──────────┼────────
    total │    3 MiB │    3 MiB │ +353 B 

 JAR     │ old   │ new   │ diff       
─────────┼───────┼───────┼────────────
 classes │  1707 │  1707 │  0 (+0 -0) 
 methods │ 21992 │ 21995 │ +3 (+5 -2) 
  fields │  5708 │  5709 │ +1 (+1 -0)
AAR
 size  │ diff   │ path          
───────┼────────┼───────────────
 3 MiB │ +353 B │ ∆ classes.jar 
───────┼────────┼───────────────
 3 MiB │ +353 B │ (total)
JAR
METHODS:

   old   │ new   │ diff       
  ───────┼───────┼────────────
   21992 │ 21995 │ +3 (+5 -2) 
  
  + io.livekit.android.events.RoomEvent_DataReceived <init>(Room, byte[], RemoteParticipant, String, LivekitModels_Encryption_Type, String)
  + io.livekit.android.events.RoomEvent_DataReceived <init>(Room, byte[], RemoteParticipant, String, LivekitModels_Encryption_Type, String, int, DefaultConstructorMarker)
  + io.livekit.android.events.RoomEvent_DataReceived getParticipantIdentity() → String
  + io.livekit.android.room.RTCEngine_Listener onUserPacket(LivekitModels_UserPacket, LivekitModels_DataPacket_Kind, LivekitModels_Encryption_Type, String)
  + io.livekit.android.room.Room onUserPacket(LivekitModels_UserPacket, LivekitModels_DataPacket_Kind, LivekitModels_Encryption_Type, String)
  
  - io.livekit.android.room.RTCEngine_Listener onUserPacket(LivekitModels_UserPacket, LivekitModels_DataPacket_Kind, LivekitModels_Encryption_Type)
  - io.livekit.android.room.Room onUserPacket(LivekitModels_UserPacket, LivekitModels_DataPacket_Kind, LivekitModels_Encryption_Type)
  

FIELDS:

   old  │ new  │ diff       
  ──────┼──────┼────────────
   5708 │ 5709 │ +1 (+1 -0) 
  
  + io.livekit.android.events.RoomEvent_DataReceived participantIdentity: String

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant