#CameraServer Plugin For Cordova
Supported platform:
- iOS
- Android
Provides Live Camera images over HTTP (over Wifi or locally to a Cordova Application):
Why over HTTP ?
- A known memory leak problem occurs when retrieving data/result in Cordova (see CameraPlus)
- It's faster and purely in native code so it was suitable for our application Netcam Studio Smart Camera
#How to use CameraServer?
cordova plugin add https://github.com/Moonware/cordova-cameraserver
cordova plugin rm cordova-plugin-cameraserver
Since Cordova 4.0, it may be required to install the cordova-plugin-whitelist to allow calls to 127.0.0.1 and localhost
Without this step, your application may not be allowed to pull and display images from the camera server plugin.
Please follow installation and setup instructions here: cordova-plugin-whitelist
#Javascript APIs
startServer( options, success_callback, error_callback );
stopServer( success_callback, error_callback );
getURL( success_callback, error_callback );
getLocalPath( success_callback, error_callback );
getNumRequests( success_callback, error_callback );
startCamera( success_callback, error_callback );
stopCamera( success_callback, error_callback );
/* Just for testing, do not use this since it leaks */
getJpegImage( success_callback, error_callback );
#Quick Start
Start the Web Server
cordova.plugins.CameraServer.startServer({
'www_root' : '/',
'port' : 8080,
'localhost_only' : false,
'json_info': []
}, function( url ){
// if server is up, it will return the url of http://<server ip>:port/
// the ip is the active network connection
// if no wifi or no cell, "127.0.0.1" will be returned.
console.log('CameraServer Started @ ' + url);
}, function( error ){
console.log('CameraServer Start failed: ' + error);
});
Start the Camera Capture (will act on demand when a HTTP request arrives)
cordova.plugins.CameraServer.startCamera(function(){
console.log('Capture Started');
},function( error ){
console.log('CameraServer StartCapture failed: ' + error);
});
Downloading a Live Image in Javascript (AngluarJS / Ionic)
var localImg = 'http://localhost:8080/live.jpg';
$http.get(localImg).
success(function(data, status, headers, config) {
console.log("Image Downloaded");
}).
error(function(data, status, headers, config) {
console.log("Image Download failed");
});
Displaying a Live Image in a Cordova App is as simple as:
<img src='http://localhost:8080/live.jpg'>
#Usage in applications
This plugin was developped for the needs of Netcam Studio Smart Camera:
Netcam Studio Smart Camera iOS
Netcam Studio Smart Camera Android
#Credits
This Cordova plugin is based on CorHttpd, thanks to the authors:
- CorHttpd, by floatinghotpot
Which is itself based on:
- 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.
We will of course appreciate if you share any improvement or addition made to the plugin.