The WebSocketTransformer provides the ability to upgrade a HttpRequest to a WebSocket connection. It supports both upgrading a single HttpRequest and upgrading a stream of HttpRequests.
To upgrade a single HttpRequest use the static upgrade method.
HttpServer server;
server.listen((request) {
if (...) {
WebSocketTransformer.upgrade(request).then((websocket) {
...
});
} else {
// Do normal HTTP request processing.
}
});
To transform a stream of HttpRequest events as it implements a stream transformer that transforms a stream of HttpRequest into a stream of WebSockets by upgrading each HttpRequest from the HTTP or HTTPS server, to the WebSocket protocol.
server.transform(new WebSocketTransformer()).listen((webSocket) => ...);
This transformer strives to implement WebSockets as specified by RFC6455.
stream
. [...]
StreamTransformer<RS, RT>
view of this stream transformer. [...]