Skip to content

Commit

Permalink
Improve room/participants metadata update. (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Nov 16, 2023
1 parent 4733f8f commit 74d7bcb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/exts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,6 @@ enum SimulateScenarioResult {
switchCandidate,
clear,
e2eeKeyRatchet,
participantName,
participantMetadata,
}
8 changes: 8 additions & 0 deletions example/lib/pages/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ class _RoomPageState extends State<RoomPage> {
..on<ParticipantNameUpdatedEvent>((event) {
print(
'Participant name updated: ${event.participant.identity}, name => ${event.name}');
_sortParticipants();
})
..on<ParticipantMetadataUpdatedEvent>((event) {
print(
'Participant metadata updated: ${event.participant.identity}, metadata => ${event.metadata}');
})
..on<RoomMetadataChangedEvent>((event) {
print('Room metadata changed: ${event.metadata}');
})
..on<DataReceivedEvent>((event) {
String decoded = 'Failed to decode';
Expand Down
10 changes: 10 additions & 0 deletions example/lib/widgets/controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ class _ControlsWidgetState extends State<ControlsWidget> {
await widget.room.e2eeManager?.ratchetKey();
}

if (SimulateScenarioResult.participantMetadata == result) {
widget.room.localParticipant?.setMetadata(
'new metadata ${widget.room.localParticipant?.identity}');
}

if (SimulateScenarioResult.participantName == result) {
widget.room.localParticipant
?.setName('new name for ${widget.room.localParticipant?.identity}');
}

await widget.room.sendSimulateScenario(
signalReconnect:
result == SimulateScenarioResult.signalReconnect ? true : null,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ class TrackStreamStateUpdatedEvent with RoomEvent, ParticipantEvent {
/// Emitted by [Room] and [Participant].
class ParticipantMetadataUpdatedEvent with RoomEvent, ParticipantEvent {
final Participant participant;
final String metadata;
const ParticipantMetadataUpdatedEvent({
required this.participant,
required this.metadata,
});

@override
Expand Down
1 change: 1 addition & 0 deletions lib/src/participant/participant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ abstract class Participant<T extends TrackPublication>
if (changed) {
[events, room.events].emit(ParticipantMetadataUpdatedEvent(
participant: this,
metadata: md,
));
}
}
Expand Down

0 comments on commit 74d7bcb

Please sign in to comment.