Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion dist/angular-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
function ($timeout, $sce) {
return {
require: 'ngModel',
template: '<div class="ng-camera clearfix"> <p ng-hide="isLoaded">Loading Camera...</p> <p ng-show="noCamera">Couldn\'t find a camera to use</p> <div class="ng-camera-stack" ng-hide="!isLoaded"> <div class="ng-camera-countdown" ng-show="activeCountdown"> <p class="tick">{{countdownText}}</p> </div> <img class="ng-camera-overlay" ng-hide="!overlaySrc" ng-src="{{overlaySrc}}" width="{{width}}" height="{{height}}"> <video id="ng-camera-feed" autoplay width="{{width}}" height="{{height}}" src="{{videoStream}}">Install Browser\'s latest version</video> <canvas id="ng-photo-canvas" width="{{width}}" height="{{height}}" style="display:none;"></canvas> </div> <div class="ng-camera-controls" ng-hide="hideUI"> <button class="btn ng-camera-take-btn" ng-click="takePicture()">Take Picture</button> </div> </div>',
template: '<div class="ng-camera clearfix"> <p ng-hide="isLoaded">Loading Camera...</p> <p ng-show="noCamera">Couldn\'t find a camera to use</p> <div class="ng-camera-stack" ng-hide="!isLoaded"> <div class="ng-camera-countdown" ng-show="activeCountdown"> <p class="tick">{{countdownText}}</p> </div> <img class="ng-camera-overlay" ng-hide="!overlaySrc" ng-src="{{overlaySrc}}" width="{{width}}" height="{{height}}" style="position: absolute;"> <video id="ng-camera-feed" autoplay width="{{width}}" height="{{height}}" src="{{videoStream}}">Install Browser\'s latest version</video> <canvas id="ng-photo-canvas" width="{{width}}" height="{{height}}" style="display:none;"></canvas> </div> <div class="ng-camera-controls" ng-hide="hideUI"> <button class="btn ng-camera-take-btn" ng-click="takePicture()">Take Picture</button> </div> </div>',
replace: false,
transclude: true,
restrict: 'E',
Expand All @@ -30,6 +30,9 @@
scope.stream.stop();
}
});
/**
* @description Set mediastream source and notify camera
*/
scope.enableCamera = function () {
return navigator.getUserMedia({
audio: false,
Expand All @@ -47,6 +50,9 @@
});
});
};
/**
* @description Disable mediastream source and notify camera
*/
scope.disableCamera = function () {
return navigator.getUserMedia({
audio: false,
Expand All @@ -57,6 +63,9 @@
});
});
};
/**
* @description Capture current state of video stream as photo
*/
scope.takePicture = function () {
var canvas, context, countdownTick, countdownTime;
canvas = window.document.getElementById('ng-photo-canvas');
Expand Down Expand Up @@ -109,6 +118,10 @@
}
return false;
};
/**
* @description Add overlay frame to canvas render
* @param {Object} context Reference to target canvas context
*/
scope.addFrame = function (context, url, callback) {
var overlay;
if (callback == null) {
Expand All @@ -124,11 +137,18 @@
overlay.crossOrigin = '';
return overlay.src = url;
};
/**
* @description Keeps a packaged version of media ready
* @param {Base64} newVal Prefix-stripped Base64 of of canvas image
*/
scope.$watch('media', function (newVal) {
if (newVal != null) {
return scope.packagedMedia = scope.media.replace(/^data:image\/\w+;base64,/, '');
}
});
/**
* @description Preloader for overlay image
*/
scope.$watch('overlaySrc', function (newVal, oldVal) {
var preloader;
if (scope.overlaySrc != null) {
Expand All @@ -145,6 +165,9 @@
return scope.isLoaded = true;
}
});
/**
* @description Watch for when to turn on/off camera feed
*/
scope.$watch('enabled', function (newVal, oldVal) {
if (newVal) {
if (!oldVal) {
Expand All @@ -156,6 +179,10 @@
}
}
});
/**
* @description Check format type of camera.
* @todo Future support for different media types (GIF, Video)
*/
return scope.$watch('type', function () {
switch (scope.type) {
case 'photo':
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-camera.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/directives/angular-camera.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('omr.directives', [])
<div class="ng-camera-countdown" ng-show="activeCountdown">
<p class="tick">{{countdownText}}</p>
</div>
<img class="ng-camera-overlay" ng-hide="!overlaySrc" ng-src="{{overlaySrc}}" width="{{width}}" height="{{height}}">
<img class="ng-camera-overlay" ng-hide="!overlaySrc" ng-src="{{overlaySrc}}" width="{{width}}" height="{{height}}" style="position: absolute;">
<video id="ng-camera-feed" autoplay width="{{width}}" height="{{height}}" src="{{videoStream}}">Install Browser\'s latest version</video>
<canvas id="ng-photo-canvas" width="{{width}}" height="{{height}}" style="display:none;"></canvas>
</div>
Expand Down Expand Up @@ -191,4 +191,4 @@ angular.module('omr.directives', [])
scope.enableCamera() if scope.enabled
else
# Defaulting to photo
scope.enableCamera() if scope.enabled
scope.enableCamera() if scope.enabled