Skip to content

Instantly share code, notes, and snippets.

@joshuajnoble
Created February 27, 2017 11:52
Show Gist options
  • Save joshuajnoble/1b2085798fbb472bbfc77c8f2ecb7297 to your computer and use it in GitHub Desktop.
Save joshuajnoble/1b2085798fbb472bbfc77c8f2ecb7297 to your computer and use it in GitHub Desktop.
// before running this you must do:
// npm install
var express = require('express');
var app = express();
var serveIndex = require('serve-index');
var serveStatic = require('serve-static');
var http = require('http').Server(app);
var io = require('socket.io')(http);
var socketNames = [];
app.use(serveStatic(__dirname));
app.use('/', serveIndex(__dirname));
http.listen(3000, function(){
console.log('listening on *:3000');
});
var osc = require('node-osc');
// this will need to be changed to run on the correct
var oscServer = new osc.Server(12000, "localhost");
var oscClient = new osc.Client("localhost", 32000);
var isConnected = false;
// right now just listening for a request for a list of clients
oscServer.on('message', function (msg) {
if(msg.toString() == "/clients") {
var allsockets = socketNames.join();
oscClient.send(allsockets);
}
});
io.sockets.on('connection', function (socket) {
console.log('connection');
socket.on("config", function (obj)
{
isConnected = true;
socket.emit("connected", 1);
});
socket.on("message", function (obj) {
if( socketNames.indexOf(obj[0]) == -1 ) {
socketNames.push(obj[0]);
}
oscClient.send.apply(oscClient, obj);
});
socket.on('disconnect', function(){
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment