Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got up to a point where the node server serves up a config page and a…
…cts as mediator between LiveOSC and Web.
- Loading branch information
Andrew Hao
committed
Sep 22, 2011
1 parent
5a1a9f0
commit 300a4c7
Showing
7 changed files
with
610 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,86 @@ | ||
// import module | ||
// also req: jade | ||
var osc = require('osc4node'); | ||
var express = require('express'); | ||
var sys = require('sys'); | ||
|
||
SERVER_PORT = 9000 | ||
CLIENT_PORT = 9001 | ||
|
||
SERVER_PORT = 9001 | ||
CLIENT_PORT = 9000 | ||
|
||
// create osc server and client | ||
var oscServer = new osc.Server(SERVER_PORT, 'localhost') | ||
, oscClient = new osc.Client('localhost', CLIENT_PORT); | ||
|
||
debugger; | ||
console.log('OSC Server set up, listening on port ' + SERVER_PORT); | ||
console.log('OSC Client set up, listening on port ' + CLIENT_PORT); | ||
|
||
// create osc message | ||
var message = new osc.Message('/live/tempo', '123.00'); | ||
sys.puts("here"); | ||
|
||
// send | ||
var message = new osc.Message('/live/time'); | ||
sys.puts("sending message" + sys.inspect(message)); | ||
oscServer.send(message, oscClient); | ||
sys.puts("heree"); | ||
|
||
// oscServer dispatches 'oscmessage' event when receives the message. | ||
// so we attach handler on the event for global message handling. | ||
oscServer.on('oscmessage', function(msg, rinfo) { | ||
console.log(msg); | ||
var web = express.createServer(); | ||
|
||
web.configure(function(){ | ||
web.set('views', __dirname + '/views'); | ||
web.set('view engine', 'jade'); | ||
web.use(express.bodyParser()); | ||
web.use(express.methodOverride()); | ||
web.use(web.router); | ||
web.use(express.static(__dirname + '/public')); | ||
}); | ||
|
||
web.get('/', function(req, res) { | ||
res.render('index', { | ||
title: 'mmtss' | ||
}); | ||
}); | ||
|
||
var io = require('socket.io').listen(web); | ||
web.listen(3000, 'localhost'); | ||
console.log('Web server listening on %s:%d', 'localhost', 3000); | ||
|
||
/** | ||
* We define our own message syntax: | ||
* {address {str} | ||
* type {str: i|f|s|a | ||
* args: [] tuples: [<val, type>] | ||
*/ | ||
sendMessage = function(msg) { | ||
var args = msg.args; | ||
var address = msg.address; | ||
var typ = msg.type; | ||
|
||
var param = null; | ||
|
||
if (typ == 'i') { | ||
param = parseInt(args); | ||
} else if (typ == 'f') { | ||
param = parseFloat(args); | ||
} else if (typ == 's') { | ||
param = msg.args | ||
} | ||
|
||
var oscMsg = new osc.Message(address, param) | ||
oscServer.send(oscMsg, oscClient); | ||
}; | ||
|
||
|
||
io.sockets.on('connection', function(socket) { | ||
sys.puts('Web browser connected'); | ||
socket.send('hey, you connected to me the server.'); | ||
socket.on('message', function(msg) { | ||
sys.puts("receiving from browser: " + msg); | ||
msg = JSON.parse(msg); | ||
console.log('msg rcv from client was: ' + sys.inspect(msg)); | ||
sendMessage(msg); | ||
}); | ||
|
||
oscServer.on('oscmessage', function(msg, rinfo) { | ||
sys.puts(sys.inspect(msg)); | ||
//debugger; | ||
socket.send('OSCMSG' + sys.inspect(msg)); | ||
}); | ||
|
||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.