Skip to content

Expose participantIdentity on DataReceivedEvent - #1256

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

xianshijing-lk wants to merge 3 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

DataReceivedEvent.participant is nullable, and the field's own comment says why:

/// Sender of the data. This may be null if data is sent from Server API.
final RemoteParticipant? participant;

When it is null — data sent via the Server API, or by a participant who has already left — the receiver has no way to tell who sent the data. The identity is not merely hard to get, it is absent from the event entirely.

The engine has it in hand at the construction site and simply drops it:

RemoteParticipant? senderParticipant;
if (dataPacketEvent.identity.isNotEmpty) {
  senderParticipant = getParticipantByIdentity(dataPacketEvent.identity) as RemoteParticipant?;
}

final event = DataReceivedEvent(
  participant: senderParticipant,   // <- dataPacketEvent.identity is right here
  data: dataPacketEvent.packet.payload,
  topic: dataPacketEvent.packet.topic,
);

The fix

Add a non-nullable participantIdentity to DataReceivedEvent, populated from the packet for every event — present whether or not the sender resolves to a RemoteParticipant.

Verification

Added test/core/data_received_identity_test.dart, which delivers an inbound packet from an identity that is not a room participant and asserts the identity still arrives. Before the change it does not compile, because the field does not exist:

Error: The getter 'participantIdentity' isn't defined for the type 'DataReceivedEvent'.

A second case covers a known participant, so both the resolved and unresolved paths are pinned.

flutter test 472/472, flutter analyze lib/ clean.

API note

This adds a required named parameter to the public DataReceivedEvent constructor. Nothing outside the SDK should be constructing these — the engine is the only producer — but it is technically breaking for anyone who does (a test fake, say). Happy to make it optional with a default of '' instead if you'd prefer to keep the constructor source-compatible.

🤖 Generated with Claude Code

DataReceivedEvent carries a nullable RemoteParticipant, which is null
whenever the sender is not in remoteParticipants - data sent through the
Server API, or by a participant that has already left. In that case the
receiver had no way at all to tell who sent the data, even though the
engine had the identity in hand at the construction site.

Add participantIdentity, populated from the data packet for every event.

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

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@github-actions

This comment has been minimized.

xianshijing-lk and others added 2 commits October 23, 2026 16:57
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A required named parameter breaks existing DataReceivedEvent callers and
would make this a major release. The engine is the only producer and
always passes the identity, so defaulting it keeps the change additive
and the patch bump honest. Matches the Android port.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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