unsubscribe method

Future<void> unsubscribe()

Implementation

Future<void> unsubscribe() async {
  if (!super.subscribed || !_subscriptionAllowed) {
    logger.fine('ignoring unsubscribe() request...');
    return;
  }
  _sendUpdateSubscription(subscribed: false);
  if (track != null) {
    // Ideally, we should wait for WebRTC's onRemoveTrack event
    // but it does not work reliably across platforms.
    // So for now we will assume remove track succeeded.
    [participant.events, participant.room.events].emit(
      TrackUnsubscribedEvent(
        participant: participant,
        track: track!,
        publication: this,
      ),
    );
    // Simply set to null for now
    await updateTrack(null);
  }
}