sendCmd method
Send a structured command to the Web Worker.
Convenience method for sending commands with optional data payload and transferable objects. Handles JS interop automatically.
Parameters:
command: Command string for the worker to processdata: Optional data payloadtransfer: Optional transferable objects (ArrayBuffers, etc.)
Usage: {@tool snippet example/web_example.dart} {@end-tool}
Implementation
void sendCmd(
String command, {
Map<String, Object?>? data,
JSObject? transfer,
}) {
final payload = <String, Object?>{...?data, 'command': command};
if (transfer != null) {
postMessage(payload.jsify(), transfer);
} else {
postMessage(payload.jsify());
}
}