Skip to content

Commit 5ecc1d9

Browse files
authored
fix: set attributes of remote participants on participant creation (#1344)
* fix: set attributes of remote participants earlier Otherwise the attributes are not set during the "ParticipantConnected" event * chore: add changeset
1 parent 5ef24e9 commit 5ecc1d9

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

.changeset/tiny-adults-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
Set participant attributes as soon as possible, making them available in all related events

src/room/Room.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,10 +1735,18 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
17351735
loggerName: this.options.loggerName,
17361736
});
17371737
} else {
1738-
participant = new RemoteParticipant(this.engine.client, '', identity, undefined, undefined, {
1739-
loggerContextCb: () => this.logContext,
1740-
loggerName: this.options.loggerName,
1741-
});
1738+
participant = new RemoteParticipant(
1739+
this.engine.client,
1740+
'',
1741+
identity,
1742+
undefined,
1743+
undefined,
1744+
undefined,
1745+
{
1746+
loggerContextCb: () => this.logContext,
1747+
loggerName: this.options.loggerName,
1748+
},
1749+
);
17421750
}
17431751
if (this.options.webAudioMix) {
17441752
participant.setAudioContext(this.audioContext);

src/room/participant/LocalParticipant.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('LocalParticipant', () => {
4747
'Remote Participant',
4848
'',
4949
undefined,
50+
undefined,
5051
ParticipantKind.STANDARD,
5152
);
5253

@@ -92,6 +93,7 @@ describe('LocalParticipant', () => {
9293
'Remote Participant',
9394
'',
9495
undefined,
96+
undefined,
9597
ParticipantKind.STANDARD,
9698
);
9799

@@ -134,6 +136,7 @@ describe('LocalParticipant', () => {
134136
'Remote Participant',
135137
'',
136138
undefined,
139+
undefined,
137140
ParticipantKind.STANDARD,
138141
);
139142

@@ -196,6 +199,7 @@ describe('LocalParticipant', () => {
196199
'Remote Participant',
197200
'',
198201
undefined,
202+
undefined,
199203
ParticipantKind.STANDARD,
200204
);
201205
});

src/room/participant/LocalParticipant.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default class LocalParticipant extends Participant {
144144

145145
/** @internal */
146146
constructor(sid: string, identity: string, engine: RTCEngine, options: InternalRoomOptions) {
147-
super(sid, identity, undefined, undefined, {
147+
super(sid, identity, undefined, undefined, undefined, {
148148
loggerName: options.loggerName,
149149
loggerContextCb: () => this.engine.logContext,
150150
});

src/room/participant/Participant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
126126
identity: string,
127127
name?: string,
128128
metadata?: string,
129+
attributes?: Record<string, string>,
129130
loggerOptions?: LoggerOptions,
130131
kind: ParticipantKind = ParticipantKind.STANDARD,
131132
) {
@@ -143,7 +144,7 @@ export default class Participant extends (EventEmitter as new () => TypedEmitter
143144
this.videoTrackPublications = new Map();
144145
this.trackPublications = new Map();
145146
this._kind = kind;
146-
this._attributes = {};
147+
this._attributes = attributes ?? {};
147148
}
148149

149150
getTrackPublications(): TrackPublication[] {

src/room/participant/RemoteParticipant.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default class RemoteParticipant extends Participant {
4444
pi.identity,
4545
pi.name,
4646
pi.metadata,
47+
pi.attributes,
4748
loggerOptions,
4849
pi.kind,
4950
);
@@ -64,10 +65,11 @@ export default class RemoteParticipant extends Participant {
6465
identity?: string,
6566
name?: string,
6667
metadata?: string,
68+
attributes?: Record<string, string>,
6769
loggerOptions?: LoggerOptions,
6870
kind: ParticipantKind = ParticipantKind.STANDARD,
6971
) {
70-
super(sid, identity || '', name, metadata, loggerOptions, kind);
72+
super(sid, identity || '', name, metadata, attributes, loggerOptions, kind);
7173
this.signalClient = signalClient;
7274
this.trackPublications = new Map();
7375
this.audioTrackPublications = new Map();

0 commit comments

Comments
 (0)