From c1136c766b660df32ea6a4840a405b3d0d40f0d4 Mon Sep 17 00:00:00 2001 From: Aake Christian Gregertsen Date: Thu, 26 May 2022 17:08:37 -0400 Subject: [PATCH 1/2] Fix ping time and handle disconnect when unauthorized --- lib/action_cable.dart | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/action_cable.dart b/lib/action_cable.dart index 5556103..4f93b95 100644 --- a/lib/action_cable.dart +++ b/lib/action_cable.dart @@ -116,7 +116,7 @@ class ActionCable { case 'ping': // rails sends epoch as seconds not miliseconds _lastPing = - DateTime.fromMillisecondsSinceEpoch(payload['message'] * 1000); + DateTime.now(); break; case 'welcome': if (onConnected != null) { @@ -124,10 +124,18 @@ class ActionCable { } break; case 'disconnect': - final channelId = parseChannelId(payload['identifier']); - final onDisconnected = _onChannelDisconnectedCallbacks[channelId]; - if (onDisconnected != null) { - onDisconnected(); + final identifier = payload['identifier']; + if (identifier != null) { + final channelId = parseChannelId(payload['identifier']); + final onDisconnected = _onChannelDisconnectedCallbacks[channelId]; + if (onDisconnected != null) { + onDisconnected(); + } + } else { + final reason = payload['reason']; + if (reason != null && reason == 'unauthorized') { + if (this.onCannotConnect != null) this.onCannotConnect!(); + } } break; case 'confirm_subscription': From 589349a62b389b11547843bf7ae2ddda018ca054 Mon Sep 17 00:00:00 2001 From: Aake Christian Gregertsen Date: Thu, 26 May 2022 17:09:07 -0400 Subject: [PATCH 2/2] update version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 517e7f8..bc270de 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: action_cable -version: 1.2.0 +version: 1.2.1 description: >- ActionCable client port in dart, available in web, dartVM and flutter. homepage: https://github.com/namiwang/actioncable_dart