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
Add the plugin to your cordova project:
cordova plugin add https://github.com/Moonware/cordova-cameraserver
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 );
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'>
This plugin was developped for the needs of Netcam Studio Smart Camera:
Netcam Studio Smart Camera iOS
Netcam Studio Smart Camera Android
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.