Skip to content

Moonware/cordova-cameraserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#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?

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:

  • 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.

About

Cordova Plugin (iOS + Android) serving Live Images from the Camera over HTTP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published