start static method

Future<WxScanWorker> start({
  1. required String workerUrl,
  2. required Uint8List wxscanWasm,
  3. String? tfliteUrl,
  4. Uint8List? detectModel,
  5. Uint8List? srModel,
})

Starts a worker and gives it everything it needs.

workerUrl is this package's wxscan_worker.js, wxscanWasm the scanner module. tfliteUrl and the two weight buffers are the inference host; without them the worker still decodes, but the CNN stages are gone and small or distant symbols are found far less often.

Implementation

static Future<WxScanWorker> start({
  required String workerUrl,
  required Uint8List wxscanWasm,
  String? tfliteUrl,
  Uint8List? detectModel,
  Uint8List? srModel,
}) async {
  final options = JSObject()..setProperty('type'.toJS, 'module'.toJS);
  final client = WxScanWorker._(_Worker(workerUrl, options));
  client._listen();

  final withModels =
      tfliteUrl != null && detectModel != null && srModel != null;
  final reply = await client._send(
    'init',
    (message) {
      message.setProperty('wxscan'.toJS, wxscanWasm.buffer.toJS);
      if (withModels) {
        message
          ..setProperty('tflite'.toJS, tfliteUrl.toJS)
          ..setProperty('detect'.toJS, detectModel.buffer.toJS)
          ..setProperty('sr'.toJS, srModel.buffer.toJS);
      }
    },
    // Copied rather than transferred, unlike a frame. These buffers belong
    // to the caller, who has every reason to keep them — the camera plugin
    // and a still-image scanner in one application are handed the same
    // weights — and transferring would empty them on the way out.
  );
  client.hasDetector = reply
      .getProperty<JSBoolean>('hasDetector'.toJS)
      .toDart;
  client.hasSuperResolution = reply
      .getProperty<JSBoolean>('hasSuperResolution'.toJS)
      .toDart;
  return client;
}