Clone this repo:
  1. 141f577 Add `pingInterval` pass through param (#16) by Max Wagner · 2 days ago master 0.2.3
  2. 8f2ad43 Merge pull request #15 from send-to-friends/master by Jonas Finnemann Jensen · 8 days ago
  3. 6ae790a Merge pull request #7 from bcko/patch-1 by Jonas Finnemann Jensen · 8 days ago
  4. af1e0aa Allow stream_channel version 2.x (#18) by Nate Bosch · 3 weeks ago 0.2.2+5
  5. 6638980 Callback is with a WebSocketChannel, not CompatibleWebSocket by Zak Cutner · 8 months ago

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