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
- WebSocketLink(String? uri, {ChannelGenerator? channelGenerator, bool autoReconnect = true, Duration reconnectInterval = const Duration(seconds: 10), RequestSerializer serializer = const RequestSerializer(), ResponseParser parser = const ResponseParser(), GraphQLSocketMessageEncoder graphQLSocketMessageEncoder = _defaultGraphQLSocketMessageEncoder, GraphQLSocketMessageDecoder graphQLSocketMessageDecoder = _defaultGraphQLSocketMessageDecoder, dynamic initialPayload, Duration? inactivityTimeout})
-
Initialize the WebSocketLink with a
uri
. You can customize the headers & protocols by passingchannelGenerator
, ifchannelGenerator
is passed,uri
must be null.channelGenerator
is a function that returnsWebSocketChannel
orIOWebSocketChannel
orHtmlWebSocketChannel
. You can also pass customRequestSerializer serializer
&ResponseParser parser
. AlsoinitialPayload
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 theRequestSerializer
. It is recommended for performance to decode the response usingcompute
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 linkinherited -
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