Clone this repo:
  1. 1f15eca blast_repo fixes (#385) by Kevin Moore · 26 hours ago master
  2. 40aa29f Bump actions/checkout from 4.1.7 to 4.2.0 in the github-actions group (#382) by dependabot[bot] · 4 weeks ago
  3. 0e1d6e2 Support latest pkg:web, prepare release (#377) by Kevin Moore · 4 months ago v3.0.1
  4. 8e95ea7 Bump the github-actions group with 2 updates (#376) by dependabot[bot] · 4 months ago
  5. bf69990 bump web_socket dependency 0.1.3 -> 0.1.5 (#370) by Thibault Chatillon · 5 months ago

CI pub package package publisher

package:web_socket_channel provides cross-platform StreamChannel wrappers for WebSocket connections.

Docs and Usage

It provides a cross-platform WebSocketChannel API, a cross-platform implementation of that API that communicates over an underlying StreamChannel, an implementation that wraps dart:io's WebSocket class, and a similar implementation that wraps dart:html's.

It also provides constants for the WebSocket protocol‘s pre-defined status codes in the status.dart library. It’s strongly recommended that users import this library with the prefix status.

import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:web_socket_channel/status.dart' as status;

main() async {
  final wsUrl = Uri.parse('ws://example.com');
  final channel = WebSocketChannel.connect(wsUrl);

  await channel.ready;

  channel.stream.listen((message) {
    channel.sink.add('received!');
    channel.sink.close(status.goingAway);
  });
}

WebSocketChannel

The WebSocketChannel class's most important role is as the interface for WebSocket stream channels across all implementations and all platforms. In addition to the base StreamChannel interface, it adds a protocol getter that returns the negotiated protocol for the socket, as well as closeCode and closeReason getters that provide information about why the socket closed.

The channel‘s sink property is also special. It returns a WebSocketSink, which is just like a StreamSink except that its close() method supports optional closeCode and closeReason parameters. These parameters allow the caller to signal to the other socket exactly why they’re closing the connection.

WebSocketChannel also works as a cross-platform implementation of the WebSocket protocol. The WebSocketChannel.connect constructor connects to a listening server using the appropriate implementation for the platform.