onCandidatesReceived method

Future<void> onCandidatesReceived(
  1. List candidates
)

Implementation

Future<void> onCandidatesReceived(List<dynamic> candidates) async {
  for (final json in candidates) {
    final candidate = RTCIceCandidate(
      json['candidate'],
      json['sdpMid'] ?? '',
      json['sdpMLineIndex']?.round() ?? 0,
    );

    if (!candidate.isValid) {
      Logs().w(
          '[VOIP] onCandidatesReceived => skip invalid candidate $candidate');
      continue;
    }

    if (direction == CallDirection.kOutgoing &&
        pc != null &&
        await pc!.getRemoteDescription() == null) {
      remoteCandidates.add(candidate);
      continue;
    }

    if (pc != null && inviteOrAnswerSent && remotePartyId != null) {
      try {
        await pc!.addCandidate(candidate);
      } catch (e, s) {
        Logs().e('[VOIP] onCandidatesReceived => ', e, s);
      }
    } else {
      remoteCandidates.add(candidate);
    }
  }

  if (pc != null &&
      pc!.iceConnectionState ==
          RTCIceConnectionState.RTCIceConnectionStateDisconnected) {
    await restartIce();
  }
}