Class: JpegCamera
Defined in: | src/jpeg_camera.coffee |
Overview
Base class for JpegCamera implementations. Subclasses provide functionality defined by this API using different engines. On supported browsers HTML5 implementation will be used, otherwise Flash will be used if available.
if (!window.JpegCamera) {
alert("Neither getUserMedia nor Flash are available!");
}
else {
// either HTML5 or Flash are available
var camera = JpegCamera("#camera").ready(function () {
var snapshot = camera.capture().show()
}).error(function () {
alert("Camera access was declined.");
});
}
Class Method Summary
-
.
(Boolean)
canvas_supported()
Tells whether the browser supports
canvas
element and you can use Snapshot#get_canvas method to display snapshots outside the camera container.
Instance Method Summary
- # (JpegCamera) ready(callback) Bind callback for camera ready event.
- # (JpegCamera) error(callback) Bind callback for camera error events.
- # (void) get_stats(callback) Peak into video stream and calculate pixel statistics.
- # (Snapshot) capture(options = {}) Capture camera snapshot.
- # (JpegCamera) show_stream() Hide currently displayed snapshot and show the video stream.
- # (JpegCamera) discard_all() Discard all snapshots and show video stream.
Class Method Details
.
(Boolean)
canvas_supported()
Tells whether the browser supports canvas
element and you can use
Snapshot#get_canvas method to display snapshots outside the camera
container.
All browsers except Internet Explorer 8 and earlier support canvas
element.
Constructor Details
#
(void)
constructor(container, options)
Construct new camera.
JpegCamera will fill the entire container element. If the element's aspect ratio is different than that of the camera stream (usually 4:3, but sometimes 16:9) the stream will be clipped horizontally or vertically.
To display the image on the client side the image might additionally get resized to match container element, but the file sent to the server will always be in camera's native resolution.
By design the file sent to the server will only contain the area that was visible to the user during capture. There is no way of sending unclipped, full camera frame without showing the whole frame to the user.
Resizing container after the camera has been initialized is not supported.
Various options provided here can be overwritten when calling capture or Snapshot#upload.
Instance Method Details
#
(JpegCamera)
ready(callback)
Bind callback for camera ready event.
Replaces the callback set using on_ready option during initialization.
If the event has already happened the argument will be called immediately.
#
(JpegCamera)
error(callback)
Bind callback for camera error events.
Replaces the callback set using on_error option during initialization.
Errors can occur if user declines camera access, flash fails to load, etc. Furthermore error event can occur even after camera was ready if for example user revokes access.
If the event has already happened the argument will be called immediately.
#
(void)
get_stats(callback)
Peak into video stream and calculate pixel statistics.
Can be useful to give the user hints about bad lighting. It uses full capture area, but at much lower resolution. It's more efficient than taking a regular capture and calling Snapshot#get_stats.
Because reading image data can take a while when Flash fallback is being
used this method does not return the data immediately. Instead it accepts
a callback that later will be called with a Stats instance as an argument.
The camera object will be available as this
.
#
(Snapshot)
capture(options = {})
Capture camera snapshot.
All of the options can have their defaults set when constructing camera object.
#
(JpegCamera)
show_stream()
Hide currently displayed snapshot and show the video stream.
#
(JpegCamera)
discard_all()
Discard all snapshots and show video stream.