Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Nov 22, 2023
1 parent d509d1b commit bafe97e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 16 additions & 8 deletions lib/html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ class HtmlWebSocketChannel extends StreamChannelMixin
/// [BinaryType.blob], they're delivered as [Blob]s instead.
HtmlWebSocketChannel.connect(Object url,
{Iterable<String>? protocols, BinaryType? binaryType})
: this(WebSocket(url.toString(),
(protocols ?? <String>[]).toList().map((e) => e.toJS).toList().toJS)
..binaryType = (binaryType ?? BinaryType.list).value);
: this(
WebSocket(
url.toString(),
(protocols?.toList() ?? const <String>[])
.map((e) => e.toJS)
.toList()
.toJS,
)..binaryType = (binaryType ?? BinaryType.list).value,
);

/// Creates a channel wrapping [innerWebSocket].
HtmlWebSocketChannel(this.innerWebSocket) {
Expand Down Expand Up @@ -124,11 +130,13 @@ class HtmlWebSocketChannel extends StreamChannelMixin
}

void _innerListen(MessageEvent event) {
dynamic data = event.data;

if ((data as JSAny?).typeofEquals('object') &&
(data as JSObject).instanceOfString('ArrayBuffer')) {
data = (data as JSArrayBuffer).toDart.asUint8List();
final eventData = event.data;
Object? data;
if (eventData.typeofEquals('object') &&
(eventData as JSObject).instanceOfString('ArrayBuffer')) {
data = (eventData as JSArrayBuffer).toDart.asUint8List();
} else {
data = event.data;
}
_controller.local.sink.add(data);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/src/web_helpers.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:web/helpers.dart';

// TODO: remove when https://github.com/dart-lang/web/pull/102 is landed
// and the min constraint on pkg:web is updated
// 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 =>
Expand Down

0 comments on commit bafe97e

Please sign in to comment.