TransportWsClientOptions class

Configuration used for the GraphQL over WebSocket client.

@category Client

Constructors

TransportWsClientOptions({required WebSocketMaker socketMaker, FutureOr<Map<String, Object?>?> connectionParams()?, bool lazy = true, void onNonLazyError(Object? errorOrCloseEvent)? = print, Duration lazyCloseTimeout = Duration.zero, Duration keepAlive = Duration.zero, Duration connectionAckWaitTimeout = Duration.zero, bool disablePong = false, int retryAttempts = 0, Future<void> retryWait(int retries) = randomizedExponentialBackoff, bool shouldRetry(Object errOrCloseEvent) = shouldRetryDefault, bool isFatalConnectionProblem(Object errOrCloseEvent) = isFatalConnectionProblemDefault, List<TransportWsEventHandler>? eventHandlers, String generateID() = generateUUID, RequestSerializer serializer = const RequestSerializer(), ResponseParser parser = const ResponseParser(), FutureOr<Object> graphQLSocketMessageEncoder(TransportWsMessage message) = defaultGraphQLSocketMessageEncoder, GraphQLSocketMessageDecoder graphQLSocketMessageDecoder = defaultGraphQLSocketMessageDecoder, void log(String logMessage)?})
Options for a TransportWsClient instance.
const

Properties

connectionAckWaitTimeout Duration
The amount of time for which the client will wait for ConnectionAck message.
final
connectionParams → (FutureOr<Map<String, Object?>?> Function()?)
Optional parameters, passed through the payload field with the ConnectionInit message, that the client specifies when establishing a connection with the server. You can use this for securely passing arguments for authentication.
final
disablePong bool
Disable sending the PongMessage automatically.
final
eventHandlers List<TransportWsEventHandler>?
Register listeners before initialising the client. This way you can ensure to catch all client relevant emitted events.
final
generateID String Function()
A custom WebSocket implementation to use instead of the one provided by the global scope. Mostly useful for when using the client outside of the browser environment. A custom ID generator for identifying subscriptions.
final
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 FutureOr<Object> Function(TransportWsMessage message)
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
isFatalConnectionProblem bool Function(Object errOrCloseEvent)
Check if the close event or connection error is fatal. If you return true, the client will fail immediately without additional retries; however, if you return false, the client will keep retrying until the retryAttempts have been exceeded.
final
keepAlive Duration
The timout between dispatched keep-alive messages, naimly server pings. Internally dispatches the PingMessage type to the server and expects a PongMessage in response. This helps with making sure that the connection with the server is alive and working.
final
lazy bool
Controls when should the connection be established.
final
lazyCloseTimeout Duration
How long should the client wait before closing the socket after the last oparation has completed. This is meant to be used in combination with lazy. You might want to have a calmdown time before actually closing the connection. Kinda' like a lazy close "debounce".
final
log → (void Function(String logMessage)?)
A function that logs events within the execution of the TransportWsClient. Useful for debugging.
final
onNonLazyError → (void Function(Object? errorOrCloseEvent)?)
Used ONLY when the client is in non-lazy mode (lazy = false). When using this mode, the errors might have no sinks to report to; however, to avoid swallowing errors, consider using onNonLazyError, which will be called when either:
final
parser → ResponseParser
Parses Responses from the Web Socket message.
final
retryAttempts int
How many times should the client try to reconnect on abnormal socket closure before it errors out?
final
retryWait Future<void> Function(int retries)
Control the wait time between retries. You may implement your own strategy by timing the resolution of the returned promise with the retries count. retries argument counts actual connection attempts, so it will begin with 0 after the first retryable disconnect.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
serializer → RequestSerializer
Serializer used to serialize Requests.
final
shouldRetry bool Function(Object errOrCloseEvent)
Check if the close event or connection error is fatal. If you return false, the client will fail immediately without additional retries; however, if you return true, the client will keep retrying until the retryAttempts have been exceeded. The argument is whatever has been thrown during the connection phase. Beware, the library classifies a few close events as fatal regardless of what is returned here. They are listed in the documentation of the retryAttempts option. @default shouldRetryDefault
final
socketMaker WebSocketMaker
URL of the GraphQL over WebSocket Protocol compliant server to connect.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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

Static Methods

defaultGraphQLSocketMessageDecoder(dynamic message) Map<String, dynamic>?
The default graphQLSocketMessageDecoder that decodes the request message from a json string.
defaultGraphQLSocketMessageEncoder(TransportWsMessage message) String
The default graphQLSocketMessageEncoder that encodes the request message to json string.
generateUUID() String
Generates a v4 UUID to be used as the ID using Math as the random number generator. Supply your own generator in case you need more uniqueness.
isFatalConnectionProblemDefault(Object errOrCloseEvent) bool
non CloseEvents are fatal by default
randomizedExponentialBackoff(int retries) Future<void>
Start with 1s delay and adds random timeout from 300ms to 3s
shouldRetryDefault(Object errOrCloseEvent) bool
By default, connection should not retry on fatal errors