ObbyClient.fromConfig constructor

ObbyClient.fromConfig(
  1. Map<String, dynamic> config, {
  2. String? libraryPath,
})

Open a connection's engine from a config map already in the wire shape.

For a host that already has a config to hand, built or loaded some other way. Only nick is required in config; every other field has a default.

Implementation

factory ObbyClient.fromConfig(Map<String, dynamic> config, {String? libraryPath}) {
  final bindings = Bindings(_load(libraryPath));
  final json = jsonEncode(config).toNativeUtf8();
  try {
    final handle = bindings.newClient(json);
    if (handle == nullptr) {
      throw ArgumentError.value(config, 'config', 'the engine refused it');
    }
    return ObbyClient._(bindings, handle);
  } finally {
    calloc.free(json);
  }
}