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.

Implements

Static Methods

isUpgradeRequest(HttpRequest request) bool

Checks whether the request is a valid WebSocket upgrade request.

upgrade(HttpRequest request, {dynamic protocolSelector(List<String> protocols)}) Future<WebSocket>

Upgrades a HttpRequest to a WebSocket connection. If the request is not a valid WebSocket upgrade request an HTTP response with status code 500 will be returned. Otherwise the returned future will complete with the WebSocket when the upgrade pocess is complete.

Constructors

WebSocketTransformer({dynamic protocolSelector(List<String> protocols)})

Create a new WebSocketTransformer.

factory

Properties

hashCode int

Get a hash code for this object.

read-only, inherited
runtimeType Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) bool

The equality operator.

inherited

Methods

bind(Stream<HttpRequest> stream) Stream<WebSocket>

Transform the incoming stream's events.

inherited
noSuchMethod(Invocation invocation) → dynamic

noSuchMethod is invoked when users invoke a non-existent method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

inherited
toString() String

Returns a string representation of this object.

inherited