-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
54 lines (42 loc) · 1.24 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Static HTTP Server
*
* Create a static file server instance to serve files
* and folder in the './public' folder
*/
// modules
var static = require( 'node-static' ),
port = 8080,
http = require( 'http' ),
DEBUG = true;
// config
var file = new static.Server( './public', {
cache: 0,
gzip: true
} );
var osc = require('node-osc'),
io = require('socket.io').listen(8081);
var oscServer, oscClient;
io.sockets.on('connection', function (socket) {
socket.on("config", function (obj) {
console.log("config message received:", obj);
oscServer = new osc.Server(obj.server.port, obj.server.host);
oscClient = new osc.Client(obj.client.host, obj.client.port);
oscClient.send('/status', 'livewriting lauhced');
oscServer.on('message', function(msg, rinfo) {
if(DEBUG)console.log("App says", msg);
socket.emit("message2", msg);
});
});
socket.on("message", function (obj) {
oscClient.send(obj);
if(DEBUG)console.log("live writing says", obj);
});
});
// serve
http.createServer( function ( request, response ) {
request.addListener( 'end', function () {
file.serve( request, response );
} ).resume();
} ).listen( port );
console.log("listening to port ",port);