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 46e159e9..1809cd65 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)), ); }