@@ -26,6 +26,7 @@ import '../publication/track_publication.dart';
2626import '../support/disposable.dart' ;
2727import '../types/other.dart' ;
2828import '../types/participant_permissions.dart' ;
29+ import '../types/participant_state.dart' ;
2930import '../utils.dart' ;
3031
3132/// Represents a Participant in the room, notifies changes via delegates as
@@ -38,8 +39,8 @@ import '../utils.dart';
3839
3940/// Base for [RemoteParticipant] and [LocalParticipant] ,
4041/// can not be instantiated directly.
41- abstract class Participant <T extends TrackPublication >
42- extends DisposableChangeNotifier with EventsEmittable <ParticipantEvent > {
42+ abstract class Participant <T extends TrackPublication > extends DisposableChangeNotifier
43+ with EventsEmittable <ParticipantEvent > {
4344 /// Reference to [Room]
4445 @internal
4546 final Room room;
@@ -80,16 +81,18 @@ abstract class Participant<T extends TrackPublication>
8081 ParticipantPermissions get permissions => _permissions;
8182
8283 /// Attributes associated with the participant
83- UnmodifiableMapView <String , String > get attributes =>
84- UnmodifiableMapView (_attributes);
84+ UnmodifiableMapView <String , String > get attributes => UnmodifiableMapView (_attributes);
8585 Map <String , String > _attributes = {};
8686
87+ // Participant state
88+ ParticipantState get state => _state;
89+ ParticipantState _state = ParticipantState .unknown;
90+
8791 /// when the participant joined the room
8892 DateTime get joinedAt {
8993 final pi = _participantInfo;
9094 if (pi != null ) {
91- return DateTime .fromMillisecondsSinceEpoch (pi.joinedAt.toInt () * 1000 ,
92- isUtc: true );
95+ return DateTime .fromMillisecondsSinceEpoch (pi.joinedAt.toInt () * 1000 , isUtc: true );
9396 }
9497 return DateTime .now ();
9598 }
@@ -176,15 +179,22 @@ abstract class Participant<T extends TrackPublication>
176179 }
177180 }
178181
182+ void _setParticipantState (ParticipantState state) {
183+ final didChange = _state != state;
184+ _state = state;
185+ if (didChange) {
186+ [events, room.events].emit (ParticipantStateUpdatedEvent (
187+ participant: this ,
188+ state: state,
189+ ));
190+ }
191+ }
192+
179193 void _setAttributes (Map <String , String > attrs) {
180- final diff = mapDiff (_attributes, attrs)
181- .map ((k, v) => MapEntry (k as String , v as String ));
194+ final diff = mapDiff (_attributes, attrs).map ((k, v) => MapEntry (k as String , v as String ));
182195 _attributes = attrs;
183196 if (diff.isNotEmpty) {
184- [
185- events,
186- room.events
187- ].emit (ParticipantAttributesChanged (participant: this , attributes: diff));
197+ [events, room.events].emit (ParticipantAttributesChanged (participant: this , attributes: diff));
188198 }
189199 }
190200
@@ -201,9 +211,7 @@ abstract class Participant<T extends TrackPublication>
201211 @internal
202212 Future <bool > updateFromInfo (lk_models.ParticipantInfo info) async {
203213 logger.fine ('LocalParticipant.updateFromInfo(info: $info )' );
204- if (_participantInfo != null &&
205- _participantInfo! .sid == info.sid &&
206- _participantInfo! .version > info.version) {
214+ if (_participantInfo != null && _participantInfo! .sid == info.sid && _participantInfo! .version > info.version) {
207215 return false ;
208216 }
209217
@@ -219,6 +227,7 @@ abstract class Participant<T extends TrackPublication>
219227 _setAttributes (info.attributes);
220228 _participantInfo = info;
221229 setPermissions (info.permission.toLKType ());
230+ _setParticipantState (info.state.toLKType ());
222231
223232 return true ;
224233 }
@@ -278,19 +287,14 @@ abstract class Participant<T extends TrackPublication>
278287 T ? getTrackPublicationBySource (TrackSource source) {
279288 if (source == TrackSource .unknown) return null ;
280289 // try to find by source
281- final result =
282- trackPublications.values.firstWhereOrNull ((e) => e.source == source);
290+ final result = trackPublications.values.firstWhereOrNull ((e) => e.source == source);
283291 if (result != null ) return result;
284292 // try to find by compatibility
285- return trackPublications.values
286- .where ((e) => e.source == TrackSource .unknown)
287- .firstWhereOrNull ((e) =>
288- (source == TrackSource .microphone && e.kind == TrackType .AUDIO ) ||
289- (source == TrackSource .camera && e.kind == TrackType .VIDEO ) ||
290- (source == TrackSource .screenShareVideo &&
291- e.kind == TrackType .VIDEO ) ||
292- (source == TrackSource .screenShareAudio &&
293- e.kind == TrackType .AUDIO ));
293+ return trackPublications.values.where ((e) => e.source == TrackSource .unknown).firstWhereOrNull ((e) =>
294+ (source == TrackSource .microphone && e.kind == TrackType .AUDIO ) ||
295+ (source == TrackSource .camera && e.kind == TrackType .VIDEO ) ||
296+ (source == TrackSource .screenShareVideo && e.kind == TrackType .VIDEO ) ||
297+ (source == TrackSource .screenShareAudio && e.kind == TrackType .AUDIO ));
294298 }
295299
296300 /// Convenience property to check whether [TrackSource.camera] is published or not.
@@ -300,20 +304,17 @@ abstract class Participant<T extends TrackPublication>
300304
301305 /// Convenience property to check whether [TrackSource.microphone] is published or not.
302306 bool isMicrophoneEnabled () {
303- return ! (getTrackPublicationBySource (TrackSource .microphone)? .muted ??
304- true );
307+ return ! (getTrackPublicationBySource (TrackSource .microphone)? .muted ?? true );
305308 }
306309
307310 /// Convenience property to check whether [TrackSource.screenShareVideo] is published or not.
308311 bool isScreenShareEnabled () {
309- return ! (getTrackPublicationBySource (TrackSource .screenShareVideo)? .muted ??
310- true );
312+ return ! (getTrackPublicationBySource (TrackSource .screenShareVideo)? .muted ?? true );
311313 }
312314
313315 /// Convenience property to check whether [TrackSource.screenShareAudio] is published or not.
314316 bool isScreenShareAudioEnabled () {
315- return ! (getTrackPublicationBySource (TrackSource .screenShareAudio)? .muted ??
316- true );
317+ return ! (getTrackPublicationBySource (TrackSource .screenShareAudio)? .muted ?? true );
317318 }
318319
319320 /// (Equality operator) [Participant.hashCode] is same as [sid.hashCode] .
0 commit comments