HomeX-It / pusher-websocket-flutter

An unofficial Flutter plugin that wraps pusher-websocket-java on Android and pusher-websocket-swift on iOS
MIT License
30 stars 23 forks source link

ConnectionStateChange DISCONNECTED #26

Open SANCHEZSJD opened 3 years ago

SANCHEZSJD commented 3 years ago

I have a view with a bottomNavigationBar, when I move between each tab, the Pusher connection changes to: DISCONNECTED. I only execute the action of "pusher.connect" in the initState of the view

MisterJimson commented 3 years ago

Are you disconnecting at all? You may want to cache the pusher objects you receive somewhere outside of the UI layer so you are not constantly connecting and disconnecting.

NTJ3 commented 3 years ago

i face same issue connection state is keep changing frequently after connecting pusher i made singleton class for connection and i trigger connect inside initState,

import 'package:pusher_websocket_flutter/pusher.dart' as Pusher;

Pusher.PusherAuth pusherAuth = Pusher.PusherAuth(
        PusherUrls.kAuthEndpoint,
        headers: {
          PusherVariables.kChatApiHeaderKey: PusherVariables.kChatApiKey,
        },
      );
      Pusher.PusherOptions pusherOptions = new Pusher.PusherOptions(
        cluster: PusherVariables.kCluster,
        auth: pusherAuth,
        activityTimeout: 3000,
      );
      log.info('IN PUSHER INIT${pusherOptions.auth.endpoint}');
      Pusher.Pusher.init(
        PusherVariables.kPusherApiKey,
        pusherOptions,
        enableLogging: true,
      ).then((value) {
        this.isPusherAuthenticated = true;
        connectPusher();
      }).catchError((err) {
        log.info('ERROR IN PUSHER INIT');
        log.info(err.toString());
        throw err;
      });