SocketClient class

Wraps a standard web socket instance to marshal and un-marshal the server / client payloads into dart object representation.

This class also deals with reconnection, handles timeout and keep alive messages.

It is meant to be instantiated once, and you can let this class handle all the heavy- lifting of socket state management. Once you're done with the socket connection, make sure you call the dispose method to release all allocated resources.

Constructors

SocketClient(String url, {String protocol = GraphQLProtocol.graphqlWs, SocketClientConfig config = const SocketClientConfig(), @visibleForTesting Uint8List? randomBytesForUuid, @visibleForTesting void onMessage(GraphQLSocketMessage)?, @visibleForTesting void onStreamError(Object error, StackTrace stackTrace) = _defaultOnStreamError})

Properties

config SocketClientConfig
final
connectionState Stream<SocketConnectionState>
These streams will emit done events when the current socket is done. A stream that emits the last value of the connection state upon subscription.
no setter
hashCode int
The hash code for this object.
no setterinherited
onMessage ↔ void Function(GraphQLSocketMessage)?
getter/setter pair
onStreamError ↔ void Function(Object error, StackTrace stackTrace)
getter/setter pair
parse Response Function(Map<String, dynamic>)
no setter
protocol String
final
randomBytesForUuid Uint8List?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serialize Map<String, dynamic> Function(Request)
no setter
socketChannel GraphQLWebSocketChannel?
getter/setter pair
url String
final

Methods

dispose() Future<void>
Closes the underlying socket if connected, and stops reconnection attempts. After calling this method, this SocketClient instance must be considered unusable. Instead, create a new instance of this class.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onConnectionLost([Object? e]) → void
subscribe(Request payload, bool waitForConnection) Stream<Response>
Sends a query, mutation or subscription request to the server, and returns a stream of the response.
toString() String
A string representation of this object.
inherited

Operators

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