Skip to content

Commit 09cca34

Browse files
committed
realtime: lower heartbeat interval to 25s
1 parent 6976fae commit 09cca34

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

packages/realtime_client/lib/src/constants.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:realtime_client/src/version.dart';
33
class Constants {
44
static const String vsn = '1.0.0';
55
static const Duration defaultTimeout = Duration(milliseconds: 10000);
6+
static const Duration defaultHeartbeatInterval = Duration(seconds: 25);
67
static const int wsCloseNormal = 1000;
78
static const Map<String, String> defaultHeaders = {
89
'X-Client-Info': 'realtime-dart/$version',

packages/realtime_client/lib/src/realtime_client.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class RealtimeClient {
6565
final WebSocketTransport transport;
6666
final Client? httpClient;
6767
final _log = Logger('supabase.realtime');
68-
int heartbeatIntervalMs = 30000;
68+
final Duration heartbeatInterval;
6969
Timer? heartbeatTimer;
7070

7171
/// reference ID of the most recently sent heartbeat.
@@ -122,7 +122,7 @@ class RealtimeClient {
122122
String endPoint, {
123123
WebSocketTransport? transport,
124124
this.timeout = Constants.defaultTimeout,
125-
this.heartbeatIntervalMs = 30000,
125+
this.heartbeatInterval = Constants.defaultHeartbeatInterval,
126126
this.logger,
127127
RealtimeEncode? encode,
128128
RealtimeDecode? decode,
@@ -145,7 +145,7 @@ class RealtimeClient {
145145
},
146146
transport = transport ?? createWebSocketClient {
147147
_log.config(
148-
'Initialize RealtimeClient with endpoint: $endPoint, timeout: $timeout, heartbeatIntervalMs: $heartbeatIntervalMs, longpollerTimeout: $longpollerTimeout, logLevel: $logLevel');
148+
'Initialize RealtimeClient with endpoint: $endPoint, timeout: $timeout, heartbeatInterval: $heartbeatInterval, longpollerTimeout: $longpollerTimeout, logLevel: $logLevel');
149149
_log.finest('Initialize with headers: $headers, params: $params');
150150
final customJWT = this.headers['Authorization']?.split(' ').last;
151151
accessToken = customJWT ?? params['apikey'];
@@ -467,7 +467,7 @@ class RealtimeClient {
467467
reconnectTimer.reset();
468468
if (heartbeatTimer != null) heartbeatTimer!.cancel();
469469
heartbeatTimer = Timer.periodic(
470-
Duration(milliseconds: heartbeatIntervalMs),
470+
heartbeatInterval,
471471
(Timer t) async => await sendHeartbeat(),
472472
);
473473
for (final callback in stateChangeCallbacks['open']!) {

packages/realtime_client/test/socket_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void main() {
7979
});
8080
expect(socket.timeout, const Duration(milliseconds: 10000));
8181
expect(socket.longpollerTimeout, 20000);
82-
expect(socket.heartbeatIntervalMs, 30000);
82+
expect(socket.heartbeatInterval, Constants.defaultHeartbeatInterval);
8383
expect(
8484
socket.logger is void Function(
8585
String? kind,
@@ -100,7 +100,7 @@ void main() {
100100
'wss://example.com/socket',
101101
timeout: const Duration(milliseconds: 40000),
102102
longpollerTimeout: 50000,
103-
heartbeatIntervalMs: 60000,
103+
heartbeatInterval: const Duration(seconds: 60),
104104
// ignore: avoid_print
105105
logger: (kind, msg, data) => print('[$kind] $msg $data'),
106106
headers: {'X-Client-Info': 'supabase-dart/0.0.0'},
@@ -117,7 +117,7 @@ void main() {
117117
});
118118
expect(socket.timeout, const Duration(milliseconds: 40000));
119119
expect(socket.longpollerTimeout, 50000);
120-
expect(socket.heartbeatIntervalMs, 60000);
120+
expect(socket.heartbeatInterval, const Duration(seconds: 60));
121121
expect(
122122
socket.logger is void Function(
123123
String? kind,

0 commit comments

Comments
 (0)