CorHttpd: embeded httpd for cordova
Supported platform:
- iOS
- Android
You can browse (locally or remotely) to access files in android/ios phone/pad:
- browse the files in mobile device with a browser in PC.
- copy files from mobile device to PC quickly, just with Wifi.
- use cordova webview to access the assets/www/ content with http protocol.
Why http access is good?
- Use wifi instead of cable, more convenient.
- For security reason, browser does not support local AJAX calls. It's big bottle neck to deploy HTML5 games to Cordova platform.
- The most popular phaser.js game engine, a httpd is always required, as it use AJAX to load resource.
How to use CorHttpd?
Add the plugin to your cordova project:
cordova plugin add https://github.com/floatinghotpot/cordova-httpd.git
Quick start, copy the demo files, and just build to play.
cp -r plugins/com.rjfun.cordova.httpd/test/* www/
Javascript APIs
; ; ; ;
Example code: (read the comments)
var httpd = null; { httpd = cordova && cordovaplugins && cordovapluginsCorHttpd ? cordovapluginsCorHttpd : null; } { documentinnerHTML = "document.location.href: " + documentlocationhref; if httpd /* use this function to get status of httpd * if server is up, it will return http://<server's ip>:port/ * if server is down, it will return empty string "" */ httpd; // call this function to retrieve the local path of the www root dir httpd; else ; } { if httpd // before start, check whether its up or not httpd; else ; } { if httpd // call this API to stop web server httpd; else ; }
Credits
This Cordova plugin is built based on following 2 projects, and thanks to the authors.
- NanoHTTPD, written in java, for java / android, by psh.
- CocoaHTTPServer, written in Obj-C, for iOS / Mac OS X, by robbiehanson.
You can use this plugin for FREE. Feel free to fork, improve and send pull request.
If need prompt support, please buy a license, you will be supported with high priority.
More Cordova/PhoneGap plugins by Raymond Xie, find them in plugin registry.
Project outsourcing and consulting service is also available. Please contact us if you have the business needs.