pusher-channels-flutter icon indicating copy to clipboard operation
pusher-channels-flutter copied to clipboard

PusherChannelsFlutter, Pusher Channels already initialized

Open DevTiago opened this issue 3 years ago • 9 comments

I'm using this package for the first time... and when i try to init inside a try/catch block i receive this error:

I/flutter ( 7005): PlatformException(PusherChannelsFlutter, Pusher Channels already initialized., null, null)

When i get this error i can handle it.. but my question is: is there a way to check if Pusher Channels are already initialized instead of handle that inside the error method?

DevTiago avatar Jul 22 '22 13:07 DevTiago

And i have another problem... that's my code:

try {
      await pusher.init(
        apiKey: pusherApiKey,
        cluster: pusherCluster,
        onConnectionStateChange: onConnectionStateChange,
        onError: onError,
        onEvent: onEvent,
        onSubscriptionError: onSubscriptionError,
        onDecryptionFailure: onDecryptionFailure,
        onMemberAdded: onMemberAdded,
        onMemberRemoved: onMemberRemoved,
      );

      await pusher.subscribe(channelName: pusherChannelName + user!.deliveryGuyId.toString());
      await pusher.connect();

    } catch (e) {
      print(pusher.channels);
      print(pusher.connectionState);
    }
  }

Because pusher is already initialized i can't connect because it gets an error.

This is the output on my console:

I/flutter ( 7005): {new-order-delivery-260: Instance of 'PusherChannel'}
I/flutter ( 7005): DISCONNECTED

DevTiago avatar Jul 22 '22 14:07 DevTiago

Another test: Even if i try to connect on catch method:

...
 } catch (e) {
      print(pusher.channels);
      print(pusher.connectionState);
      await pusher.connect();
    }

the console prints:

I/flutter ( 7005): {new-order-delivery-260: Instance of 'PusherChannel'}
I/flutter ( 7005): DISCONNECTED
I/flutter ( 7005): Connection: CONNECTING
W/upeats.deliver( 7005): Reducing the number of considered missed Gc histogram windows from 1007 to 100
I/flutter ( 7005): Connection: DISCONNECTING
I/flutter ( 7005): Connection: DISCONNECTED

DevTiago avatar Jul 22 '22 14:07 DevTiago

Hi, we have a known issue https://github.com/pusher/pusher-channels-flutter/issues/38 where hot reloading causes the android client to error with I/flutter ( 6421): Pusher ERR: PlatformException(PusherChannelsFlutter, Pusher Channels already initialized., null, null) There might a workaround in that issue thread, but for now our engineers are aware of the issue and we are prioritising it. It likely they've found it harder than expected to fix it.

benjamin-tang-pusher avatar Jul 22 '22 17:07 benjamin-tang-pusher

any update on this issue?

Jalalajlan avatar Sep 26 '22 02:09 Jalalajlan

This issue is not solved yet? Please ..

ziagit avatar Oct 03 '22 12:10 ziagit

still waiting for solve

abdalmonem avatar Oct 08 '22 11:10 abdalmonem

any progress? thanks.

keanyee avatar Oct 10 '22 03:10 keanyee

i guess its related to 'Hot restart' , cuz in the situation of "normal restart" every thing goes fine, so the plugin doesn't support the hot restart and of course the hot reload also

abdalmonem avatar Oct 10 '22 05:10 abdalmonem

We have just merged https://github.com/pusher/pusher-channels-flutter/pull/80 which allow for re-initialization. Does that help in your case?

proggen-com avatar Oct 28 '22 05:10 proggen-com

A fix for this should be present in #80 as per @proggen-com's comment. I will close this now that the fix is applied.

benw-pusher avatar Nov 24 '22 12:11 benw-pusher