Skip to content

Commit 19d5c86

Browse files
Rochak69vincenzopalazzo
authored andcommitted
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.
1 parent e1c6d54 commit 19d5c86

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

packages/graphql/lib/src/links/websocket_link/websocket_client.dart

+17-14
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ enum SocketConnectionState { notConnected, handshake, connecting, connected }
4040
enum ToggleConnectionState { disconnect, connect }
4141

4242
class SocketClientConfig {
43-
const SocketClientConfig({
44-
this.serializer = const RequestSerializer(),
45-
this.parser = const ResponseParser(),
46-
this.autoReconnect = true,
47-
this.queryAndMutationTimeout = const Duration(seconds: 10),
48-
this.inactivityTimeout = const Duration(seconds: 30),
49-
this.delayBetweenReconnectionAttempts = const Duration(seconds: 5),
50-
this.initialPayload,
51-
this.headers,
52-
this.connectFn,
53-
this.onConnectionLost,
54-
this.toggleConnection,
55-
});
43+
const SocketClientConfig(
44+
{this.serializer = const RequestSerializer(),
45+
this.parser = const ResponseParser(),
46+
this.autoReconnect = true,
47+
this.queryAndMutationTimeout = const Duration(seconds: 10),
48+
this.inactivityTimeout = const Duration(seconds: 30),
49+
this.delayBetweenReconnectionAttempts = const Duration(seconds: 5),
50+
this.initialPayload,
51+
this.headers,
52+
this.connectFn,
53+
this.onConnectionLost,
54+
this.toggleConnection,
55+
this.pingMessage = const <String, dynamic>{}});
5656

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

79+
// The payload to send the send while pinging. If null payload while ping the server will be empty.
80+
final Map<String, dynamic> pingMessage;
81+
7982
/// The duration after which a query or mutation should time out.
8083
/// If null, no timeout is applied, although not recommended.
8184
final Duration? queryAndMutationTimeout;
@@ -413,7 +416,7 @@ class SocketClient {
413416
_pingTimer?.cancel();
414417
_pingTimer = new Timer(
415418
config.inactivityTimeout!,
416-
() => _write(PingMessage()),
419+
() => _write(PingMessage(config.pingMessage)),
417420
);
418421
}
419422

0 commit comments

Comments
 (0)