Open SANCHEZSJD opened 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.
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;
});
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