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

ConnectionStateChange DISCONNECTED

Open SANCHEZSJD opened this issue 5 years ago • 2 comments
trafficstars

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

SANCHEZSJD avatar Sep 30 '20 13:09 SANCHEZSJD

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.

MisterJimson avatar Sep 30 '20 13:09 MisterJimson

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;
      });

NTJ3 avatar Nov 06 '20 12:11 NTJ3