Skip to content

Commit 5b11500

Browse files
authored
Add support for participant attributes (#558)
* upgrade protocol to v1.19.1. * Add Attributes for Participant. * change attributes to UnmodifiableMapView. * update ParticipantPermissions. * dart run import_sorter:main. * fix.
1 parent 76973a3 commit 5b11500

File tree

10 files changed

+414
-21
lines changed

10 files changed

+414
-21
lines changed

lib/src/events.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ class RoomMetadataChangedEvent with RoomEvent {
115115
String toString() => '${runtimeType}()';
116116
}
117117

118+
/// Participant's attributes have changed.
119+
/// Emitted by [Room].
120+
class ParticipantAttributesChanged with RoomEvent, ParticipantEvent {
121+
final Participant participant;
122+
final Map<String, String> attributes;
123+
124+
const ParticipantAttributesChanged({
125+
required this.participant,
126+
required this.attributes,
127+
});
128+
129+
@override
130+
String toString() => '${runtimeType}(participant: ${participant})';
131+
}
132+
118133
/// Room recording status has changed.
119134
/// Emitted by [Room].
120135
class RoomRecordingStatusChanged with RoomEvent {

lib/src/participant/local.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
466466
));
467467
}
468468

469+
/// Sets and updates the attributes of the local participant.
470+
/// @attributes key-value pairs to set
471+
void setAttributes(Map<String, String> attributes) {
472+
room.engine.signalClient
473+
.sendUpdateLocalMetadata(lk_rtc.UpdateParticipantMetadata(
474+
attributes: attributes,
475+
));
476+
}
477+
469478
/// Sets and updates the name of the local participant.
470479
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
471480
/// @param name

lib/src/participant/participant.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import '../publication/track_publication.dart';
2626
import '../support/disposable.dart';
2727
import '../types/other.dart';
2828
import '../types/participant_permissions.dart';
29+
import '../utils.dart';
2930

3031
/// Represents a Participant in the room, notifies changes via delegates as
3132
/// well as ChangeNotifier/providers.
@@ -78,6 +79,11 @@ abstract class Participant<T extends TrackPublication>
7879
ParticipantPermissions _permissions = const ParticipantPermissions();
7980
ParticipantPermissions get permissions => _permissions;
8081

82+
/// Attributes associated with the participant
83+
UnmodifiableMapView<String, String> get attributes =>
84+
UnmodifiableMapView(_attributes);
85+
Map<String, String> _attributes = {};
86+
8187
/// when the participant joined the room
8288
DateTime get joinedAt {
8389
final pi = _participantInfo;
@@ -170,6 +176,18 @@ abstract class Participant<T extends TrackPublication>
170176
}
171177
}
172178

179+
void _setAttributes(Map<String, String> attrs) {
180+
final diff = mapDiff(_attributes, attrs)
181+
.map((k, v) => MapEntry(k as String, v as String));
182+
_attributes = attrs;
183+
if (diff.isNotEmpty) {
184+
[
185+
events,
186+
room.events
187+
].emit(ParticipantAttributesChanged(participant: this, attributes: diff));
188+
}
189+
}
190+
173191
@internal
174192
void updateConnectionQuality(ConnectionQuality quality) {
175193
if (_connectionQuality == quality) return;
@@ -196,6 +214,8 @@ abstract class Participant<T extends TrackPublication>
196214
if (info.metadata.isNotEmpty) {
197215
_setMetadata(info.metadata);
198216
}
217+
218+
_setAttributes(info.attributes);
199219
_participantInfo = info;
200220
setPermissions(info.permission.toLKType());
201221

lib/src/proto/livekit_models.pb.dart

Lines changed: 27 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/proto/livekit_models.pbjson.dart

Lines changed: 44 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)