Permalink
Browse files

multiplayer

  • Loading branch information...
leggetter committed Jan 30, 2013
1 parent 4864968 commit 40860821496788d7b99890784b75000cd4493e32
Showing with 37 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +1 −0 package.json
  3. +1 −0 public/index.html
  4. +18 −1 public/js/app.js
  5. +16 −0 web.js
View
@@ -1,3 +1,4 @@
*.DS_Store
node_modules
*.env
View
@@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"express": "2.5.x",
"pusher": "0.1.x"
},
"engines": {
"node": "0.8.x",
View
@@ -67,6 +67,7 @@
<script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script src="js/libs/buffer-loader.js"></script>
<script src="http://js.pusher.com/1.12/pusher.min.js"></script>
<script src="js/app.js"></script>
<script type="text/javascript">
View
@@ -1,7 +1,15 @@
(function() {
Pusher.log = function( msg ) {
if( window.console && window.console.log ) {
window.console.log( msg );
}
};
var content = $('#content');
var video = $('#webcam')[0];
var pusher = new Pusher( '4a870a0661cd8eca89c7' );
var channel = pusher.subscribe( 'private-notes' );
var resize = function() {
var w = $(this).width();
@@ -134,15 +142,24 @@
var note = {
note: source,
ready: true,
visual: $("#note" + i)
visual: $("#note" + i),
index: i
};
notes.push(note);
}
start();
}
channel.bind( 'client-note-on', handleNoteEvent );
function handleNoteEvent( data ) {
var note = notes[ data.index ];
playSound( note );
}
function playSound(obj) {
if (!obj.ready) return;
channel.trigger( 'client-note-on', { index: obj.index } );
var source = soundContext.createBufferSource();
source.buffer = obj.note.buffer;
source.connect(soundContext.destination);
View
16 web.js
@@ -1,7 +1,23 @@
var express = require( 'express' );
var Pusher = require( 'pusher' );
var app = express.createServer( express.logger() );
app.use( express.static( __dirname + '/public' ) );
app.use( express.bodyParser() );
var config = {
id: process.env.PUSHER_APP_ID,
key: process.env.PUSHER_APP_KEY,
secret: process.env.PUSHER_APP_SECRET
};
var pusher = new Pusher( config );
app.post( '/pusher/auth', function( req, res ) {
var socketId = req.body.socket_id;
var channel = req.body.channel_name;
var auth = pusher.auth( socketId, channel );
res.send( auth );
} );
var port = process.env.PORT || 5000;
app.listen( port, function() {

0 comments on commit 4086082

Please sign in to comment.