Candidate.fromSdp constructor

Candidate.fromSdp(
  1. String sdp
)

Implementation

Candidate.fromSdp(String sdp) {
  List<String> arr = sdp.split(" ");
  String firstIp = "";
  String firstPort = "";
  String secondIp = "";
  String secondPort = "";
  final possibleType = ["host", "srflx", "prflx", "relay"];
  for (int i = 0; i < arr.length; i++) {
    final text = arr[i];
    if (text == "udp" || text == "tcp") {
      transportType = text;
    } else if (Candidate._verifyWholeIP(text) == true) {
      if (firstIp == "") {
        firstIp = text;
        if (i+1 < arr.length) {
          firstPort = arr[i+1];
        }
      } else {
        secondIp = text;
        if (i+2 < arr.length) {
          secondPort = arr[i+2];
        }
      }
    } else if (text == "typ") {
      if (i+1 < arr.length) {
        final typ = arr[i+1];
        if (possibleType.contains(typ) == true) {
          type = typ;
        }
      }
    }
    if (firstIp.isNotEmpty && firstPort.isNotEmpty) {
      sourceIp = firstIp;
      sourcePort = firstPort;
    }
    if (secondIp.isNotEmpty && secondPort.isNotEmpty) {
      destIp = secondIp;
      destPort = secondPort;
    }
  }
}