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 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();