Network status is an indicator of the client's connection to the network. Knowledge of network status is crucial to building applications which can operate offline or which manage their battery consumption.
Sometimes, the PubNub SDK even provides more accurate network status information than the host platform APIs.
The Redux components described in this section manage the knowledge of whether the client is considered connected.
Network status is monitored using the Boolean
isConnected property of the
networkStatus object. When
isConnected is true, the application is considered to be online.
The following example shows the shape of Network Status data in the store:
The PubNub Redux framework provides reducers your app can implement that respond to various actions that update the store. To track the state of a set of objects in the store, combine the reducers you want into the
rootReducer for your app.
createNetworkStatusReducer instantiates a reducer in the store that responds to actions dispatched to update the state of network status in the store.
|Usually, you initialize this reducer with a value of
false. The listener invokes the reducer with either
false based on the network status connection.
The PubNub Redux framework includes listeners that monitor PubNub events from the server and dispatch corresponding actions. All listeners are automatically invoked if your app registers the combined PubNub listener. You can register only specific listeners, or implement your own combine listeners function.
createNetworkStatusListener registers a listener in the store that monitors network status events.
A sample implementation of a single listener:
The PubNub Redux framework doesn't contain any built-in commands to dispatch a network status event actions.