shelf_web_socket

v3.0.0

A shelf handler that wires up a listener for every connection.

Архив пакета: https://pubdev.letsnova.ru/api/archives/shelf_web_socket/3.0.0.tar.gz

Установкаdart pub add shelf_web_socket

README

pub package package publisher

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';
                
                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}');
                  });
                }
                

История изменений

3.0.0

  • BREAKING:: Change the signature of the webSocketHandler method's onConnection callback. Previously this took an untyped function with either one or two parameters. This now requires a ConnectionCallback; a typedef taking two parameters. See also https://github.com/dart-lang/shelf/issues/457.
  • Add a API usage example.
  • Require Dart ^3.5.0.

Note that most clients seeing analysis issues from the above breaking change can fix it by adding a second parameter to their callback. So, they would change this:

webSocketHandler((webSocket) {
                  webSocket.stream.listen((message) {
                    webSocket.sink.add('echo $message');
                  });
                });
                

to this:

webSocketHandler((webSocket, _) {
                  webSocket.stream.listen((message) {
                    webSocket.sink.add('echo $message');
                  });
                });
                

2.0.1

  • Require Dart ^3.3.0.

2.0.0

  • BREAKING:: Remove support for hijacking WebSocket requests that are not being transported using dart:io Sockets.
  • Require Dart ^3.0.0.

1.0.4

  • Added package topics to the pubspec file.

1.0.3

  • Require Dart 2.17.
  • Fix checking for binary callbacks with strong null safety.

1.0.2

  • Require Dart 2.14.
  • Update the pubspec repository field.

1.0.1

  • Require the latest shelf, remove dead code.

1.0.0

  • Migrate to null safety.

0.2.4+1

  • Support the latest package:web_socket_channel.

0.2.4

  • Support the latest shelf release (1.x.x).
  • Require at least Dart 2.1
  • Allow omitting protocols argument even if the onConnection callback takes a second argument.

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.