createAsync static method

Future<HandshakeIP> createAsync(
  1. RawDatagramSocket socket
)

Implementation

static Future<HandshakeIP> createAsync(RawDatagramSocket socket) async {
  // Configure STUN handler
  final input = (
    address: null,
    port: null,
    socket: socket,
  );
  final handler = StunHandler(input);
  final local = await handler.performLocalRequest();
  final public = await handler.performStunRequest();
  if (socket.address.type == InternetAddressType.IPv4) {
    return HandshakeIP._iPv4(
      PeerInfo(address: InternetAddress(public.publicIp), port: public.publicPort),
      PeerInfo(address: InternetAddress(local.localIp), port: local.localPort),
    );
  } else {
    return HandshakeIP._iPv6(
      PeerInfo(address: InternetAddress(public.publicIp), port: public.publicPort),
      PeerInfo(address: InternetAddress(local.localIp), port: local.localPort),
    );
  }
}