updateFromInfo method

  1. @override
  2. @internal
Future<bool> updateFromInfo(
  1. ParticipantInfo info
)
override

Implementation

@override
@internal
Future<bool> updateFromInfo(lk_models.ParticipantInfo info) async {
  logger.fine('RemoteParticipant.updateFromInfo(info: $info)');
  if (!await super.updateFromInfo(info)) {
    //return false;
  }

  // figuring out deltas between tracks
  final newPubs = <RemoteTrackPublication>{};

  for (final trackInfo in info.tracks) {
    RemoteTrackPublication? pub = getTrackPublicationBySid(trackInfo.sid);
    if (pub == null) {
      final RemoteTrackPublication pub;
      if (trackInfo.type == lk_models.TrackType.VIDEO) {
        pub = RemoteTrackPublication<RemoteVideoTrack>(
          participant: this,
          info: trackInfo,
        );
      } else if (trackInfo.type == lk_models.TrackType.AUDIO) {
        pub = RemoteTrackPublication<RemoteAudioTrack>(
          participant: this,
          info: trackInfo,
        );
      } else {
        throw UnexpectedStateException('Unknown track type');
      }
      newPubs.add(pub);
      addTrackPublication(pub);
    } else {
      pub.updateFromInfo(trackInfo);
    }
  }

  // always emit events for new publications, Room will not forward them unless it's ready
  for (final pub in newPubs) {
    final event = TrackPublishedEvent(
      participant: this,
      publication: pub,
    );
    if (room.connectionState == ConnectionState.connected) {
      [events, room.events].emit(event);
    }
  }

  // remove any published track that is not in the info
  final validSids = info.tracks.map((e) => e.sid);
  final removeSids =
      trackPublications.keys.where((e) => !validSids.contains(e)).toSet();
  for (final sid in removeSids) {
    await removePublishedTrack(sid);
  }

  return true;
}