From 462f7f3d3a6666aeb76d7b506fb195de27d21bed Mon Sep 17 00:00:00 2001 From: Tobias Ollmann Date: Thu, 5 Dec 2024 09:01:08 +0100 Subject: [PATCH 1/2] fix: set attributes of remote participants earlier Otherwise the attributes are not set during the "ParticipantConnected" event --- src/room/Room.ts | 16 ++++++++++++---- src/room/participant/LocalParticipant.test.ts | 4 ++++ src/room/participant/LocalParticipant.ts | 2 +- src/room/participant/Participant.ts | 3 ++- src/room/participant/RemoteParticipant.ts | 4 +++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/room/Room.ts b/src/room/Room.ts index ce9e7235c1..2ebcb294fa 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -1733,10 +1733,18 @@ class Room extends (EventEmitter as new () => TypedEmitter) loggerName: this.options.loggerName, }); } else { - participant = new RemoteParticipant(this.engine.client, '', identity, undefined, undefined, { - loggerContextCb: () => this.logContext, - loggerName: this.options.loggerName, - }); + participant = new RemoteParticipant( + this.engine.client, + '', + identity, + undefined, + undefined, + undefined, + { + loggerContextCb: () => this.logContext, + loggerName: this.options.loggerName, + }, + ); } if (this.options.webAudioMix) { participant.setAudioContext(this.audioContext); diff --git a/src/room/participant/LocalParticipant.test.ts b/src/room/participant/LocalParticipant.test.ts index 3b7d6435a0..238d16a306 100644 --- a/src/room/participant/LocalParticipant.test.ts +++ b/src/room/participant/LocalParticipant.test.ts @@ -47,6 +47,7 @@ describe('LocalParticipant', () => { 'Remote Participant', '', undefined, + undefined, ParticipantKind.STANDARD, ); @@ -92,6 +93,7 @@ describe('LocalParticipant', () => { 'Remote Participant', '', undefined, + undefined, ParticipantKind.STANDARD, ); @@ -134,6 +136,7 @@ describe('LocalParticipant', () => { 'Remote Participant', '', undefined, + undefined, ParticipantKind.STANDARD, ); @@ -196,6 +199,7 @@ describe('LocalParticipant', () => { 'Remote Participant', '', undefined, + undefined, ParticipantKind.STANDARD, ); }); diff --git a/src/room/participant/LocalParticipant.ts b/src/room/participant/LocalParticipant.ts index 5504ed6e7f..3c5e99b84e 100644 --- a/src/room/participant/LocalParticipant.ts +++ b/src/room/participant/LocalParticipant.ts @@ -144,7 +144,7 @@ export default class LocalParticipant extends Participant { /** @internal */ constructor(sid: string, identity: string, engine: RTCEngine, options: InternalRoomOptions) { - super(sid, identity, undefined, undefined, { + super(sid, identity, undefined, undefined, undefined, { loggerName: options.loggerName, loggerContextCb: () => this.engine.logContext, }); diff --git a/src/room/participant/Participant.ts b/src/room/participant/Participant.ts index a414c97066..d80f29482d 100644 --- a/src/room/participant/Participant.ts +++ b/src/room/participant/Participant.ts @@ -126,6 +126,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter identity: string, name?: string, metadata?: string, + attributes?: Record, loggerOptions?: LoggerOptions, kind: ParticipantKind = ParticipantKind.STANDARD, ) { @@ -143,7 +144,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter this.videoTrackPublications = new Map(); this.trackPublications = new Map(); this._kind = kind; - this._attributes = {}; + this._attributes = attributes ?? {}; } getTrackPublications(): TrackPublication[] { diff --git a/src/room/participant/RemoteParticipant.ts b/src/room/participant/RemoteParticipant.ts index b84d5455d8..ccd17584e7 100644 --- a/src/room/participant/RemoteParticipant.ts +++ b/src/room/participant/RemoteParticipant.ts @@ -44,6 +44,7 @@ export default class RemoteParticipant extends Participant { pi.identity, pi.name, pi.metadata, + pi.attributes, loggerOptions, pi.kind, ); @@ -64,10 +65,11 @@ export default class RemoteParticipant extends Participant { identity?: string, name?: string, metadata?: string, + attributes?: Record, loggerOptions?: LoggerOptions, kind: ParticipantKind = ParticipantKind.STANDARD, ) { - super(sid, identity || '', name, metadata, loggerOptions, kind); + super(sid, identity || '', name, metadata, attributes, loggerOptions, kind); this.signalClient = signalClient; this.trackPublications = new Map(); this.audioTrackPublications = new Map(); From 238f37bdda75915190f34d4670052d94d1959a37 Mon Sep 17 00:00:00 2001 From: Tobias Ollmann Date: Thu, 5 Dec 2024 09:25:45 +0100 Subject: [PATCH 2/2] chore: add changeset --- .changeset/tiny-adults-think.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tiny-adults-think.md diff --git a/.changeset/tiny-adults-think.md b/.changeset/tiny-adults-think.md new file mode 100644 index 0000000000..af8d801258 --- /dev/null +++ b/.changeset/tiny-adults-think.md @@ -0,0 +1,5 @@ +--- +'livekit-client': patch +--- + +Set participant attributes as soon as possible, making them available in all related events