From df4c5de7caecd0adbbc6ac077111630df3a36388 Mon Sep 17 00:00:00 2001 From: Tobias Kammerer Date: Sat, 28 Dec 2024 23:54:31 +0100 Subject: [PATCH] added pingInterval to config & new version --- CHANGELOG.md | 3 +++ README.md | 1 + lib/src/connect_io.dart | 11 ++++++++--- lib/src/stomp_config.dart | 5 +++++ pubspec.yaml | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f76d435..8c5cbce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.1.1 + - Added `pingInterval` to `StompConfig` to control the ping interval of IO WebSockets. Thanks @AndruhovSasha + ## 2.1.0 - Updated version of `web_socket_channel` dependency to 3.0.1 - Moved from `dart:html` to `package:web` for [web interop](https://dart.dev/interop/js-interop/package-web#migrating-from-dart-html) diff --git a/README.md b/README.md index a64953a..c307f37 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ This table shows all available options in `StompConfig` | reconnectDelay: Duration | Time duration between reconnect attempts. Set to 0 ms if you don't want to reconnect automatically. The default value is 5 seconds | | heartbeatOutgoing: Duration | Time duration between outgoing heartbeat messages. Set to 0 ms to not send any heartbeats. The default value is 5 seconds | | heartbeatIncoming: Duration | Time duration between incoming heartbeat messages. Set to 0 ms to not receive any heartbeats. The default value is 5 seconds | +| pingInterval: Duration | Time duration between ping messages being sent on the underlying WebSocket. (Not supported in Web) | | connectionTimeout: Duration | Time duration it waits until a connection attempt is aborted. Set to 0 ms to not set a timeout. The default value is 0 ms | | stompConnectHeaders: Map | Optional header values which will be used on the STOMP connect frame | | webSocketConnectHeaders: Map| Optional header values which will be used when connecting to the underlying WebSocket [(not supported in Web)](#token-authentication-browser-based-clients) | diff --git a/lib/src/connect_io.dart b/lib/src/connect_io.dart index 719610d..394ef59 100644 --- a/lib/src/connect_io.dart +++ b/lib/src/connect_io.dart @@ -8,14 +8,19 @@ import 'stomp_config.dart'; Future connect(StompConfig config) async { try { - var webSocket = WebSocket.connect( + var webSocketFuture = WebSocket.connect( config.connectUrl, headers: config.webSocketConnectHeaders, ); if (config.connectionTimeout.inMilliseconds > 0) { - webSocket = webSocket.timeout(config.connectionTimeout); + webSocketFuture = webSocketFuture.timeout(config.connectionTimeout); } - return IOWebSocketChannel(await webSocket); + + var webSocket = await webSocketFuture; + + webSocket.pingInterval = config.pingInterval; + + return IOWebSocketChannel(webSocket); } on SocketException catch (err) { throw WebSocketChannelException.from(err); } diff --git a/lib/src/stomp_config.dart b/lib/src/stomp_config.dart index c6f64bd..e7b99f0 100644 --- a/lib/src/stomp_config.dart +++ b/lib/src/stomp_config.dart @@ -29,6 +29,9 @@ class StompConfig { /// Set to a duration with 0 milliseconds to not receive any heartbeats final Duration heartbeatIncoming; + /// Time between sent pings on the underlying WebSocket (unsupported in HTML) + final Duration? pingInterval; + /// Connection timeout. If specified the connection will be dropped after /// the timeout and depending on the [reconnectDelay] it will try again final Duration connectionTimeout; @@ -84,6 +87,7 @@ class StompConfig { this.connectionTimeout = Duration.zero, this.stompConnectHeaders, this.webSocketConnectHeaders, + this.pingInterval, this.beforeConnect = _noOpFuture, this.onConnect = _noOp, this.onStompError = _noOp, @@ -105,6 +109,7 @@ class StompConfig { this.connectionTimeout = Duration.zero, this.stompConnectHeaders, this.webSocketConnectHeaders, + this.pingInterval, this.beforeConnect = _noOpFuture, this.onConnect = _noOp, this.onStompError = _noOp, diff --git a/pubspec.yaml b/pubspec.yaml index de37f5a..d4bd0fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,5 +11,5 @@ dependencies: dev_dependencies: test: ^1.25.8 - lints: ^4.0.0 + lints: ^5.0.0 stream_channel: ^2.1.2