main: change main osc module to support boolean args properly, add vmodule deps to disable unsupported serialport require()

This commit is contained in:
jean-emmanuel 2016-10-11 15:31:35 +02:00
parent 7d6e724d64
commit 47285f4dea
4 changed files with 50 additions and 51 deletions

View file

@ -46,7 +46,7 @@ It relies on the use of several libraries :
- [Node.js](https://nodejs.org/)
- [Electron](http://electron.atom.io/)
- [node-osc](https://github.com/TheAlphaNerd/node-osc)
- [osc.js](https://github.com/colinbdclark/osc.js)
- [socket.io](http://socket.io)
- [browserify](http://browserify.org)
- [express](http://expressjs.com)

View file

@ -1,67 +1,65 @@
var osc = require('node-osc'),
// destroy serialport module as it's currently unsupported and would throw when required by osc
require('vmodule')('serialport', {}, {global: true})
var osc = require('osc'),
ipc = require('./server').ipc,
settings = require('./settings'),
oscInPort = settings.read('oscInPort'),
debug = settings.read('debug')
if (oscInPort) {
var oscServer = new osc.Server(oscInPort, '127.0.0.1')
var oscServer = new osc.UDPPort({
localAddress: "0.0.0.0",
localPort: oscInPort
});
oscServer.on('message', function (msg, rinfo) {
var data = {path:msg.shift(),args:msg}
if (data.args.length==1) data.args = data.args[0]
ipc.send('receiveOsc',data)
if (debug) console.log('OSC received: ',data, 'From : ' + rinfo.address + ':' + rinfo.port)
})
oscServer.on('message', function (msg, bundle, info) {
var data = {path: msg.address, args: msg.args}
if (data.args.length==1) data.args = data.args[0]
ipc.send('receiveOsc',data)
if (debug) console.log('OSC received: ',data, 'From : ' + info.address + ':' + info.port)
})
oscServer.open()
var parseArg = function(arg,precision){
if (arg==null) return null
switch (typeof arg) {
case 'number':
return {type: precision == 0 ? 'i' : 'f', value: arg}
case 'boolean':
return {type: arg ? 'T' : 'F', value: arg}
case 'object':
return {type: arg.type, value: arg.value}
default:
return {type: 'string', value:String(arg)}
}
}
module.exports = {
send: function(host,port,path,args,precision) {
var client = new osc.Client(host, port)
var message = []
client._sock.bind({exclusive:false,reuseAddr:true,port:oscInPort},function(){
if (typeof args=='object' && args!==null) {
for (i in args) {
var arg = parseArg(args[i],precision)
if (arg!=null) message.push(arg)
}
} else if (args!==null){
var arg = parseArg(args[i],precision)
if (arg!=null) message.push(arg)
}
var message = new osc.Message(path)
var numberType = precision==0?'integer':'float'
if (typeof args=='object' && args!==null) {
for (i in args) {
var arg = args[i]
if (typeof arg == 'number' && arg!==null && typeof arg != 'object') {
message.append({type:numberType,value:arg})
} else if (typeof arg == "boolean") {
message.append({type:"boolean",value:arg})
} else if (arg!==null && typeof arg != 'object'){
message.append({type:'string',value:String(arg)})
} else if (arg!==null && typeof arg == 'object' && arg.type && arg.value!=undefined) {
message.append({type:arg.type,value:arg.value})
}
}
} else if (args!==null){
if (typeof args == 'number') {
message.append({type:numberType,value:args})
} else if (typeof args == "boolean") {
message.append({type:"boolean",value:args})
} else if (typeof args == 'object' && arg.type && arg.value!=undefined) {
message.append({type:args.type,value:args.value})
} else {
message.append({type:'string',value:String(args)})
}
}
client.send(message, function () {
client.kill()
})
if (debug) console.log('OSC sent: ',{path:path,args:message.args}, 'To : ' + host + ':' + port)
})
oscServer.send({
address: path,
args: message
}, host, port);
if (debug) console.log('OSC sent: ',{path:path,args:message}, 'To : ' + host + ':' + port)
}
}

View file

@ -9,8 +9,9 @@
"email": "jeannot@ammd.net"
},
"dependencies": {
"vmodule":"1.0.1",
"electron-localshortcut":"0.6.1",
"node-osc": "2.0.3",
"osc": "2.0.3",
"yargs": "5.0.0",
"socket.io": "1.4.8",
"socket.io-client": "1.4.8",

View file

@ -35,7 +35,7 @@ It relies on the use of several libraries :
- [Node.js](https://nodejs.org/)
- [Electron](http://electron.atom.io/)
- [node-osc](https://github.com/TheAlphaNerd/node-osc)
- [osc.js](https://github.com/colinbdclark/osc.js)
- [socket.io](http://socket.io)
- [browserify](http://browserify.org)
- [express](http://expressjs.com)