shelf_web_socket 0.2.3

Web Socket Handler for Shelf #

shelf_web_socket is a Shelf handler for establishing WebSocket connections. It exposes a single function, webSocketHandler, which calls an onConnection callback with a WebSocketChannel object for every connection that's established.

import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_web_socket/shelf_web_socket.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() {
  var handler = webSocketHandler((webSocket) {
    webSocket.stream.listen((message) {
      webSocket.sink.add("echo $message");
    });
  });

  shelf_io.serve(handler, 'localhost', 8080).then((server) {
    print('Serving at ws://${server.address.host}:${server.port}');
  });
}

0.2.3 #

  • Add pingInterval argument to webSocketHandler, to be passed through to the created channel.

0.2.2+5 #

  • Allow stream_channel version 2.x

0.2.2+4 #

  • Fix the check for onConnection to check the number of arguments and not that the arguments are dynamic.

0.2.2+3 #

  • Set max SDK version to <3.0.0, and adjust other dependencies.

0.2.2+2 #

  • Stopped using deprected HTML_ESCAPE constant name.

0.2.2+1 #

  • Update SDK version to 2.0.0-dev.17.0.

0.2.2 #

  • Stop using comment-based generic syntax.

0.2.1 #

  • Fix all strong-mode warnings.

0.2.0 #

  • Breaking change: webSocketHandler() now uses the WebSocketChannel class defined in the web_socket_channel package, rather than the deprecated class defined in http_parser.

0.1.0 #

  • Breaking change: webSocketHandler() now passes a WebSocketChannel to the onConnection() callback, rather than a deprecated CompatibleWebSocket.

0.0.1+5 #

  • Support http_parser 2.0.0.

0.0.1+4 #

  • Fix a link to shelf in the README.

0.0.1+3 #

  • Support http_parser 1.0.0.

0.0.1+2 #

  • Mark as compatible with version 0.6.0 of shelf.

0.0.1+1 #

  • Properly parse the Connection header. This fixes an issue where Firefox was unable to connect.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  shelf_web_socket: ^0.2.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:shelf_web_socket/shelf_web_socket.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
96
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
96
Learn more about scoring.

We analyzed this package on Sep 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:shelf_web_socket/shelf_web_socket.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and shelf_web_socket.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
shelf ^0.7.0 0.7.5
stream_channel >1.4.0 <3.0.0 2.0.0
web_socket_channel ^1.0.0 1.0.15
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
http_parser 3.1.3
meta 1.1.7
path 1.6.4
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
http >=0.10.0 <0.12.0
test ^1.0.0