Code Monkey home page Code Monkey logo

ember-webcam's Introduction

Ember Webcam

Build Status Ember Observer Score Code Climate Test Coverage

This Ember CLI addon is a simple wrapper for WebcamJS 1.x.

Installation

ember install ember-webcam

Usage

This Ember addon provides an ember-webcam component which renders a live camera viewer. It also yields a camera controller (camera) to the block. This controller can be used to trigger certain camera actions, such as taking a still snapshot (camera.snap).

The component also takes two optional closure actions:

  • didSnap will be fired after a snapshot is taken, with the data URI of the snapshot. This URI can be passed around like any URL, or be submitted to your server.

  • didError will be fired when an error occurs.

import Component from 'ember-component';

export default Component.extend({
  dataUri: null,
  actions: {
    didSnap(dataUri) {
      // Delivers a data URI when snapshot is taken.
      this.set('dataUri', dataUri);
    },
    didError(error) {
      // Fires when a WebcamError occurs.
      console.error(error);
    }
  }
});
{{#ember-webcam
  didSnap=(action 'didSnap')
  didError=(action 'didError')
  as |camera|}}
  <button {{action camera.snap}}>
    Take Snapshot!
  </button>
{{/ember-webcam}}

<img src={{dataUri}}>

Fastboot Compatibility

For Fastboot compatibility you must avoid rendering ember-webcam on the server. One way to do this is wrap ember-webcam in your own component which only renders ember-webcam after the didInsertElement hook.

import Component from 'ember-component';

export default Component.extend({
  didInsertElement() {
    this.set('displayWebcam');
  }
)}
{{#if displayWebcam}}
  {{#ember-webcam
    didSnap=(action 'didSnap')
    didError=(action 'didError')
    as |camera|}}
    <button {{action camera.snap}}>
      Take Snapshot!
    </button>
  {{/ember-webcam}}

  <img src={{dataUri}}>
{{/if}}

Configurations

By default, this addon will import a webcam.swf file from WebcamJS and include it in your build. This file is used as a fallback if your browser does not support HTML5 getUserMedia. IE and Safari are two major browsers that do not yet have the support. For more details, see WebcamJS Docs and caniuse.com.

This Flash fallback can be turned off by specifying enableFlashFallback: false inside the ember-webcam config property in your ember-cli-build.js file (or your index.js if you are working on an addon):

module.exports = function(defaults) {
  const app = new EmberApp(defaults, {
    'ember-webcam': {
      enableFlashFallback: false
    }
  });

  // ...
};

You may otherwise specify where you want webcam.swf to be located in your build, using the flashFallbackDir option. The default value is 'assets', meaning the file will be located at <APP_ROOT>/assets/webcam.swf.

Contributors

Kind thanks to Lei Zhao (leizhao4) for initiating this project and of course the authors of WebcamJS.

License

This addon is MIT Licensed.

ember-webcam's People

Contributors

chbonser avatar devotox avatar ember-tomster avatar kltdwrds avatar leizhao4 avatar repl-philip-kan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.