I made an app in Phone Gap but now I am trying to make it in NativeScript,
App connect and is almost 50% complete; however when the user navigate away from the app, screen go off or change to another app, the app disconnect and reconnect when on focus again..
My question, has anybody tackle the issue and keep SocketIO from disconnecting and reconnecting when in background mode?
I have run this example, but have no clue how to implement it.. for SocketIO.. https://github.com/NativeScript/sample-android-background-services
cordova with this simple code, it keep the socket connected.
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
function onPause(){
setTimeout(function(){
//console.log('pausing');
cordova.plugins.backgroundMode.enable();
}, 500);
};
function onResume(){
setTimeout(function() {
console.log('resuming');
cordova.plugins.backgroundMode.disable();
}, 500);
};
how to implement same behavior in {{N}}.
// App went to background...
application.on(application.suspendEvent, function (args) {
console.log('chat is in background mode');
});
// App was reopened...
application.on(application.resumeEvent, function (args) {
console.log('chat is not longer in background mode');
});