Reputation: 167
I am facing a problem the heartbeat interval in my IBM MobileFirst application.
The first time the app runs everything is ok. If I go offline, it recognizes that I am offline. The problem is that if I go offline and then go online again, the apps tries to send the heartbeat and it keeps trying to send it for about 20-30 seconds. Even after being online with my phone, I am still 'offline' in the application because the heartbeat is still trying to send be sent and be successful. 20-30 later is when I receive that the connection was successful and then the app recognizes that I am online. Is there a way to avoid this 'delay'?
I want the app to know that I am offline/online as soon as possible. Is there a way to achieve this?
This is my initOptions where I am using the timeout:
var wlInitOptions = {
timeout: 5000,
.
.
.
And this is my app.js where i am using the WL.Client.setHeartBeatInterval
WL.Client.setHeartBeatInterval(5);
document.addEventListener(WL.Events.WORKLIGHT_IS_CONNECTED, function (event) {
WL.Logger.error('We are online, lower the heartbeat');
WL.Client.setHeartBeatInterval(5);
}, false);
document.addEventListener(WL.Events.WORKLIGHT_IS_DISCONNECTED, function (event) {
WL.Logger.error('We are no longer online, raise heartbeat');
WL.Client.setHeartBeatInterval(1);
}, false);
Upvotes: 1
Views: 119
Reputation: 17722
The heartbeat indirectly recognises you are online due to a successful heartbeat - it doesn't look at the status of online/offline using the phone's hardware. Therefore, there will always be a delay, which on average will be half of the heartbeat length. If you wish to increase the speed at which it recognises you're online, you need to reduce the heartbeat interval. Of course, that will increase network traffic.
There are Cordova plugins, such as this one, which instead look at the phone's hardware and detect whether it is online or offline, providing events you can listen to. They don't (as far as I know) attempt to initiate a network connection to a remote host, so that will tell you only whether the phone thinks it has a network connection, not whether it is stable/robust/fast. As far as I know, MFP doesn't have that functionality built in. To be clear, the plugin is not supported by IBM and I haven't tested it.
Upvotes: 1