Skip to content
Browse files

Minor program changes to better suite mobile use

Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
  • Loading branch information...
1 parent e05f31f commit 7cd7c4378750592ed6846db58a5e8b3ecc8e04f0 @rwaldron rwaldron committed Feb 29, 2012
Showing with 31 additions and 21 deletions.
  1. +15 −10 app.js
  2. +6 −2 lib/dmv.js
  3. +6 −2 public/javascripts/dmv.js
  4. +2 −2 public/javascripts/dmv.min.js
  5. +1 −1 public/stylesheets/style.css
  6. +0 −4 views/index.jade
  7. +1 −0 views/layout.jade
View
25 app.js
@@ -1,5 +1,6 @@
var express = require("express"),
- socket = require("socket.io");
+ socket = require("socket.io"),
+ fs = require("fs");
var app = express.createServer(),
io = socket.listen( app );
@@ -22,6 +23,7 @@ app.get( "/", function( req, res ) {
});
});
+
// Connection Pool
var connections = {
// uid: object
@@ -47,18 +49,21 @@ io.sockets.on( "connection", function( client ) {
client.on( "capture", function( data ) {
+ var file, buffer,
+ filepath = "saved/" + Date.now() + ".png";
+ // Create a buffer from the base64 encoded string
+ buffer = new Buffer( data.captured.replace(/^data:image\/\w+;base64,/, ""), "base64" );
+ // Save to new image file
+ file = fs.openSync( filepath, "w+" );
-
- // Do Stuff with captured data uri
- console.log( data.captured.length );
-
-
-
-
-
-
+ // Output regenerated, compressed code
+ fs.write( file, buffer, 0, buffer.length, 0, function( err, data ) {
+ if ( err == null ) {
+ console.log( "Saved: http://localhost:8080/" + filepath );
+ }
+ });
});
});
View
8 lib/dmv.js
@@ -1,3 +1,7 @@
+/*! dmv - v0.1.0 - 2/28/2012
+* https://github.com/rwldrn/dmv
+* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
+
/*! dmv - v0.1.0 - 2/5/2012
* https://github.com/rwldrn/dmv
* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
@@ -68,7 +72,6 @@ var // Localize navigator for use within getUserMedia
var capture = this.canvas.toDataURL(),
image = document.querySelector( "#i_" + this.id );
- console.log( image );
if ( !image ) {
image = Operator.fixture( "img", this.id );
}
@@ -99,6 +102,7 @@ var // Localize navigator for use within getUserMedia
node.id = nodeName[0] + "_" + id;
+ console.log( document.offsetWidth );
node.style.width = "320px";
node.style.height = "280px";
@@ -155,7 +159,7 @@ var // Localize navigator for use within getUserMedia
this.listen();
},
listen: function() {
- var capture = document.querySelector("#capture");
+ var capture = document.querySelector("video");
capture.addEventListener( "click", DMV.operator.capture.bind( DMV.operator ), false );
}
View
8 public/javascripts/dmv.js
@@ -1,3 +1,7 @@
+/*! dmv - v0.1.0 - 2/29/2012
+* https://github.com/rwldrn/dmv
+* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
+
/*! dmv - v0.1.0 - 2/28/2012
* https://github.com/rwldrn/dmv
* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
@@ -72,7 +76,6 @@ var // Localize navigator for use within getUserMedia
var capture = this.canvas.toDataURL(),
image = document.querySelector( "#i_" + this.id );
- console.log( image );
if ( !image ) {
image = Operator.fixture( "img", this.id );
}
@@ -103,6 +106,7 @@ var // Localize navigator for use within getUserMedia
node.id = nodeName[0] + "_" + id;
+ console.log( document.offsetWidth );
node.style.width = "320px";
node.style.height = "280px";
@@ -159,7 +163,7 @@ var // Localize navigator for use within getUserMedia
this.listen();
},
listen: function() {
- var capture = document.querySelector("#capture");
+ var capture = document.querySelector("video");
capture.addEventListener( "click", DMV.operator.capture.bind( DMV.operator ), false );
}
View
4 public/javascripts/dmv.min.js
@@ -1,4 +1,4 @@
-/*! dmv - v0.1.0 - 2/28/2012
+/*! dmv - v0.1.0 - 2/29/2012
* https://github.com/rwldrn/dmv
* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
-(function(a){var b=a.navigator,c=function(a){var c=b.getUserMedia||b.webkitGetUserMedia,d=b.getUserMedia?{video:!0,audio:!0}:"video audio";c.call(b,d,function(b){var c=window.webkitURL?window.webkitURL.createObjectURL(b):b;a(c)})},d,e;d=function(a,b){this.id=a,this.media=d.fixture("video",this.id),this.canvas=d.fixture("canvas"),this.context=this.canvas.getContext("2d"),this.socket=b,this.dataUri="",c(function(a){this.media.src=a,this.media.addEventListener("loadedmetadata",function(){this.media.play()}.bind(this),!1),this.media.addEventListener("timeupdate",function(){this.draw()}.bind(this),!1)}.bind(this))},d.prototype.draw=function(){this.context.drawImage(this.media,0,0,280,160)},d.prototype.capture=function(){var a=this.canvas.toDataURL(),b=document.querySelector("#i_"+this.id);console.log(b),b||(b=d.fixture("img",this.id)),b.src=a,this.socket.emit("capture",{id:this.id,captured:this.canvas.toDataURL()})},d.id=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0;return(a==="x"?b:b&3|8).toString(16)}).toUpperCase()},d.fixture=function(a,b){var c=document.querySelector("#container"),d=document.createElement(a);return d.id=a[0]+"_"+b,d.style.width="320px",d.style.height="280px",c||(c=document.body),a==="canvas"&&(d.style.display="none"),c.appendChild(d),d},d.exists=function(a){return!!document.querySelectorAll("[id$='"+a+"']").length},e={socket:null,operator:null,init:function(a){var b,c;b=localStorage.getItem("id"),b||(b=d.id(),localStorage.setItem("id",b)),e.socket=a,e.operator=new d(b,a),this.listen()},listen:function(){var a=document.querySelector("#capture");a.addEventListener("click",e.operator.capture.bind(e.operator),!1)}},a.DMV=e,a.Operator=d})(typeof exports=="object"&&exports||this)
+(function(a){var b=a.navigator,c=function(a){var c=b.getUserMedia||b.webkitGetUserMedia,d=b.getUserMedia?{video:!0,audio:!0}:"video audio";c.call(b,d,function(b){var c=window.webkitURL?window.webkitURL.createObjectURL(b):b;a(c)})},d,e;d=function(a,b){this.id=a,this.media=d.fixture("video",this.id),this.canvas=d.fixture("canvas"),this.context=this.canvas.getContext("2d"),this.socket=b,this.dataUri="",c(function(a){this.media.src=a,this.media.addEventListener("loadedmetadata",function(){this.media.play()}.bind(this),!1),this.media.addEventListener("timeupdate",function(){this.draw()}.bind(this),!1)}.bind(this))},d.prototype.draw=function(){this.context.drawImage(this.media,0,0,280,160)},d.prototype.capture=function(){var a=this.canvas.toDataURL(),b=document.querySelector("#i_"+this.id);b||(b=d.fixture("img",this.id)),b.src=a,this.socket.emit("capture",{id:this.id,captured:this.canvas.toDataURL()})},d.id=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=Math.random()*16|0;return(a==="x"?b:b&3|8).toString(16)}).toUpperCase()},d.fixture=function(a,b){var c=document.querySelector("#container"),d=document.createElement(a);return d.id=a[0]+"_"+b,console.log(document.offsetWidth),d.style.width="320px",d.style.height="280px",c||(c=document.body),a==="canvas"&&(d.style.display="none"),c.appendChild(d),d},d.exists=function(a){return!!document.querySelectorAll("[id$='"+a+"']").length},e={socket:null,operator:null,init:function(a){var b,c;b=localStorage.getItem("id"),b||(b=d.id(),localStorage.setItem("id",b)),e.socket=a,e.operator=new d(b,a),this.listen()},listen:function(){var a=document.querySelector("video");a.addEventListener("click",e.operator.capture.bind(e.operator),!1)}},a.DMV=e,a.Operator=d})(typeof exports=="object"&&exports||this)
View
2 public/stylesheets/style.css
@@ -1,5 +1,5 @@
body {
- padding: 50px;
+/* padding: 50px;*/
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}
View
4 views/index.jade
@@ -1,6 +1,2 @@
-h1= title
-
-
#operator-container
-button#capture Capture
View
1 views/layout.jade
@@ -2,6 +2,7 @@
html
head
title= title
+ meta(name="viewport", content="width=device-width, initial-scale=1")
link(rel="stylesheet", href="/stylesheets/style.css")
script(src="/socket.io/socket.io.js")
script(src="//code.jquery.com/jquery.min.js")

0 comments on commit 7cd7c43

Please sign in to comment.
Something went wrong with that request. Please try again.