Skip to content

Commit

Permalink
Merge pull request #1 from Rochak69/feature/custom-ping-message
Browse files Browse the repository at this point in the history
Send custom payload in PingMessage
  • Loading branch information
Rochak69 authored Aug 30, 2023
2 parents d41edf5 + 46780f5 commit 28754d9
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 28754d9

Please sign in to comment.