Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BroadcastChannel is not a type. #96

Open
jay-athelas opened this issue Mar 22, 2024 · 2 comments
Open

BroadcastChannel is not a type. #96

jay-athelas opened this issue Mar 22, 2024 · 2 comments

Comments

@jay-athelas
Copy link

I am trying to use the BroadcastChannel api , to send communication between a service worker and the main thread. Our app is hybrid, currently support web, ios and android.

Even when importing from import 'package:universal_html/html.dart'; I get a compilation error when trying to build for ios, stating that BroadastChannel is not a type. I can click on it and see the definition in html_dart2js.dart. What is going on here?

To replicate:

  • Import universal html
  • Use BroacastChannel BroadcastChannel? _channel;
  • Compile for ios
@dab246
Copy link

dab246 commented Mar 25, 2024

You can use 1 of the following 2 ways:

  1. Use of conditional imports/exports
  • Create 'broadcast_channel_stub.dart' to use for mobile:
class BroadcastChannel {
   final String name;

   BroadcastChannel(this.name);

   Stream<dynamic> get onMessage => const Stream.empty();
}
  • Create 'broadcast_channel_web.dart' to use for web:
export 'dart:html' show BroadcastChannel;
  • Create 'broadcast_channel.dart' to use for all platforms:
export 'broadcast_channel_stub.dart' if (dart.library.html) 'broadcast_channel_web.dart';
  1. Wait for PR #97 to be merged for use.

@jay-athelas
Copy link
Author

Thanks @dab246 , awesome, do you have an estimate of when this PR might be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants