Skip to content

Commit

Permalink
Merge pull request #1374 from Rochak69/main
Browse files Browse the repository at this point in the history
Send payload in PingMessage
  • Loading branch information
vincenzopalazzo authored Aug 31, 2023
2 parents 8c9cc86 + 19d5c86 commit 060fb63
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/graphql/lib/src/links/websocket_link/websocket_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ enum SocketConnectionState { notConnected, handshake, connecting, connected }
enum ToggleConnectionState { disconnect, connect }

class SocketClientConfig {
const SocketClientConfig({
this.serializer = const RequestSerializer(),
this.parser = const ResponseParser(),
this.autoReconnect = true,
this.queryAndMutationTimeout = const Duration(seconds: 10),
this.inactivityTimeout = const Duration(seconds: 30),
this.delayBetweenReconnectionAttempts = const Duration(seconds: 5),
this.initialPayload,
this.headers,
this.connectFn,
this.onConnectionLost,
this.toggleConnection,
});
const SocketClientConfig(
{this.serializer = const RequestSerializer(),
this.parser = const ResponseParser(),
this.autoReconnect = true,
this.queryAndMutationTimeout = const Duration(seconds: 10),
this.inactivityTimeout = const Duration(seconds: 30),
this.delayBetweenReconnectionAttempts = const Duration(seconds: 5),
this.initialPayload,
this.headers,
this.connectFn,
this.onConnectionLost,
this.toggleConnection,
this.pingMessage = const <String, dynamic>{}});

/// Serializer used to serialize request
final RequestSerializer serializer;
Expand All @@ -76,6 +76,9 @@ class SocketClientConfig {
/// If null, the reconnection will occur immediately, although not recommended.
final Duration? delayBetweenReconnectionAttempts;

// The payload to send the send while pinging. If null payload while ping the server will be empty.
final Map<String, dynamic> pingMessage;

/// The duration after which a query or mutation should time out.
/// If null, no timeout is applied, although not recommended.
final Duration? queryAndMutationTimeout;
Expand Down Expand Up @@ -413,7 +416,7 @@ class SocketClient {
_pingTimer?.cancel();
_pingTimer = new Timer(
config.inactivityTimeout!,
() => _write(PingMessage()),
() => _write(PingMessage(config.pingMessage)),
);
}

Expand Down

0 comments on commit 060fb63

Please # to comment.