main: stop using electron-specific api : always use express server and use electron as a normal browser/client
This commit is contained in:
parent
d2791758f7
commit
bde96d5d3b
7 changed files with 359 additions and 400 deletions
120
app/main/osc.js
120
app/main/osc.js
|
|
@ -1,64 +1,64 @@
|
|||
var osc = require('node-osc')
|
||||
var osc = require('node-osc'),
|
||||
ipc = require('./server-express').ipc,
|
||||
settings = require('./settings'),
|
||||
oscInPort = settings.read('oscInPort'),
|
||||
debug = settings.read('debug')
|
||||
|
||||
module.exports = function(ipc, settings) {
|
||||
if (oscInPort) {
|
||||
|
||||
var inPort = settings.read('oscInPort'),
|
||||
debug = settings.read('debug')
|
||||
|
||||
if (inPort) {
|
||||
var oscServer = new osc.Server(inPort, '127.0.0.1')
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
send: function(host,port,path,args,precision) {
|
||||
|
||||
var client = new osc.Client(host, port)
|
||||
|
||||
client._sock.bind({exclusive:false,reuseAddr:true,port:inPort},function(){
|
||||
|
||||
|
||||
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 (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 == '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)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
var oscServer = new osc.Server(oscInPort, '127.0.0.1')
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
send: function(host,port,path,args,precision) {
|
||||
|
||||
var client = new osc.Client(host, port)
|
||||
|
||||
client._sock.bind({exclusive:false,reuseAddr:true,port:oscInPort},function(){
|
||||
|
||||
|
||||
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 (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 == '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)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue