From 44a42eafea672dcafeac0e12574c05f0e795b902 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Sun, 2 Jan 2022 01:38:54 +0700 Subject: [PATCH] name field for participant --- example/lib/widgets/participant.dart | 4 +++- lib/src/core/room.dart | 1 + lib/src/participant/local.dart | 1 + lib/src/participant/participant.dart | 8 +++++++- lib/src/participant/remote.dart | 3 +++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/example/lib/widgets/participant.dart b/example/lib/widgets/participant.dart index caeaa02..73cdf5c 100644 --- a/example/lib/widgets/participant.dart +++ b/example/lib/widgets/participant.dart @@ -126,7 +126,9 @@ abstract class _ParticipantWidgetState children: [ ...extraWidgets(), ParticipantInfoWidget( - title: widget.participant.identity, + title: widget.participant.name.isNotEmpty + ? '${widget.participant.name} (${widget.participant.identity})' + : widget.participant.identity, audioAvailable: firstAudioPublication?.muted == false && firstAudioPublication?.subscribed == true, connectionQuality: widget.participant.connectionQuality, diff --git a/lib/src/core/room.dart b/lib/src/core/room.dart index 9a95945..e1a5689 100644 --- a/lib/src/core/room.dart +++ b/lib/src/core/room.dart @@ -222,6 +222,7 @@ class Room extends DisposableChangeNotifier with EventsEmittable { room: this, sid: sid, identity: '', + name: '', ); } else { participant = RemoteParticipant.fromInfo( diff --git a/lib/src/participant/local.dart b/lib/src/participant/local.dart index fd8bf61..3c04b28 100644 --- a/lib/src/participant/local.dart +++ b/lib/src/participant/local.dart @@ -28,6 +28,7 @@ class LocalParticipant extends Participant { room: room, sid: info.sid, identity: info.identity, + name: info.name, ) { updateFromInfo(info); } diff --git a/lib/src/participant/participant.dart b/lib/src/participant/participant.dart index 57f02a3..317ab06 100644 --- a/lib/src/participant/participant.dart +++ b/lib/src/participant/participant.dart @@ -43,6 +43,10 @@ abstract class Participant /// User-assigned identity. String identity; + /// Name of the participant (readonly). + String get name => _name; + String _name; + /// Client-assigned metadata, opaque to livekit. String? metadata; @@ -94,7 +98,8 @@ abstract class Participant required this.room, required this.sid, required this.identity, - }) { + required String name, + }) : _name = name { // Any event emitted will trigger ChangeNotifier events.listen((event) { logger.fine('[ParticipantEvent] $event, will notifyListeners()'); @@ -150,6 +155,7 @@ abstract class Participant @internal void updateFromInfo(lk_models.ParticipantInfo info) { identity = info.identity; + _name = info.name; // participantSid = info.sid; if (info.metadata.isNotEmpty) { _setMetadata(info.metadata); diff --git a/lib/src/participant/remote.dart b/lib/src/participant/remote.dart index bad10e3..3e847ae 100644 --- a/lib/src/participant/remote.dart +++ b/lib/src/participant/remote.dart @@ -22,10 +22,12 @@ class RemoteParticipant extends Participant { required Room room, required String sid, required String identity, + required String name, }) : super( room: room, sid: sid, identity: identity, + name: name, ); @internal @@ -36,6 +38,7 @@ class RemoteParticipant extends Participant { room: room, sid: info.sid, identity: info.identity, + name: info.name, ) { updateFromInfo(info); }