WebSocketLink class

A Universal WebSocket Link implementation to support the WebSocket-GraphQL transport. It supports subscriptions, query and mutation operations as well.

NOTE: the actual socket connection will only get established after a Request is handled by this WebSocketLink.

Constructors

Initialize the WebSocketLink with a uri. You can customize the headers & protocols by passing channelGenerator, if channelGenerator is passed, uri must be null. channelGenerator is a function that returns WebSocketChannel or IOWebSocketChannel or HtmlWebSocketChannel. You can also pass custom RequestSerializer serializer & ResponseParser parser. Also initialPayload to be passed with the first request to the GraphQL server.

Properties

autoReconnect bool
Automatically recreate the channel when connection is lost, and re send all active subscriptions. true by default.
getter/setter pair
connectionStateStream Stream<ConnectionState>
A stream that notifies about changes of the current connection state.
no setter
graphQLSocketMessageDecoder GraphQLSocketMessageDecoder
A function that decodes the incoming http response to Map<String, dynamic>, the decoded map will be then passes to the RequestSerializer. It is recommended for performance to decode the response using compute function.
final
graphQLSocketMessageEncoder GraphQLSocketMessageEncoder
A function that encodes the request message to json string before sending it over the network.
final
hashCode int
The hash code for this object.
no setterinherited
inactivityTimeout Duration?
The duration after which the connection is considered unstable, because no keep alive message was received from the server in the given time-frame. The connection to the server will be closed. If the value is null this is ignored, By default this is null.
final
initialPayload → dynamic
Payload to be sent with the connection_init request Must be able to json.encode(initialPayload).
final
isDisabled bool
true when the WebSocketLink can't send any more messages. This happends after calling dispose or when autoReconnect is false and the web socket disconnected.
no setter
parser ↔ ResponseParser
Response parser
getter/setter pair
reconnectInterval Duration
The interval between reconnects, the default value is 10 seconds.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serializer → RequestSerializer
Serializer used to serialize request
final

Methods

concat(Link next) → Link
Adds next after this link
inherited
dispose() Future<void>
Disposes the underlying channel explicitly. Only use this, if you want to disconnect from the current server in favour of another one. If that's the case, create a new WebSocketLink instance.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
request(Request request, [NextLink? forward]) Stream<Response>
A function called when a request reaches this Link
route(LinkRouter route) → Link
Route requests after this link
inherited
split(bool test(Request request), Link left, [Link right = const PassthroughLink()]) → Link
Split requests after this link
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited