summaryrefslogtreecommitdiff
path: root/js/camera.js
diff options
context:
space:
mode:
authorjules <jules@okfoc.us>2014-07-30 09:34:57 -0400
committerjules <jules@okfoc.us>2014-07-30 09:34:57 -0400
commitb2375e11e2c9eee9d09bf30fd5ec8e900023c46f (patch)
tree999a1d4b1a7df077ae7f1ba0e4e29033ed38114d /js/camera.js
parent28b6a443dd5760829fced2fae54ef8e02566ba7d (diff)
shader-cam
Diffstat (limited to 'js/camera.js')
-rw-r--r--js/camera.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/js/camera.js b/js/camera.js
new file mode 100644
index 0000000..3a0c8b4
--- /dev/null
+++ b/js/camera.js
@@ -0,0 +1,61 @@
+var camera = (function(){
+ var loaded = false, video
+
+ navigator.getMedia = ( navigator.getUserMedia ||
+ navigator.webkitGetUserMedia ||
+ navigator.mozGetUserMedia ||
+ navigator.msGetUserMedia);
+
+ if (! navigator.getMedia) {
+ $("#camera").hide()
+ return
+ }
+
+ $("#camera").click(load)
+ function load(){
+ if (! loaded) {
+ build()
+ }
+ else {
+ ready()
+ }
+ window.gif = window.img = null
+ }
+
+ function ready(){
+ cc.canvas.width = actual_w = w = min(video.videoWidth, 400)
+ cc.canvas.height = actual_h = h = video.videoHeight / (video.videoWidth/w)
+ video.setAttribute('width', video.videoWidth)
+ video.setAttribute('height', video.videoHeight)
+ window.gif = window.img = null
+ window.cam = video
+ }
+
+ function build(){
+ video = document.createElement("video")
+ navigator.getMedia({
+ video: true,
+ audio: false
+ },
+ function(stream) {
+ if (navigator.mozGetUserMedia) {
+ video.mozSrcObject = stream;
+ } else {
+ var vendorURL = window.URL || window.webkitURL;
+ video.src = vendorURL.createObjectURL(stream);
+ }
+ video.play();
+ },
+ function(err) {
+ console.log("An error occured! " + err);
+ }
+ )
+
+ video.addEventListener('canplay', function(ev){
+ if (! loaded) {
+ loaded = true
+ ready()
+ }
+ }, false);
+ }
+})()