-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we listen for PubNub connectivity/status events? #97
Comments
Hi! Sorry for late reply and thanks for your patience! By default, Dart SDK does not attempt reconnection. However, you can enable it with a There is an undocumented property on the PubNub instance called An example of that: pubnub.signals.networkIsConnected.listen((isConnected) {
if (isConnected) {
} else {
}
}); However, you have to keep in mind that this is not 100% reliable, because of the stateless nature of the underlying protocol. The connection can be dropped and the system may not notify the SDK at all - then the only information about it is going to be a timeout after 5 minutes. Please be careful with relying on this API. |
are - Thanks for the reply. Just so I am clear, the networkIsConnected property is updated when the connection to PubNub gets interrupted, not the general internet connection, is that correct? In other words, setting this listener will get triggered (most of the time, I understand your comment about reliability) when a connection to PubNub itself gets interrupted even if the internet connection is still valid, correct? Thanks! |
are - Also you mention a timeout event - is that a separate aspect of |
Yes, that is correct. It basically collects network errors in other requests to PubNub.
Timeouts are defined for each request in the PubNub SDK - in case of subscribe, if 5 mintues pass without response from the server, the timeout will kick in and start a reconnection process to determine the cause. Signals and the timeout/reconnection are both part of the |
How does a timeout event manifest itself - will it come through the |
If timeout happens, it will be thrown as an exception on the message stream. However, with a RetryPolicy enabled it will be caught by the |
OK thanks - one last question. I am seeing cases where once I establish a subscription and I send a test message (or a signal) I don't see a response. Is there some sort of delay that isn't documented between when a subscribe() is performed and when it can be used to publish a message? Here is my code (same as before, just added the publish at the end):
I can see that the subscribe is completed and the connection message sent. However I only intermittently receive the "CONNECTED" message in the listener, which makes me wonder if there is some timing issue going on between when the subscribe happens and when PubNub can actually receive a publish request? |
We have successfully implemented PubNub using the Java SDK, and are now porting our app to Flutter using the Dart SDK using the latest 4.1.3. I am not seeing the equivalent of the status() method in the SubscribeCallback object that is in the Java SDK in the Dart SDK. I notice that the listeners section for a subscription describes multiple types, but none of them are specific to status.
Is there a separate stream we are supposed to listen on to receive status events for PubNub as a whole such as connect, disconnect, reconnect, etc? The Java SDK has a very robust set of events that are sent.
Our app has a separate module that tracks catching connectivity changes for the Internet, but using the Java SDK we noticed many times the Internet connection would be healthy but for whatever reason the connection to PubNub would be temporarily disconnected, then automatically reconnected according to our retry policy. It would send notifications for each state that our app responds to (disabling some areas, visually showing the user that they can send messages to other subscribers, etc.)
Here is the sample code we are using just to test connectivity:
I would have thought that once we killed the Internet connection, we would get some sort of message from the SDK indicating that connectivity to PubNub had been interrupted (we do in the Java SDK), but we don't. Is there a different Stream/listener we should be using?
The text was updated successfully, but these errors were encountered: