chinloyal / pusher_client

A Pusher Channels Client for Fluttter (Fully supports Android and iOS)
https://pusher.com/channels
MIT License
43 stars 182 forks source link

PlatformException(TRIGGER_ERROR, Cannot trigger event client-my-tracking because channel private-ride-138 is in SUBSCRIBE_SENT state #49

Open KBRR11 opened 2 years ago

KBRR11 commented 2 years ago

Hello, I am making a delivery application in which the delivery man must constantly broadcast his location, everything is fine until the delivery man goes through areas where he does not have a very good signal for mobile data and pusher stops sending events, for which I have this error:

PlatformException(TRIGGER_ERROR, Cannot trigger event client-my-tracking because channel private-ride-138 is in SUBSCRIBE_SENT state, java.lang.IllegalStateException: Cannot trigger event client-my-tracking because channel private-ride-138 is in SUBSCRIBE_SENT state at com.pusher.client.channel.impl.PrivateChannelImpl.trigger(PrivateChannelImpl.java:48) at com.github.chinloyal.pusher_client.pusher.PusherService.trigger(PusherService.kt:278) at com.github.chinloyal.pusher_client.pusher.PusherService.access$trigger(PusherService.kt:30) at com.github.chinloyal.pusher_client.pusher.PusherService$register$1.onMethodCall(PusherService.kt:60) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:178) at io.flutter.embedding.engine.dart.DartMessenger.lambda$handleMessageFromDart$0$DartMessenger(DartMessenger.java:206) at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$6ZD

My question here is... how can I know the status of a channel? because in the documentation it only shows how to know the state of the pusher with pusher.onConnectionStateChange(), but this takes about 30 to 40 seconds to show in an emulator, or how can I know if my events are being sent correctly?

For example, I have this: when the distributor starts to move, I capture its location every 10 meters, which is why I ask about the connection status of the pusher:

`conectarPusher(userId) async { await pusher.connect(); channel = pusher.subscribe('private-ride-$userId') pusher.onConnectionStateChange((state) async { pusherConnection = state?.currentState ?? 'DISCONNECTED'; print( "--- CAMBIO DE ESTADO de: ${state?.previousState} a -> ${state?.currentState}");

      if (state?.currentState == 'CONNECTED') {
        canSendEvents = true;
      } else {
        canSendEvents = false;
      }
    });

}`

BackgroundLocation.getLocationUpdates((position) async { final positionRepartidor = { "latitude": position.latitude, "longitude": position.longitude }; if (canSendEvents) { channel.trigger('client-my-tracking', jsonEncode(positionRepartidor)); } else { print("No envio nada porque el pusher está desconectado"); } });

and this one is my Pusher options configuration: PusherClient pusher = PusherClient( Enviroments.appKeyPusher, PusherOptions( cluster: 'us2', encrypted: true, auth: PusherAuth(Enviroments.authEndPointPusher)), autoConnect: false);

please 🙏 what should be the correct way to check the status of the channel, the pusher and the correct sending of events