postIceCandidates method

dynamic postIceCandidates()

Implementation

postIceCandidates() async {
  var pending = [..._pendingIceCandidates];
  _pendingIceCandidates.clear();

  var local = await connection.getLocalDescription();
  var remote = await connection.getRemoteDescription();

  // Don't send ice candidates until both offer and answer is set
  // This is mainly to simplify for clients so they don't have to handle the
  // case of ice candidates getting received before offer on non initiator.
  if (local != null && remote != null) {
    for (var candidate in pending) {
      var type = _initiator ? 'senderIceCandidate' : 'receiverIceCandidate';
      await _signaling(type, candidate.toMap());
    }
  } else {
    _pendingIceCandidates.addAll(pending);
  }
}