PlatformException(TRIGGER_ERROR,无法触发事件 client-my-tracking,因为通道 private-ride-138 处于状态 SUBSCRIBE_SENT
PlatformException(TRIGGER_ERROR, no se puede desencadenar el evento client-my-tracking porque el canal private-ride-138 está en estado SUBSCRIBE_SENT
我正在制作一个送货应用程序,其中送货员必须不断广播他的位置,一切都很好,直到送货员经过他没有很好的移动数据信号并且推送器停止发送事件的区域,为此我有这个错误:
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.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[=13=]$DartMessenger(DartMessenger.java:206) at io.flutter.embedding.engine.dart.-$$Lambda$DartMessengerZD
我的问题是...我如何知道频道的状态?因为在文档中它只显示了如何使用 pusher.onConnectionStateChange()
了解推送器的状态,但这需要大约 30 到 40 秒才能在模拟器中显示,或者我如何知道我的事件是否被正确发送?
比如我有这个:当分发器开始移动时,我每10米捕获一次它的位置,这就是我询问推送器连接状态的原因:
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;
}
});
}
-- into other method:
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);```
what should be the correct way to check the status of the channel, the pusher and the correct sending of events?
您可以绑定到 connection state 更改,但正如您所说,它不会是 real-time。
最好的办法是在要触发事件时捕获异常。如果初始连接成功,但客户端无法触发事件,则可以认为这是某种连接问题。
在这种情况下最好的做法取决于您的期望。如果整个行程对你来说不重要,你可以忽略失败的位置更新,因为客户关心最后的位置。
如果您关心整个行程(例如,您正在构建一个管理仪表板以查看送货员是否正确遵循路线),您应该将它们保存在内存中并稍后重试。 (可能您想限制内存使用,以防设备长时间离线)
我正在制作一个送货应用程序,其中送货员必须不断广播他的位置,一切都很好,直到送货员经过他没有很好的移动数据信号并且推送器停止发送事件的区域,为此我有这个错误:
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.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[=13=]$DartMessenger(DartMessenger.java:206) at io.flutter.embedding.engine.dart.-$$Lambda$DartMessengerZD
我的问题是...我如何知道频道的状态?因为在文档中它只显示了如何使用 pusher.onConnectionStateChange()
了解推送器的状态,但这需要大约 30 到 40 秒才能在模拟器中显示,或者我如何知道我的事件是否被正确发送?
比如我有这个:当分发器开始移动时,我每10米捕获一次它的位置,这就是我询问推送器连接状态的原因:
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;
}
});
}
-- into other method:
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);```
what should be the correct way to check the status of the channel, the pusher and the correct sending of events?
您可以绑定到 connection state 更改,但正如您所说,它不会是 real-time。
最好的办法是在要触发事件时捕获异常。如果初始连接成功,但客户端无法触发事件,则可以认为这是某种连接问题。
在这种情况下最好的做法取决于您的期望。如果整个行程对你来说不重要,你可以忽略失败的位置更新,因为客户关心最后的位置。
如果您关心整个行程(例如,您正在构建一个管理仪表板以查看送货员是否正确遵循路线),您应该将它们保存在内存中并稍后重试。 (可能您想限制内存使用,以防设备长时间离线)