Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Binding to channel events cancels calls to onConnectionStateChange etc #7

Closed
gertdrui opened this issue Jan 21, 2021 · 9 comments

Comments

@gertdrui
Copy link

When binding to events on channels I receive no callbacks for onConnectionStateChange. If I don't bind to events I successfully receive callbacks.

It appears each bind adds a new listener to the EventChannel, however on the Android side each new listener replaces the previous PusherService.eventSink, so I assume that is why multiple listeners are not actually working.

@chinloyal
Copy link
Owner

What version of this package are you using?

@gertdrui
Copy link
Author

v1.1.2

@chinloyal
Copy link
Owner

The onConnectionStateChange method gets triggered once you initialize the PusherClient constructor with autoconnect set to true. Or when you call .connect() on an instance of PusherClient. It doesn't get triggered when binding to an event or channel.

@chinloyal
Copy link
Owner

As stated in the readme for this package you can bind to internal pusher events like pusher:subscription_succeeded this lets you know when a subscription to a channel has succeeded. (See under "Binding to events")

@gertdrui
Copy link
Author

gertdrui commented Jan 21, 2021

Logs from the native side indicate that I am connected and I'm receiving events from my subscribed channels, however when I use bind, the onConnectionStateChange callbacks never reach flutter.

Without using bind, I do receive callbacks on onConnectionStateChange.

I'm coming from using pusher_websocket_flutter which uses one receiveBroadcastStream() listener to handle all incoming event types, be it connection state changes or actual channel events.

This plugin looks similar, but the big difference being that each bind also adds a listener to receiveBroadcastStream(), and on the native side this replaces the eventSink, which is ok for pusher_websocket_flutter's single listener, but I'd suspect not for this plugin?

https://github.com/chinloyal/pusher_client/blob/master/android/src/main/kotlin/com/github/chinloyal/pusher_client/pusher/PusherService.kt#L67

@chinloyal
Copy link
Owner

Yes, onConnectionStateChange callbacks are not triggered when you use bind. As stated on the comment for onConnectionStateChange.

  /// Callback that is fired whenever the connection state of the
  /// connection changes. The state typically changes during connection
  /// to Pusher and during disconnection and reconnection.
  void onConnectionStateChange(void Function(ConnectionStateChange state) callback)

So the state will never change on bind

@chinloyal
Copy link
Owner

What exactly are you trying to achieve?

@gertdrui
Copy link
Author

Sorry for the confusion, what I'm trying to communicate is that ConnectionStateChanges like 'CONNECTED', 'DISCONNECTED', 'RECONNECTING' are not reaching flutter, after using bind.

I don't expect connection state changes to be triggered because of bind, but what I'm saying is that normal connection state changes no longer reach flutter after I do.

this works:
pusher.connect();
pusher.onConnectionStateChange((state) { print('state change'); });

this does not, state change will never get called on flutter, but I can see it in native logs:
pusher.connect();
pusher.onConnectionStateChange((state) { print('state change'); });
channel = pusher.subscribe('my-channel');
channel.bind('my-event', (_) {});

@chinloyal
Copy link
Owner

Oh OK I think I get it. I'll try to reproduce and resolve

@chinloyal chinloyal added this to In progress in Pusher Client for Flutter Jan 21, 2021
@chinloyal chinloyal moved this from In progress to Done in Pusher Client for Flutter Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants