Permalink
Browse files

Initial commit, ported platoon to dmv

  • Loading branch information...
0 parents commit 41b3b132ddcf12b6054007e0b3fd7f91df5154fb @rwaldron rwaldron committed Feb 14, 2012
Showing 2,514 changed files with 271,388 additions and 0 deletions.
@@ -0,0 +1,3 @@
+.DS_Store
+*.sublime-*
+dist/
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Rick Waldron, Wes Bos
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,42 @@
+# DMV
+
+Node.js powered, WebRTC Delivered video chat. [Canary](http://tools.google.com/dlpage/chromesxs) and [Opera](http://dev.opera.com/articles/view/labs-more-fun-using-the-web-with-getusermedia-and-native-pages/)
+
+
+Dependency: `grunt`
+
+```bash
+$ npm install grunt -g
+```
+
+
+Dependency: npm modules
+
+```bash
+$ npm install
+```
+
+
+Verify and Build code with:
+
+```bash
+$ grunt
+```
+
+Run Application with:
+
+```bash
+$ node app
+```
+
+
+
+<img src="http://gyazo.com/371f1171d2e19208f64adbbecb38b15d.png">
+
+
+
+
+
+Built With: grunt, express, socket.io and love
+
+All code _must_ confirm to https://github.com/rwldrn/idiomatic.js
66 app.js
@@ -0,0 +1,66 @@
+var express = require("express"),
+ socket = require("socket.io");
+
+var app = express.createServer(),
+ io = socket.listen( app );
+
+// Express app Configuration
+app.configure(function() {
+ // Uses Express defaults
+ app.set( "views", __dirname + "/views" );
+ app.set( "view engine", "jade" );
+ app.use( express.bodyParser() );
+ app.use( express.methodOverride() );
+ app.use( app.router );
+ app.use( express.static(__dirname + "/public") );
+});
+
+// Routes
+app.get( "/", function( req, res ) {
+ res.render( "index", {
+ title: "DMV"
+ });
+});
+
+// Connection Pool
+var connections = {
+ // uid: object
+};
+
+io.set( "log level", 1 );
+// When socket is connected, initialize new unit in dmv,
+// begin relay of WebRTC captures
+io.sockets.on( "connection", function( client ) {
+
+ // Receive "init" events for new units,
+ // dispatch "initialized" with any instructions
+ client.on( "init", function( data ) {
+ // Contains a connection uid to add to the pool
+ // console.log( data );
+
+ connections[ data.id ] = true;
+
+ // Emit "initialized" notice to all other connections,
+ // Will create new unit and output canvas
+ io.sockets.emit( "initialized", data );
+ });
+
+ client.on( "capture", function( data ) {
+
+
+
+
+
+ // Do Stuff with captured data uri
+ console.log( data.captured.length );
+
+
+
+
+
+
+ });
+});
+
+app.listen(3000);
+console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
@@ -0,0 +1,58 @@
+/*global config:true, task:true*/
+config.init({
+ pkg: '<json:package.json>',
+ meta: {
+ banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
+ '<%= template.today("m/d/yyyy") %>\n' +
+ '<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
+ '* Copyright (c) <%= template.today("yyyy") %> <%= pkg.author.name %>;' +
+ ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
+ },
+ concat: {
+ 'dist/dmv.js': ['<banner>', '<file_strip_banner:lib/dmv.js>'],
+ 'public/javascripts/dmv.js': ['<banner>', '<file_strip_banner:lib/dmv.js>']
+ },
+ min: {
+ 'dist/dmv.min.js': ['<banner>', 'dist/dmv.js'],
+ 'public/javascripts/dmv.min.js': ['<banner>', 'public/javascripts/dmv.js']
+ },
+ test: {
+ files: ['test/**/*.js']
+ },
+ lint: {
+ files: ['grunt.js', 'lib/**/*.js', 'test/**/*.js']
+ },
+ watch: {
+ files: '<config:lint.files>',
+ tasks: 'lint test'
+ },
+ jshint: {
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ browser: true
+ },
+ globals: {
+ navigator: true,
+ requestAnimationFrame: true,
+ jQuery: true,
+ io: true,
+ global: true,
+ exports: true,
+ module: true,
+ console: true
+ }
+ },
+ uglify: {}
+});
+
+// Default task.
+task.registerTask('default', 'lint test concat min');
@@ -0,0 +1,166 @@
+/*! dmv - v0.1.0 - 2/5/2012
+* https://github.com/rwldrn/dmv
+* Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>; Licensed MIT */
+
+(function( exports ) {
+
+var // Localize navigator for use within getUserMedia
+ navigator = exports.navigator,
+
+ // Create a reasonable getUserMedia shim that covers support for the two existing
+ // getUserMedia implementations. Thanks to Mike Taylr's http://miketaylr.com/photobooth/
+ // for helping to outline proper Opera support
+ getUserMedia = function( callback ) {
+ var getMedia = navigator.getUserMedia || navigator.webkitGetUserMedia,
+ media = navigator.getUserMedia ? { video: true, audio: true } : "video audio";
+
+ getMedia.call( navigator, media, function( data ) {
+ var stream = window.webkitURL ? window.webkitURL.createObjectURL( data ) : data;
+
+ callback( stream );
+ });
+ },
+
+ // Program initializers
+ Operator, DMV;
+
+ // ---- Program ---- //
+
+ // Operator Constructor
+ Operator = function( id, socket ) {
+
+ this.id = id;
+
+ // This Operator's video
+ this.media = Operator.fixture( "video", this.id );
+
+ // This Operator's canvas
+ this.canvas = Operator.fixture("canvas");
+ this.context = this.canvas.getContext("2d");
+
+ this.socket = socket;
+
+ // Store datauri's received from stream
+ this.dataUri = "";
+
+ getUserMedia(function( stream ) {
+ // Attach user media stream to video container source
+ this.media.src = stream;
+
+ // When video signals that it has loadedmetadata, begin "playing"
+ this.media.addEventListener( "loadedmetadata", function() {
+ this.media.play();
+ }.bind(this), false);
+
+ this.media.addEventListener( "timeupdate", function() {
+ this.draw();
+ }.bind(this), false);
+
+ }.bind(this));
+ };
+
+ Operator.prototype.draw = function() {
+ // Draw current video frame to the canvas
+ this.context.drawImage( this.media, 0, 0, 280, 160 );
+ };
+
+ Operator.prototype.capture = function() {
+ var capture = this.canvas.toDataURL(),
+ image = document.querySelector( "#i_" + this.id );
+
+ console.log( image );
+ if ( !image ) {
+ image = Operator.fixture( "img", this.id );
+ }
+
+ image.src = capture;
+
+ // Dispatch a "capture" event to the socket
+ this.socket.emit( "capture", {
+ id: this.id,
+ captured: this.canvas.toDataURL()
+ });
+ };
+
+ // Static Operator functions
+ // Operator.id()
+ // Returns a pretty damn unique id
+ Operator.id = function() {
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function( chr ) {
+ var rnd = Math.random() * 16 | 0;
+ return ( chr === "x" ? rnd : (rnd & 0x3 | 0x8) ).toString( 16 );
+ }).toUpperCase();
+ };
+
+ // Create an HTML element fixture
+ Operator.fixture = function( nodeName, id ) {
+ var container = document.querySelector("#container"),
+ node = document.createElement( nodeName );
+
+ node.id = nodeName[0] + "_" + id;
+
+ node.style.width = "320px";
+ node.style.height = "280px";
+
+ // TODO: make this definable
+ if ( !container ) {
+ container = document.body;
+ }
+
+ if ( nodeName === "canvas" ) {
+ node.style.display = "none";
+ }
+
+ container.appendChild( node );
+
+ return node;
+ };
+
+ Operator.exists = function( id ) {
+ return !!document.querySelectorAll( "[id$='" + id + "']" ).length;
+ };
+
+
+ DMV = {
+
+ socket: null,
+
+ operator: null,
+
+ // Entry point:
+ // creates new id,
+ // stores id,
+ // stores reference to socket
+ // sets up socket listeners
+ // emits "init" event to socket
+ init: function( socket ) {
+ var id, op;
+
+ // Check to see if an Id exists in storage...
+ id = localStorage.getItem("id");
+
+ // If not, then generate id for for newly initialized Operator
+ // Store id locally to keep track of repeat visitors
+ if ( !id ) {
+ id = Operator.id();
+ localStorage.setItem( "id", id );
+ }
+
+ DMV.socket = socket;
+
+ DMV.operator = new Operator( id, socket );
+
+ this.listen();
+ },
+ listen: function() {
+ var capture = document.querySelector("#capture");
+
+ capture.addEventListener( "click", DMV.operator.capture.bind( DMV.operator ), false );
+ }
+ };
+
+ exports.DMV = DMV;
+ exports.Operator = Operator;
+
+
+} (typeof exports === "object" && exports || this) );
Oops, something went wrong.

0 comments on commit 41b3b13

Please sign in to comment.