create static method

Future<WebTaskWorker> create(
  1. String family,
  2. Map<String, Object?> options, {
  3. bool longRequests = false,
})

Starts a worker from family's worker script (mediapipe_text or mediapipe_audio) and creates its task from options: the task's settings named as in Google's JavaScript API, plus modelBytes or modelPath, a URL resolved against the page.

longRequests lifts the bridge's time limits, for a task whose requests take time in proportion to their input.

Implementation

static Future<WebTaskWorker> create(
  String family,
  Map<String, Object?> options, {
  bool longRequests = false,
}) async {
  await loadPackageScript('mediapipe_core', 'assets/task_bridge.js');
  final bytes = options['modelBytes'] as Uint8List?;
  final path = options['modelPath'] as String?;
  final input = {
    ...options,
    'modelBytes': bytes == null ? null : Uint8List.fromList(bytes).toJS,
    'modelPath': path == null ? null : Uri.base.resolve(path).toString(),
    'runtimeBaseUrl': MediaPipeWebRuntime.resolve(Uri.base),
  }.jsify()!;
  final worker = Uri.base.resolve('assets/packages/$family/assets/worker.js');
  return WebTaskWorker._(
    await _reported(
      _create(worker.toString().toJS, input as JSObject, longRequests.toJS),
    ),
  );
}