floatinghotpot / cordova-httpd

Embed tiny web server into Cordova with a plugin
285 stars 148 forks source link

Server stops on iOS after sleep #23

Open thedracle opened 8 years ago

thedracle commented 8 years ago

I'm noticing that a service started works fine to begin with.

However after the device sleeps for a period of time, it seems as if the server gets shut down, or stops responding to requests.

Any help would be greatly appreciated.

smoresch commented 8 years ago

Hi, here is the solution, works for me:

add two events listeners:

document.addEventListener("resume", function() { httpd = null; httpd = (cordova && cordova.plugins && cordova.plugins.CorHttpd) ? cordova.plugins.CorHttpd : null; if (httpd) { window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) { var path = fileSystem.root.nativeURL.replace("file://", ""); startServer(path); }); } }, false);

document.addEventListener("pause", function() { if ( httpd ) { // call this API to stop web server httpd.stopServer(function(){ console.log('server is stopped.'); },function( error ){ console.log('failed to stop server' + error); }); } else { console.log('CorHttpd plugin not available/ready.'); } });

AdeelKhan1 commented 8 years ago

I am new to iOS Apps / Cordova stuff so please be patient

I build SPA with angular wrapped in Cordova and run it on httpd server .

All great But :)

I build SPA with angular wrapped in Cordova and run it on httpd server .

All great But :)

In iOs server stops when device pause :

following fix this problem .. thanks smoresch https://github.com/floatinghotpot/cordova-httpd/issues/23

But above does not solves my problem because what i am doing is

After starting server I open url (localhost:443) which goes to www/htdocs and run SPA

and when I am in SPA and do pause iphone Server stops and that breaks SPA cant do anything ..

What will work : Link on SPA which let me go back to root index so i can start server again or some how on Pause i can reset app to go back to root index Or any other brilliant suggestion will work

Thisgio commented 6 years ago

I'm having this problem with my ionic app.

But the strange thing in my app is that you don't even need to let the app sleep to stop the server from working. If you don't touch the app for around 10 minutes, even when it is in foreground, the app requests stops working (on page change).

Another strange thing is that iOS works fine, but Android does not.

Any suggestions?

TuxGamer commented 6 years ago

I'm also having this problem on iOS.

We will go with the restart workaround for now, but a real fix would be great :)