NakamaGrpcClient.init constructor

NakamaGrpcClient.init({
  1. String? host,
  2. String? serverKey,
  3. String key = _kDefaultAppKey,
  4. int port = 7349,
  5. bool ssl = false,
})

Either inits and returns a new instance of NakamaGrpcClient or returns a already initialized one.

Implementation

factory NakamaGrpcClient.init({
  String? host,
  String? serverKey,
  String key = _kDefaultAppKey,
  int port = 7349,
  bool ssl = false,
}) {
  if (_clients.containsKey(key)) {
    return _clients[key]!;
  }

  // Not yet initialized -> check if we've got all parameters to do so
  if (host == null || serverKey == null) {
    throw Exception(
      'Not yet initialized, need parameters [host] and [serverKey] to initialize.',
    );
  }

  // Create a new instance of this with given parameters.
  return _clients[key] = NakamaGrpcClient(
    host: host,
    port: port,
    serverKey: serverKey,
    ssl: ssl,
  );
}