Moonware / cordova-cameraserver

Cordova Plugin (iOS + Android) serving Live Images from the Camera over HTTP
43 stars 34 forks source link

CameraServer Plugin For Cordova

Supported platform:

Provides Live Camera images over HTTP (over Wifi or locally to a Cordova Application):

Why over HTTP ?

How to use CameraServer?

Add the plugin to your cordova project:

cordova plugin add https://github.com/Moonware/cordova-cameraserver   

Removing the plugin to your cordova project:

cordova plugin rm cordova-plugin-cameraserver      

Dependency

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:

Which is itself based on:

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.