Open sabin26 opened 2 weeks ago
I've committed https://github.com/d-markey/squadron/commit/7e951e7a51fa189984a0c40862991746cb6f468e to tentatively fix your issue... according to the stack trace, it happens on line 68 in lib/src/_impl/web/_channel.dart, where something like $<obj> as Class(Object)
is happening since err
is dynamic
. So it will probably uncover another issue and the connection will likely raise a SquadronErrorExt.create('Unexpected error')
.
Could you post the generated code from codec_service.worker.g.dart
? (avoid posting the full code in a comment, just attach the file instead please)
Also, I understand you compiled your Flutter app to Web Assembly, but did you also compile workers to Web Assembly?
At least, this fix made test "- Squadron Worker - initialization error - not found" pass again :-) Thanks!
Also, I understand you compiled your Flutter app to Web Assembly, but did you also compile workers to Web Assembly?
Scenario 1: CodecService
@SquadronService(baseUrl: '/services/codec', wasm: false) // Raises runtime exception TypeError (this issue)
@SquadronService(baseUrl: '/services/codec', wasm: true) // No error but I would get on to scenario 2
Scenario 2: WebSocketService
@SquadronService(baseUrl: '/services/websocket', wasm: true) // Another issue but no exception
For wasm: false (default):
dart compile js codec_service.web.g.dart -o codec_service.web.g.dart.js
For wasm: true:
dart compile wasm codec_service.web.g.dart -o codec_service.web.g.dart.wasm
I don't know how to explain scenario 2 because there is no exception, but I don't receive WebSocket messages in a Stream. I will open another issue if this issue resolves first.
Flutter app does runtime check to see if the browser supports wasm. How will squadron manage to do the same ? For js app, load js worker and for wasm app, load wasm worker ?
Do I have to dual compile ?
dart compile js codec_service.web.g.dart -o codec_service.web.g.dart.js
dart compile wasm codec_service.web.g.dart -o codec_service.web.g.dart.wasm
Could you post the generated code from codec_service.worker.g.dart? (avoid posting the full code in a comment, just attach the file instead please)
I had to change the extension to .txt to upload it here.
Thanks for the file, I don't think the error comes from the generated code.
What output do you have in your browser's console logs?
The logs I shared on the first post is from the browser console when the app is launched and some action is performed. The app compiles to wasm sucessfully. So, no compilation error.
Flutter app does runtime check to see if the browser supports wasm. How will squadron manage to do the same ? For js app, load js worker and for wasm app, load wasm worker ?
Do I have to dual compile ?
Yes, you'd have to dual compile AND implement any logic you need to serve JS or wasm. I believe you'd also have to copy the files generated by squadron_builder
, because the entry point URI is either js or wasm. Also the worker code is hard-wired on that URI, so the generated worker code will also need some adaptations.
It's an interesting feature, I'll keep that in mind once everything wasm is sorted out.
The same code works as expected when my flutter app is compiled to javascript but when I compile it to wasm, I get the following error:
Pubspec.yaml