From 68a9f0afe08af157c38698b8540833fa3497889b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Fri, 8 Dec 2023 16:07:12 +0530 Subject: [PATCH] Refactored attach channels with right spec --- .../io/ably/lib/realtime/AblyRealtime.java | 19 ++++++++++--------- .../java/io/ably/lib/realtime/Connection.java | 3 +++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java b/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java index 2f139a3c5..a0758c7da 100644 --- a/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java +++ b/lib/src/main/java/io/ably/lib/realtime/AblyRealtime.java @@ -284,6 +284,16 @@ private void clear() { } } + // RTN19b + protected void reattachChannels() { + for (Channel channel : this.channels.values()) { + if (channel.state == ChannelState.attaching || channel.state == ChannelState.attached || channel.state == ChannelState.suspended) { + Log.d(TAG, "reAttach(); channel = " + channel.name); + channel.attach(true, null); + } + } + } + protected void setChannelSerialsFromRecoverOption(Map serials) { for (Map.Entry entry : serials.entrySet()) { String channelName = entry.getKey(); @@ -295,15 +305,6 @@ protected void setChannelSerialsFromRecoverOption(Map serials) { } } - protected void reattachChannels() { - for (Channel channel : this.channels.values()) { - if (channel.state == ChannelState.attaching || channel.state == ChannelState.attached || channel.state == ChannelState.suspended) { - Log.d(TAG, "reAttach(); channel = " + channel.name); - channel.attach(true, null); - } - } - } - protected Map getChannelSerials() { Map channelSerials = new HashMap<>(); for (Channel channel : this.channels.values()) { diff --git a/lib/src/main/java/io/ably/lib/realtime/Connection.java b/lib/src/main/java/io/ably/lib/realtime/Connection.java index 443aef04f..dd5b8b0a6 100644 --- a/lib/src/main/java/io/ably/lib/realtime/Connection.java +++ b/lib/src/main/java/io/ably/lib/realtime/Connection.java @@ -130,6 +130,9 @@ public void close() { public void onConnectionStateChange(ConnectionStateChange stateChange) { state = stateChange.current; reason = stateChange.reason; + if (state == ConnectionState.connected) { // RTN19b + ably.reattachChannels(); + } emit(state, stateChange); }