From 19d5c86b98e889b333996da43126f9404a9a4556 Mon Sep 17 00:00:00 2001 From: Rochak69 Date: Wed, 30 Aug 2023 13:00:06 +0545 Subject: [PATCH] feat(graphql): Send custom payload in PingMessage I am using it to send information about the workspaces I want to stay online for because there are multiple workspaces. --- .../websocket_link/websocket_client.dart | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart index 4634b5d2..85cce552 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -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 {}}); /// Serializer used to serialize request final RequestSerializer serializer; @@ -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 pingMessage; + /// The duration after which a query or mutation should time out. /// If null, no timeout is applied, although not recommended. final Duration? queryAndMutationTimeout; @@ -413,7 +416,7 @@ class SocketClient { _pingTimer?.cancel(); _pingTimer = new Timer( config.inactivityTimeout!, - () => _write(PingMessage()), + () => _write(PingMessage(config.pingMessage)), ); }