You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a web worker code piece in my project.
It works fine when I do a flutter run web or take a web build.
But when I try to do a flutter run web --wasm or flutter build web --wasm, the web worker part does not work.
I am not able to do postMessage to my web worker instance.
Code snippet for creating and sending messages to web worker:
import 'dart:async';
import 'dart:js_interop';
import 'dart:typed_data';
import 'package:web/web.dart' as web;
class WebWorkers {
final _workers = <int, web.Worker>{};
Future<int> create(String url) async{
print('WebWorkersWeb.create: $url');
final worker = web.Worker(url.toJS);
final id = _workers.length;
_workers[id] = worker;
return id;
}
Stream<String> onMessage(int id) {
print('WebWorkersWeb.onMessage: $id');
final worker = _workers[id];
if (worker == null) {
throw PlatformException(
code: 'Unimplemented',
details: 'web_worker for web doesn\'t implement \'${id}\'',
);
}
final controller = StreamController<String>();
worker.addEventListener('message', (web.MessageEvent msg){
print('message from worker is ${msg.data.toString()}');
controller.add(msg.data.toString());
}.toJS);
return controller.stream;
}
Future<void> postMessage(int id, String message) async{
print('WebWorkersWeb.postMessage: $id, $message');
final worker = _workers[id];
worker.postMessage(message.toJS);
}
}
Does web worker in wasm builds require any additional handling?
The text was updated successfully, but these errors were encountered:
Can you share a minimal repro and the error you are seeing here? The above example doesn't have a main method. There shouldn't be any additional handling for web workers when compiling to Wasm.
I have a web worker code piece in my project.
It works fine when I do a
flutter run web
or take a web build.But when I try to do a
flutter run web --wasm
orflutter build web --wasm
, the web worker part does not work.I am not able to do postMessage to my web worker instance.
Code snippet for creating and sending messages to web worker:
Does web worker in wasm builds require any additional handling?
The text was updated successfully, but these errors were encountered: