ws library

WebSockets, served by the same router as HTTP.

import 'package:dust_server/ws.dart';

final app = Router()..route('/chat/{room}', ws(joinRoom));

Future<void> joinRoom(WebSocketSession session) async {
  await for (final message in session.textMessages) {
    session.send(message);
  }
}

Everything here is also exported from package:dust_server/server.dart.

Classes

WebSocketChannel
A StreamChannel that communicates over a WebSocket.
WebSocketClose
Close codes this package uses.
WebSocketSession
One accepted WebSocket connection.

Functions

ws(WebSocketHandler handler, {Iterable<String>? protocols, Duration? pingInterval}) MethodRouter
Serves a WebSocket upgrade at this path.

Typedefs

WebSocketHandler = FutureOr<void> Function(WebSocketSession session)
What a WebSocket route runs once the connection is open.