Skip to content

Commit

Permalink
Add Attributes for Participant.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Jul 16, 2024
1 parent 6e22c49 commit 53f5479
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ class RoomMetadataChangedEvent with RoomEvent {
String toString() => '${runtimeType}()';
}

/// Participant's attributes have changed.
/// Emitted by [Room].
class ParticipantAttributesChanged with RoomEvent {
final Participant participant;
final Map<String, String> attributes;

const ParticipantAttributesChanged({
required this.participant,
required this.attributes,
});

@override
String toString() => '${runtimeType}(participant: ${participant})';
}

/// Room recording status has changed.
/// Emitted by [Room].
class RoomRecordingStatusChanged with RoomEvent {
Expand Down
13 changes: 12 additions & 1 deletion lib/src/participant/local.dart
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,25 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
/// Sets and updates the metadata of the local participant.
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
/// @param metadata
void setMetadata(String metadata, {Map<String, String>? attributes}) {
void setMetadata(String metadata) {
room.engine.signalClient
.sendUpdateLocalMetadata(lk_rtc.UpdateParticipantMetadata(
name: name,
metadata: metadata,
));
}

/// Sets and updates the attributes of the local participant.
/// @attributes key-value pairs to set
void setAttributes(Map<String, String> attributes) {
room.engine.signalClient
.sendUpdateLocalMetadata(lk_rtc.UpdateParticipantMetadata(
name: name,
metadata: metadata ?? '',
attributes: attributes,
));
}

/// Sets and updates the name of the local participant.
/// Note: this requires `CanUpdateOwnMetadata` permission encoded in the token.
/// @param name
Expand Down
17 changes: 17 additions & 0 deletions lib/src/participant/participant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ abstract class Participant<T extends TrackPublication>
ParticipantPermissions _permissions = const ParticipantPermissions();
ParticipantPermissions get permissions => _permissions;

/// Attributes associated with the participant
Map<String, String> get attributes => _attributes;
Map<String, String> _attributes = {};

/// when the participant joined the room
DateTime get joinedAt {
final pi = _participantInfo;
Expand Down Expand Up @@ -170,6 +174,17 @@ abstract class Participant<T extends TrackPublication>
}
}

void _setAttributes(Map<String, String> attrs) {
final changed = !const MapEquality().equals(_attributes, attrs);
_attributes = attrs;
if (changed) {
[events, room.events].emit(ParticipantAttributesChanged(
participant: this,
attributes: attrs,
));
}
}

@internal
void updateConnectionQuality(ConnectionQuality quality) {
if (_connectionQuality == quality) return;
Expand All @@ -196,6 +211,8 @@ abstract class Participant<T extends TrackPublication>
if (info.metadata.isNotEmpty) {
_setMetadata(info.metadata);
}

_setAttributes(info.attributes);
_participantInfo = info;
setPermissions(info.permission.toLKType());

Expand Down

0 comments on commit 53f5479

Please sign in to comment.