feat(web): migrate web bindings to dart:js_interop for WebAssembly (dart2wasm) support#132
Open
sunweiyang wants to merge 1 commit into
Open
Conversation
Under dart2wasm the 'dart.library.js' conditional-import predicate is false, so the platform selection fell through to the stub and createAgoraRtcEngine() threw UnimplementedError on flutter build web --wasm. Switch the conditionals to 'dart.library.js_interop' (true under both dart2js and dart2wasm) and migrate the web bindings off legacy package:js/dart:js: - iris_api_common_bindings_js.dart: @JS/@anonymous classes -> dart:js_interop extension types; array members are JSArray; callIrisApi is typed as JSPromise<CallIrisApiResult> (what IrisCore.callIrisApi actually returns); IrisCEventHandler is now a JSFunction typedef. - iris_method_channel_internal_web.dart: allowInterop -> .toJS. - SDK floor raised to 3.3 (extension types); generated ffi Struct subclasses marked 'final' to satisfy Dart 3 class modifiers. Note: consumers of iris_method_channel_bindings_web.dart must convert Dart lists/typed-data with .toJS (see Agora-Flutter-SDK companion change). Tests under test/platform/fake still use legacy interop and are unchanged. Generated with AI assistance (Claude Code). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
flutter build web --wasmbuilds that include this package compile successfully but break at runtime: the platform implementation is selected viaand under dart2wasm both
dart.library.ioanddart.library.jsare false (wasm exposesdart.library.js_interopinstead), so the stub implementation is exported andcreateAgoraRtcEngine()in agora_rtc_engine throwsUnimplementedError: Unimplemented createPlatformBindingsProviderbefore any API call runs. Because this is a silent wrong-import selection rather than a compile error, apps only discover it in production wasm builds.Changes
iris_method_channel_internal.dartandutils.dart:dart.library.js→dart.library.js_interop, which is true under both dart2js and dart2wasm, so a single web implementation serves both compilers (including the JS fallback that--wasmbuilds ship for non-wasmGC browsers).lib/src/platform/web/bindings/iris_api_common_bindings_js.dart: migrated from legacypackage:js@JS()/@anonymousclasses todart:js_interopextension types (legacypackage:js/dart:jsare unavailable under dart2wasm):JSArray— under dart2wasm DartLists are not JS arrays, so implicit passthrough no longer exists; callers convert with.toJS/.toDart.callIrisApiis now typedJSPromise<CallIrisApiResult>(whatIrisCore.callIrisApiactually returns) instead ofint+ adartify()Promise cast, which does not work under dart2wasm.IrisCEventHandleris now aJSFunctiontypedef;iris_method_channel_internal_web.dartuses.toJSinstead ofallowInterop.pubspec.yaml: SDK floor raised to>=3.3.0(required fordart:js_interopextension types). The language-version bump also requires the ffigen-generatedffi.Structsubclasses to befinal(Dart 3 class modifiers) — io-only files, no behavior change.Breaking-change note
The exported web bindings surface (
iris_method_channel_bindings_web.dart) changes shape (JS types instead of Dart lists/functions). Its consumer in agora_rtc_engine needs the matching one-file update to its web binding delegate — I will submit that companion PR to Agora-Flutter-SDK referencing this one.test/platform/fakestill uses legacy interop and is untouched in this PR; happy to migrate it as well if you'd like.Testing
dart analyze libclean (errors/warnings).createAgoraRtcEngine→initialize→registerEventHandler→enableAudio→joinChannelall succeed, and the JS→Dart event path delivers typed events (including thebuffermarshalling in both directions). dart2js behavior is unchanged.