Client = function (host, port) {
this.host = host;
this.port = port;
this._sock = dgram();
this.kill = function() {
this._sock.close();
};
}...
Sending OSC messages:
::
var osc = require('node-osc');
var client = new osc.Client('127.0.0.1', 3333);
client.send('/oscAddress', 200, function () {
client.kill();
});
Listening for OSC messages:
::
...function Message(address) {
this.oscType = 'message';
this.address = address;
this.args = [];
for (var i = 1; i < arguments.length; i++) {
this.append(arguments[i]);
}
}n/a
Server = function (port, host) {
var server;
events.EventEmitter.call(this);
this.port = port;
this.host = host;
this._sock = dgram();
this._sock.bind(port);
server = this;
this._sock.on('message', function (msg, rinfo) {
try {
var decoded = decode(msg);
// [<address>, <typetags>, <values>*]
}
catch (e) {
console.log('can\'t decode incoming message: ' + e.message);
}
if (decoded) {
server.emit('message', decoded, rinfo);
server.emit(decoded[0], decoded, rinfo);
}
});
this.kill = function() {
this._sock.close();
};
}...
Listening for OSC messages:
::
var osc = require('node-osc');
var oscServer = new osc.Server(3333, '0.0.0.0');
oscServer.on("message", function (msg, rinfo) {
console.log("TUIO message:");
console.log(msg);
});
Example of received TUIO (based on OSC) messages:
...Client = function (host, port) {
this.host = host;
this.port = port;
this._sock = dgram();
this.kill = function() {
this._sock.close();
};
}...
Sending OSC messages:
::
var osc = require('node-osc');
var client = new osc.Client('127.0.0.1', 3333);
client.send('/oscAddress', 200, function () {
client.kill();
});
Listening for OSC messages:
::
...send = function (message) {
var mes;
var buf;
var callback;
var args = Array.prototype.slice.call(arguments);
var last = args[args.length - 1];
if (typeof last === 'function') {
callback = args.pop();
}
else {
callback = function () {};
}
if (message instanceof Array) {
message = {
address: message[0],
args: message.splice(1)
}
}
switch (typeof message) {
case 'object':
buf = min.toBuffer(message);
this._sock.send(buf, 0, buf.length, this.port, this.host, callback);
break;
case 'string':
mes = new Message(args[0]);
for (var i = 1; i < args.length; i++) {
mes.append(args[i]);
}
buf = min.toBuffer(mes);
this._sock.send(buf, 0, buf.length, this.port, this.host, callback);
break;
default:
throw new Error('That Message Just Doesn\'t Seem Right');
}
}...
Sending OSC messages:
::
var osc = require('node-osc');
var client = new osc.Client('127.0.0.1', 3333);
client.send('/oscAddress', 200, function () {
client.kill();
});
Listening for OSC messages:
::
...function Message(address) {
this.oscType = 'message';
this.address = address;
this.args = [];
for (var i = 1; i < arguments.length; i++) {
this.append(arguments[i]);
}
}n/a
append = function (arg) {
var argOut;
switch (typeof arg) {
case 'object':
if (arg instanceof Array) {
for (var i = 0; i < arg.length; i++) {
this.append(arg[i]);
}
} else if (arg.type) {
this.args.push(arg);
} else {
throw new Error('don\'t know how to encode object ' + arg);
}
break;
case 'number':
if (Math.floor(arg) === arg) {
argOut = new Argument('integer', arg);
this.args.push(argOut);
} else {
argOut = new Argument('float', arg);
this.args.push(argOut);
}
break;
case 'string':
argOut = new Argument('string', arg);
this.args.push(argOut);
break;
default:
throw new Error('don\'t know how to encode ' + arg);
}
}n/a
Server = function (port, host) {
var server;
events.EventEmitter.call(this);
this.port = port;
this.host = host;
this._sock = dgram();
this._sock.bind(port);
server = this;
this._sock.on('message', function (msg, rinfo) {
try {
var decoded = decode(msg);
// [<address>, <typetags>, <values>*]
}
catch (e) {
console.log('can\'t decode incoming message: ' + e.message);
}
if (decoded) {
server.emit('message', decoded, rinfo);
server.emit(decoded[0], decoded, rinfo);
}
});
this.kill = function() {
this._sock.close();
};
}...
Listening for OSC messages:
::
var osc = require('node-osc');
var oscServer = new osc.Server(3333, '0.0.0.0');
oscServer.on("message", function (msg, rinfo) {
console.log("TUIO message:");
console.log(msg);
});
Example of received TUIO (based on OSC) messages:
...function EventEmitter() {
EventEmitter.init.call(this);
}n/a
function TBlob(value) { this.value = value; }n/a
function TDouble(value) { this.value = value; }n/a
function TFalse(value) { this.value = value; }n/a
function TFloat(value) { this.value = value; }n/a
function TInt(value) { this.value = value; }n/a
function TString(value) { this.value = value; }n/a
function TTime(value) { this.value = value; }n/a
function TTrue(value) { this.value = value; }n/a