pub repository
mirror.p-hatan.irweb_socket_channel
1.0.3StreamChannel wrappers for WebSockets.
Readme
The web_socket_channel package provides StreamChannel
wrappers for WebSocket connections. 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 wrap's
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 should be imported with the prefix status.
import 'package:web_socket_channel/io.dart';
import 'package:web_socket_channel/status.dart' as status;
main() async {
var channel = await IOWebSocketChannel.connect("ws://localhost:1234");
channel.stream.listen((message) {
channel.sink.add("received!");
channel.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. Because it can't initiate or handle HTTP requests in a
cross-platform way, the new WebSocketChannel() constructor takes an
underlying StreamChannel over which it communicates using
the WebSocket protocol. It also provides the static signKey()
method to make it easier to implement the initial WebSocket handshake. These
are used in the shelf_web_socket package to support
WebSockets in a cross-platform way.
IOWebSocketChannel
The IOWebSocketChannel class wraps
dart:io's WebSocket class. Because it imports dart:io, it
has its own library, package:web_socket_channel/io.dart. This allows the main
WebSocketChannel class to be available on all platforms.
An IOWebSocketChannel can be created by passing a dart:io WebSocket to
its constructor. It's more common to want to connect
directly to a ws:// or wss:// URL, in which case
new IOWebSocketChannel.connect() should be used.
import 'package:web_socket_channel/io.dart';
main() async {
var channel = new IOWebSocketChannel.connect("ws://localhost:8181");
channel.sink.add("connected!");
channel.sink.listen((message) {
// ...
});
}
HtmlWebSocketChannel
The HtmlWebSocketChannel class wraps
dart:html's WebSocket class. Because it imports
dart:html, it has its own library, package:web_socket_channel/html.dart.
This allows the main WebSocketChannel class to be available on all platforms.
An HtmlWebSocketChannel can be created by passing a dart:html WebSocket to
its constructor. It's more common to want to connect
directly to a ws:// or wss:// URL, in which case
new HtmlWebSocketChannel.connect() should be used.
import 'package:web_socket_channel/html.dart';
main() async {
var channel = new HtmlWebSocketChannel.connect("ws://localhost:8181");
channel.sink.add("connected!");
channel.sink.listen((message) {
// ...
});
}
Changelog
1.0.3
-
Fix all strong-mode errors and warnings.
-
Fix a bug where
HtmlWebSocketChannel.close()would crash on non-Dartium browsers if the close code and reason weren't provided explicitly.
1.0.2
- Properly use
BASE64fromdart:convertrather thancrypto.
1.0.1
- Add support for
crypto1.0.0.
1.0.0
- Initial version
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add web_socket_channelpubspec.yaml
name: web_socket_channel
version: 1.0.3
description: StreamChannel wrappers for WebSockets.
author: Dart Team <misc@dartlang.org>
homepage: https://github.com/dart-lang/web_socket_channel
environment:
sdk: '>=1.13.0 <2.0.0'
dependencies:
async: '^1.3.0'
crypto: '>=0.9.2 <2.0.0'
stream_channel: '^1.2.0'
dev_dependencies:
test: '^0.12.0'
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 1.0.0 | 2016-03-03T00:17:36.221Z | Download | 844befad15d7b044ea91650c379a14c371d1b157225b3df932dc48ef876118fb |
| 1.0.1 | 2016-03-23T20:53:10.407Z | Download | cfba8c5cf97356cc91566927c6dd03ea59e16ec4700d5ec75a57bbf5dd83a2c6 |
| 1.0.2 | 2016-03-28T23:34:05.551Z | Download | c503cef80496d841ceadc8f6672f336b78e0193b8242037f3280407a50139b00 |
| 1.0.3 | 2016-05-09T19:10:53.971Z | Download | cff6e547911ff0058bf199430d471c463f71e21b262ef7b9e5eb2e2fda854371 |
| 1.0.4 | 2016-06-06T19:51:42.149Z | Download | 4b27d9c641cc0e0dd527443d5899d0588c57d83615dc8b56a86653b784667c0c |
| 1.0.5 | 2017-08-04T17:30:37.885906Z | Download | adb6bb7e815e2a71a54209e4b2b507c80860596d90c5fb62e67a5967952c5b8a |
| 1.0.6-dev | 2017-09-22T20:54:29.363492Z | Download | 66c36a902b43d831197691173553c0e48d20a764edb42c4827d6115c4a24f79c |
| 1.0.6 | 2017-09-22T20:55:13.724630Z | Download | 46fdd71f5ca77db9ee176c6de0f46b83ade12f5617f8ff0952f1c187c974f3c5 |
| 1.0.7 | 2018-02-10T01:21:22.296182Z | Download | 5a63697aec7183ce2498a27cc2f5c3e4bdfb9af1f7f3e5996515b999f2adc456 |
| 1.0.8 | 2018-06-01T17:16:52.738535Z | Download | e277cf08f2b16cf6abaf033a433825176dca8dfeebae3c3d758cb745a91d777e |
| 1.0.9 | 2018-07-17T19:52:49.447480Z | Download | e2624a64def8e0a810eae819e53dfbee858eb06db46a78a3c25a6752f65b11b2 |
| 1.0.10 | 2019-03-26T16:39:58.842972Z | Download | 15b642a3a470f6c8cc3bbc0173d2aa0abd8409e2e89ef23e6a86ae935b358dd7 |
| 1.0.11 | 2019-03-26T16:48:01.083518Z | Download | 7c7b33eb6ce4a812655aab4ed6a09f018a0de3fe8d5662ad04dd594d7520d142 |
| 1.0.12 | 2019-03-27T19:31:57.620882Z | Download | e65803d473090c101b37717824cde4900b74f56cc0c6532b4a9321dfcc51a4d0 |
| 1.0.13 | 2019-05-22T21:09:29.301335Z | Download | 30a31845149e1ab383c7ce97fcbf9dee6d568bdd6802819756860aa95526acc1 |
| 1.0.14 | 2019-07-09T22:22:25.726457Z | Download | 6dd76d3bf6014571db39dd86e8b5cc3a46206b37e672b842cec520488217834a |
| 1.0.15 | 2019-08-08T20:36:59.807877Z | Download | 06ef56a7ea82b1bbcd07ace05032fbcb7790bdb07129dc78e78b6cc35857093b |
| 1.1.0 | 2019-10-11T20:56:06.320836Z | Download | 7712c6d1d3f1ad9b7f6da95c3898fd39c60592307475bef76f10ab388ec258de |
| 1.2.0 | 2021-01-20T18:49:20.674197Z | Download | bfd93faab893a64920903d7d375517c18789c21e4c7daa5232a31ee126b7fea1 |
| 2.0.0 | 2021-02-19T00:22:50.054154Z | Download | 500e6014efebd305a30ebf1c6006d13faa82dcd85c7a2a7793679a64ed69ec48 |
| 2.1.0 | 2021-05-03T19:11:47.229047Z | Download | 0c2ada1b1aeb2ad031ca81872add6be049b8cb479262c6ad3c4b0f9c24eaab2f |
| 2.2.0 | 2022-04-26T22:14:20.448675Z | Download | 3a969ddcc204a3e34e863d204b29c0752716f78b6f9cc8235083208d268a4ccd |
| 2.3.0 | 2023-01-11T17:44:33.095346Z | Download | ca49c0bc209c687b887f30527fb6a9d80040b072cc2990f34b9bec3e7663101b |
| 2.4.0 | 2023-04-11T18:44:56.573941Z | Download | d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b |
| 2.4.1 | 2023-12-18T23:45:07.031257Z | Download | 045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b |
| 2.4.2 | 2024-01-04T17:41:56.822434Z | Download | cc1f6c632a248278a091fd7d9a68f624906830f7c1c5aa66503fae0804633e1c |
| 2.4.3 | 2024-01-08T18:08:15.299567Z | Download | 939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23 |
| 2.4.4 | 2024-02-15T23:23:41.062272Z | Download | 1d8e795e2a8b3730c41b8a98a2dff2e0fb57ae6f0764a1c46ec5915387d257b2 |
| 2.4.5 | 2024-04-08T17:46:53.652270Z | Download | 58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42 |
| 3.0.0 | 2024-05-06T20:04:37.033898Z | Download | a2d56211ee4d35d9b344d9d4ce60f362e4f5d1aafb988302906bd732bc731276 |
| 3.0.1 | 2024-07-16T19:36:02.873491Z | Download | 9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f |
| 3.0.2 | 2025-01-22T15:53:39.722866Z | Download | 0b8e2457400d8a859b7b2030786835a28a8e80836ef64402abef392ff4f1d0e5 |
| 3.0.3 | 2025-04-17T20:42:13.656396Z | Download | d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 |
Dependencies
async "^1.3.0"
crypto "\u003e=0.9.2 \u003c2.0.0"
stream_channel "^1.2.0"