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

Rename helper extensions to not collide with pkg:web unreleased #303

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class HtmlWebSocketChannel extends StreamChannelMixin
}
// The socket API guarantees that only a single open event will be
// emitted.
innerWebSocket.onOpen.first.then((_) {
innerWebSocket.onOpenX.first.then((_) {
_readyCompleter.complete();
_listen();
});
}

// The socket API guarantees that only a single error event will be emitted,
// and that once it is no open or message events will be emitted.
innerWebSocket.onError.first.then((_) {
innerWebSocket.onErrorX.first.then((_) {
// Unfortunately, the underlying WebSocket API doesn't expose any
// specific information about the error itself.
final error = WebSocketChannelException('WebSocket connection failed.');
Expand All @@ -115,11 +115,11 @@ class HtmlWebSocketChannel extends StreamChannelMixin
_controller.local.sink.close();
});

innerWebSocket.onMessage.listen(_innerListen);
innerWebSocket.onMessageX.listen(_innerListen);

// The socket API guarantees that only a single error event will be emitted,
// and that once it is no other events will be emitted.
innerWebSocket.onClose.first.then((event) {
innerWebSocket.onCloseX.first.then((event) {
_closeCode = event.code;
_closeReason = event.reason;
_controller.local.sink.close();
Expand Down
8 changes: 4 additions & 4 deletions lib/src/web_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import 'package:web/helpers.dart';
// TODO(kevmoo): remove when https://github.com/dart-lang/web/commit/4cb5811ed06
// is in a published release and the min constraint on pkg:web is updated
extension WebSocketEvents on WebSocket {
Stream<Event> get onOpen => EventStreamProviders.openEvent.forTarget(this);
Stream<MessageEvent> get onMessage =>
Stream<Event> get onOpenX => EventStreamProviders.openEvent.forTarget(this);
Stream<MessageEvent> get onMessageX =>
EventStreamProviders.messageEvent.forTarget(this);
Stream<CloseEvent> get onClose =>
Stream<CloseEvent> get onCloseX =>
EventStreamProviders.closeEvent.forTarget(this);
Stream<Event> get onError =>
Stream<Event> get onErrorX =>
EventStreamProviders.errorEventSourceEvent.forTarget(this);
}
2 changes: 1 addition & 1 deletion test/html_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void main() {

test('communicates using an existing open WebSocket', () async {
final webSocket = WebSocket('ws://localhost:$port');
await webSocket.onOpen.first;
await webSocket.onOpenX.first;

final channel = HtmlWebSocketChannel(webSocket);

Expand Down