Skip to content

Commit

Permalink
added pingInterval to config & new version
Browse files Browse the repository at this point in the history
  • Loading branch information
KammererTob committed Dec 28, 2024
1 parent bb46f62 commit df4c5de
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> | Optional header values which will be used on the STOMP connect frame |
| webSocketConnectHeaders: Map<String, dynamic>| Optional header values which will be used when connecting to the underlying WebSocket [(not supported in Web)](#token-authentication-browser-based-clients) |
Expand Down
11 changes: 8 additions & 3 deletions lib/src/connect_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import 'stomp_config.dart';

Future<WebSocketChannel> 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);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/src/stomp_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dependencies:

dev_dependencies:
test: ^1.25.8
lints: ^4.0.0
lints: ^5.0.0
stream_channel: ^2.1.2

0 comments on commit df4c5de

Please sign in to comment.