removeMediaTrack method

  1. @override
Future<MediaStream> removeMediaTrack(
  1. String trackId
)

Implementation

@override
Future<MediaStream> removeMediaTrack(String trackId) {
  if (localStream == null) {
    return Future.error(IllegalStateException(
        'Can\'t remove the track cause the local media stream doesn\'t exist'));
  }

  var track = localStream?.getTrackById(trackId);

  if (track == null) {
    return Future.error(IllegalStateException(
        'Can\'t remove the track cause it not found in the local media stream'));
  }

  return channels[publisherId]?.removeTrack(trackId).then((_) {
        localStream?.removeTrack(track);
        track.stop();
        onLocalStreamReceived?.call(localStream!);

        return localStream!;
      }) ??
      Future.error(IllegalStateException(
          'Can\'t remove the track cause the publisher\'s peer connection doesn\'t exist'));
}