createChannel static method

ClientChannel createChannel({
  1. String? address,
  2. int? port,
})

Implementation

static ClientChannel createChannel({String? address, int? port}) {
  if (address != null) {
    String addressPrefix = "";
    if (address.startsWith("http://") || address.startsWith("https://")) {
      var split = address.split("//");
      address = split[1];
    }
    if (address.contains(":")) {
      List<String> splited = address.split(':');
      address = addressPrefix + splited[0];
      port = int.parse(splited[1]);
    }
  }

  address = address ?? kBackendAddress;
  port = port ?? kBackendPort;
  ChannelOptions co =
      ((port != 80 && port != 81) && !(port >= 8080 && port <= 8085))
          ? const ChannelOptions(credentials: ChannelCredentials.secure())
          : const ChannelOptions(credentials: ChannelCredentials.insecure());

  return ClientChannel(
    address,
    port: port,
    options: co,
  );
}