W3cubDocs

/Dart 2

WebSocketTransformer class

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.

Implemented types

Constructors

WebSocketTransformer({dynamic protocolSelector(List<String> protocols), CompressionOptions compression: CompressionOptions.compressionDefault })
factory
Create a new WebSocketTransformer. [...]

Properties

hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

Methods

bind(Stream<HttpRequest> stream) → Stream<WebSocket>
inherited
Transforms the provided stream. [...]
cast<RS, RT>() → StreamTransformer<RS, RT>
inherited
Provides a StreamTransformer<RS, RT> view of this stream transformer. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
Returns a string representation of this object.

Operators

operator ==(dynamic other) → bool
inherited
The equality operator. [...]

Static Methods

isUpgradeRequest(HttpRequest request) → bool
Checks whether the request is a valid WebSocket upgrade request.
upgrade(HttpRequest request, { dynamic protocolSelector(List<String> protocols), CompressionOptions compression: CompressionOptions.compressionDefault }) → 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 process is complete. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-io/WebSocketTransformer-class.html