diff --git a/README.md b/README.md new file mode 100644 index 0000000..47b2c20 --- /dev/null +++ b/README.md @@ -0,0 +1,80 @@ +jQuery Webcam Plugin +==================== +[![CDNJS version](https://img.shields.io/cdnjs/v/jQuery-webcam.svg)](https://cdnjs.com/libraries/jQuery-webcam) + + +Description +----------- +A small wrapper library to be able to communicate with a Flash webcam via JavaScript. + + +Example +------ + +Please note: The camera doesn't work if you have any dom-errors on your page! + +The Flash object will be embedded into the following Div: + +```html +
+``` + +```javascript + +jQuery("#webcam").webcam({ + + width: 320, + height: 240, + mode: "callback", + swffile: "/jscam_canvas_only.swf", // canvas only doesn't implement a jpeg encoder, so the file is much smaller + + onTick: function(remain) { + + if (0 == remain) { + jQuery("#status").text("Cheese!"); + } else { + jQuery("#status").text(remain + " seconds remaining..."); + } + }, + + onSave: function(data) { + + var col = data.split(";"); + // Work with the picture. Picture-data is encoded as an array of arrays... Not really nice, though =/ + }, + + onCapture: function () { + webcam.save(); + + // Show a flash for example + }, + + debug: function (type, string) { + // Write debug information to console.log() or a div, ... + }, + + onLoad: function () { + // Page load + var cams = webcam.getCameraList(); + for(var i in cams) { + jQuery("#cams").append("
  • " + cams[i] + "
  • "); + } + } +}); + + +``` + +If you want to draw the picture onto a canvas, have a look at the source of the page on my blog, linked below. + + +Further examples and documentation +========================== +For further details and code examples take a look at the demonstration and documentation page on: + +[https://raw.org/article/camara-support-in-html5-and-javascript/](https://raw.org/article/camara-support-in-html5-and-javascript/) + +License +====== +Copyright (c) 2013, [Robert Eisele](https://raw.org/) +Dual licensed under the MIT or GPL Version 2 licenses. diff --git a/jquery.webcam.js b/jquery.webcam.js index ac1d6c1..cd3655e 100644 --- a/jquery.webcam.js +++ b/jquery.webcam.js @@ -10,27 +10,27 @@ var webcam = { - extern: null, // external select token to support jQuery dialogs - append: true, // append object instead of overwriting + "extern": null, // external select token to support jQuery dialogs + "append": true, // append object instead of overwriting - width: 320, - height: 240, + "width": 320, + "height": 240, - mode: "callback", // callback | save | stream + "mode": "callback", // callback | save | stream - swffile: "jscam.swf", - quality: 85, + "swffile": "jscam.swf", + "quality": 85, - debug: function () {}, - onCapture: function () {}, - onTick: function () {}, - onSave: function () {}, - onLoad: function () {} + "debug": function () {}, + "onCapture": function () {}, + "onTick": function () {}, + "onSave": function () {}, + "onLoad": function () {} }; - window.webcam = webcam; + window["webcam"] = webcam; - $.fn.webcam = function(options) { + $["fn"]["webcam"] = function(options) { if (typeof options === "object") { for (var ndx in webcam) { @@ -40,54 +40,54 @@ } } - var source = ''; + var source = ''; - if (null !== webcam.extern) { - $(webcam.extern)[webcam.append ? "append" : "html"](source); + if (null !== webcam["extern"]) { + $(webcam["extern"])[webcam["append"] ? "append" : "html"](source); } else { - this[webcam.append ? "append" : "html"](source); + this[webcam["append"] ? "append" : "html"](source); } var run = 3; (_register = function() { var cam = document.getElementById('XwebcamXobjectX'); - if (cam && cam.capture !== undefined) { + if (cam && cam["capture"] !== undefined) { /* Simple callback methods are not allowed :-/ */ - webcam.capture = function(x) { + webcam["capture"] = function(x) { try { - return cam.capture(x); + return cam["capture"](x); } catch(e) {} } - webcam.save = function(x) { + webcam["save"] = function(x) { try { - return cam.save(x); + return cam["save"](x); } catch(e) {} } - webcam.setCamera = function(x) { + webcam["setCamera"] = function(x) { try { - return cam.setCamera(x); + return cam["setCamera"](x); } catch(e) {} } - webcam.getCameraList = function() { + webcam["getCameraList"] = function() { try { - return cam.getCameraList(); + return cam["getCameraList"](); } catch(e) {} } - webcam.pauseCamera = function() { + webcam["pauseCamera"] = function() { try { - return cam.pauseCamera(); + return cam["pauseCamera"](); } catch(e) {} } - webcam.resumeCamera = function() { + webcam["resumeCamera"] = function() { try { - return cam.resumeCamera(); + return cam["resumeCamera"](); } catch(e) {} } - webcam.onLoad(); + webcam["onLoad"](); } else if (0 == run) { - webcam.debug("error", "Flash movie not yet registered!"); + webcam["debug"]("error", "Flash movie not yet registered!"); } else { /* Flash interface not ready yet */ run--; diff --git a/jquery.webcam.min.js b/jquery.webcam.min.js new file mode 100644 index 0000000..97e7c57 --- /dev/null +++ b/jquery.webcam.min.js @@ -0,0 +1,10 @@ +/* + jQuery webcam plugin v1.0.0 09/12/2010 + http://www.xarg.org/project/jquery-webcam-plugin/ + + Copyright (c) 2010, Robert Eisele (robert@xarg.org) + Dual licensed under the MIT or GPL Version 2 licenses. +*/ +(function(f){var a={extern:null,append:!0,width:320,height:240,mode:"callback",swffile:"jscam.swf",quality:85,debug:function(){},onCapture:function(){},onTick:function(){},onSave:function(){},onLoad:function(){}};window.webcam=a;f.fn.webcam=function(b){if("object"===typeof b)for(var d in a)void 0!==b[d]&&(a[d]=b[d]);b='';if(null!==a.extern)f(a.extern)[a.append?"append":"html"](b);else this[a.append?"append":"html"](b);var e=3;(_register=function(){var c=document.getElementById("XwebcamXobjectX");c&&void 0!==c.capture?(a.capture=function(a){try{return c.capture(a)}catch(b){}},a.save=function(a){try{return c.save(a)}catch(b){}},a.setCamera=function(a){try{return c.setCamera(a)}catch(b){}},a.getCameraList=function(){try{return c.getCameraList()}catch(a){}}, +a.pauseCamera=function(){try{return c.pauseCamera()}catch(a){}},a.resumeCamera=function(){try{return c.resumeCamera()}catch(a){}},a.onLoad()):0==e?a.debug("error","Flash movie not yet registered!"):(e--,window.setTimeout(_register,1E3*(4-e)))})()}})(jQuery);