diff --git a/packages/realtime_client/lib/src/realtime_channel.dart b/packages/realtime_client/lib/src/realtime_channel.dart index 7c37d800..02c7aa86 100644 --- a/packages/realtime_client/lib/src/realtime_channel.dart +++ b/packages/realtime_client/lib/src/realtime_channel.dart @@ -150,9 +150,11 @@ class RealtimeChannel { joinPush.receive( 'ok', - (response) { + (response) async { final serverPostgresFilters = response['postgres_changes']; - if (socket.accessToken != null) socket.setAuth(socket.accessToken); + if (socket.accessToken != null) { + await socket.setAuth(socket.accessToken); + } if (serverPostgresFilters == null) { if (callback != null) { diff --git a/packages/realtime_client/lib/src/realtime_client.dart b/packages/realtime_client/lib/src/realtime_client.dart index ce4904ad..269b046a 100644 --- a/packages/realtime_client/lib/src/realtime_client.dart +++ b/packages/realtime_client/lib/src/realtime_client.dart @@ -467,7 +467,7 @@ class RealtimeClient { if (heartbeatTimer != null) heartbeatTimer!.cancel(); heartbeatTimer = Timer.periodic( Duration(milliseconds: heartbeatIntervalMs), - (Timer t) => sendHeartbeat(), + (Timer t) async => await sendHeartbeat(), ); for (final callback in stateChangeCallbacks['open']!) { callback(); @@ -533,7 +533,7 @@ class RealtimeClient { } @internal - void sendHeartbeat() { + Future sendHeartbeat() async { if (!isConnected) { return; } @@ -555,6 +555,6 @@ class RealtimeClient { payload: {}, ref: pendingHeartbeatRef!, )); - setAuth(accessToken); + await setAuth(accessToken); } } diff --git a/packages/realtime_client/test/socket_test.dart b/packages/realtime_client/test/socket_test.dart index 746c0e86..55c50914 100644 --- a/packages/realtime_client/test/socket_test.dart +++ b/packages/realtime_client/test/socket_test.dart @@ -200,7 +200,7 @@ void main() { await Future.delayed(const Duration(milliseconds: 200)); expect(opens, 1); - socket.sendHeartbeat(); + await socket.sendHeartbeat(); // need to wait for event to trigger await Future.delayed(const Duration(seconds: 1)); expect(lastMsg['event'], 'heartbeat'); @@ -459,7 +459,7 @@ void main() { test( "sets access token, updates channels' join payload, and pushes token to channels", - () { + () async { final mockedChannel1 = MockChannel(); when(() => mockedChannel1.joinedOnce).thenReturn(true); when(() => mockedChannel1.isJoined).thenReturn(true); @@ -484,7 +484,7 @@ void main() { final channel1 = mockedSocket.channel(tTopic1); final channel2 = mockedSocket.channel(tTopic2); - mockedSocket.setAuth(token); + await mockedSocket.setAuth(token); expect(mockedSocket.accessToken, token); @@ -498,7 +498,7 @@ void main() { test( "sets access token, updates channels' join payload, and pushes token to channels if is not a jwt", - () { + () async { final mockedChannel1 = MockChannel(); final mockedChannel2 = MockChannel(); final mockedChannel3 = MockChannel(); @@ -537,7 +537,7 @@ void main() { final pushPayload = {'access_token': token}; final updateJoinPayload = {'access_token': token}; - mockedSocket.setAuth(token); + await mockedSocket.setAuth(token); expect(mockedSocket.accessToken, token); @@ -581,18 +581,18 @@ void main() { //! Unimplemented Test: closes socket when heartbeat is not ack'd within heartbeat window - test('pushes heartbeat data when connected', () { + test('pushes heartbeat data when connected', () async { mockedSocket.connState = SocketStates.open; - mockedSocket.sendHeartbeat(); + await mockedSocket.sendHeartbeat(); verify(() => mockedSink.add(captureAny(that: equals(data)))).called(1); }); - test('no ops when not connected', () { + test('no ops when not connected', () async { mockedSocket.connState = SocketStates.connecting; - mockedSocket.sendHeartbeat(); + await mockedSocket.sendHeartbeat(); verifyNever(() => mockedSink.add(any())); }); });