osc: sending speed optimization: all static infos (target, address, preArgs) are cached server side to reduce network overhead
This commit is contained in:
parent
3612496693
commit
ab281dd534
8 changed files with 123 additions and 54 deletions
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
## 0.17.6
|
||||
|
||||
- main
|
||||
- osc sending speed optimization: all static infos (target, address, preArgs) are cached server side to reduce network overhead
|
||||
- bug fixes
|
||||
- launcher: link to the app's address is clickable
|
||||
- launcher: link to the app's address is clickable
|
||||
|
||||
## 0.17.5
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ var vm = require('vm'),
|
|||
fs = require('fs'),
|
||||
settings = require('./settings'),
|
||||
osc = require('./osc'),
|
||||
ipc = require('./server').ipc,
|
||||
{ipc, clients} = require('./server'),
|
||||
chokidar = require('chokidar')
|
||||
|
||||
var openedSessions = {},
|
||||
widgetHashTable = {},
|
||||
lastSavingClient
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -132,15 +133,36 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
|
||||
sessionOpened: function(data, clientId) {
|
||||
clients[clientId].broadcast.emit('stateSend')
|
||||
},
|
||||
|
||||
savingSession: function(data, clientId) {
|
||||
|
||||
lastSavingClient = clientId
|
||||
|
||||
},
|
||||
|
||||
sendOsc: function(data) {
|
||||
syncOsc: function(data, clientId) {
|
||||
|
||||
if (data.syncOnly) return
|
||||
var value = data.v,
|
||||
data = widgetHashTable[clientId][data.h]
|
||||
|
||||
data.args = data.preArgs.concat(value)
|
||||
|
||||
clients[clientId].broadcast.emit('receiveOsc', data)
|
||||
|
||||
},
|
||||
|
||||
sendOsc: function(data, clientId) {
|
||||
|
||||
|
||||
var value = data.v,
|
||||
data = widgetHashTable[clientId][data.h]
|
||||
|
||||
data.args = data.preArgs.concat(value)
|
||||
|
||||
clients[clientId].broadcast.emit('receiveOsc', data)
|
||||
|
||||
var targets = []
|
||||
|
||||
|
|
@ -148,16 +170,54 @@ module.exports = {
|
|||
if (data.target) Array.prototype.push.apply(targets, data.target)
|
||||
|
||||
|
||||
for (i in targets) {
|
||||
for (var i in targets) {
|
||||
|
||||
var host = targets[i].split(':')[0],
|
||||
port = targets[i].split(':')[1]
|
||||
|
||||
if (port) osc.send(host,port,data.address,data.args,data.precision)
|
||||
if (port) {
|
||||
|
||||
if (data.split) {
|
||||
|
||||
for (var j in data.split) {
|
||||
osc.send(host,port,data.split[j],data.args,data.precision)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
osc.send(host,port,data.address,data.args,data.precision)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
addWidget(data, clientId) {
|
||||
|
||||
if (!widgetHashTable[clientId]) {
|
||||
widgetHashTable[clientId] = {}
|
||||
}
|
||||
|
||||
widgetHashTable[clientId][data.hash] = data.data
|
||||
},
|
||||
|
||||
removeWidget(data, clientId) {
|
||||
|
||||
delete widgetHashTable[data.hash + clientId]
|
||||
|
||||
},
|
||||
|
||||
removeClientWidgets(clientId) {
|
||||
|
||||
if (widgetHashTable[clientId]) {
|
||||
delete widgetHashTable[clientId]
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
stateSave: function(data) {
|
||||
dialog.showSaveDialog(window,{title:'Save current state to preset file',defaultPath:settings.read('presetPath').replace(settings.read('presetPath').split('/').pop(),''),filters: [ { name: 'OSC Preset', extensions: ['preset'] }]},function(file){
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ var express = require('express')(),
|
|||
ioWildcard = require('socketio-wildcard')(),
|
||||
ipc = {},
|
||||
settings = require('./settings'),
|
||||
appAddresses = settings.read('appAddresses')
|
||||
appAddresses = settings.read('appAddresses'),
|
||||
clients = {}
|
||||
|
||||
express.get('/', function(req, res){
|
||||
res.sendFile(path.resolve(__dirname + '/../browser/index.html'))
|
||||
|
|
@ -34,21 +35,21 @@ ipc.send = function(name,data,clientId) {
|
|||
|
||||
var bindCallbacks = function(callbacks) {
|
||||
io.on('connection', function(socket) {
|
||||
|
||||
clients[socket.id] = socket
|
||||
|
||||
socket.on('*', function(e){
|
||||
var name = e.data[0],
|
||||
data = e.data[1]
|
||||
|
||||
if ((name=='sendOsc' && data.sync!==false) || name=='syncOsc') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('receiveOsc',data)
|
||||
}
|
||||
if (name=='sessionOpened') {
|
||||
// synchronize all other connected clients
|
||||
socket.broadcast.emit('stateSend',data)
|
||||
}
|
||||
|
||||
if (callbacks[name]) callbacks[name](data,socket.id)
|
||||
})
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
callbacks.removeClientWidgets(socket.id)
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -58,5 +59,6 @@ console.log('App available at ' + appAddresses.join(' & '))
|
|||
|
||||
module.exports = {
|
||||
ipc:ipc,
|
||||
bindCallbacks:bindCallbacks
|
||||
bindCallbacks:bindCallbacks,
|
||||
clients:clients
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
var ipc = require('./ipc')
|
||||
|
||||
var WidgetManager = function(){
|
||||
|
||||
this.widgets = {}
|
||||
|
|
@ -77,6 +79,17 @@ WidgetManager.prototype.addWidget = function(widget) {
|
|||
widget.widget.abstract = widget
|
||||
if (widget.container) widget.container[0].abstract = widget
|
||||
|
||||
ipc.send('addWidget', {
|
||||
hash:hash,
|
||||
data:{
|
||||
precision: widget.widgetData.precision,
|
||||
preArgs: widget.widgetData.preArgs,
|
||||
split: widget.split,
|
||||
target: widget.widgetData.target,
|
||||
address: widget.widgetData.address,
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.removeWidget = function(hash) {
|
||||
|
|
@ -89,6 +102,10 @@ WidgetManager.prototype.removeWidget = function(hash) {
|
|||
if (this.widgets[hash]) {
|
||||
if (this.widgets[hash].onRemove) this.widgets[hash].onRemove()
|
||||
delete this.widgets[hash]
|
||||
|
||||
ipc.send('removeWidget', {
|
||||
hash:hash
|
||||
})
|
||||
}
|
||||
if (id && this.idRoute[id].indexOf(hash) != -1) this.idRoute[id].splice(this.idRoute[id].indexOf(hash), 1)
|
||||
if (linkId && this.linkIdRoute[linkId].indexOf(hash) != -1) this.linkIdRoute[linkId].splice(this.linkIdRoute[linkId].indexOf(hash), 1)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Osc.prototype.send = function(data) {
|
|||
|
||||
if (this.syncOnly) {
|
||||
|
||||
ipc.send('syncOsc', data)
|
||||
this.sync(data)
|
||||
|
||||
} else {
|
||||
|
||||
|
|
@ -27,6 +27,12 @@ Osc.prototype.send = function(data) {
|
|||
|
||||
}
|
||||
|
||||
Osc.prototype.sync = function(data) {
|
||||
|
||||
ipc.send('syncOsc', data)
|
||||
|
||||
}
|
||||
|
||||
Osc.prototype.receive = function(data){
|
||||
|
||||
if (this.remoteControl.exists(data.address)) return this.remoteControl.exec(data.address, data.args)
|
||||
|
|
|
|||
|
|
@ -124,15 +124,21 @@ module.exports = class Push extends _widgets_base {
|
|||
|
||||
sendValue(v, norelease) {
|
||||
|
||||
var args = this.widgetData.preArgs.concat(v)
|
||||
if (norelease) {
|
||||
|
||||
osc.send({
|
||||
target: this.widgetData.target,
|
||||
address: this.widgetData.address,
|
||||
precision: this.widgetData.precision,
|
||||
args:args,
|
||||
syncOnly:norelease
|
||||
})
|
||||
osc.send({
|
||||
h: this.hash,
|
||||
v: this.value
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
osc.sync({
|
||||
h: this.hash,
|
||||
v: this.value
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,31 +26,11 @@ module.exports = class _widgets_base {
|
|||
|
||||
sendValue() {
|
||||
|
||||
var args = this.widgetData.preArgs.concat(this.value)
|
||||
|
||||
osc.send({
|
||||
target:this.widgetData.target,
|
||||
address:this.widgetData.address,
|
||||
precision:this.widgetData.precision,
|
||||
args:args,
|
||||
syncOnly:this.split?true:false
|
||||
h:this.hash,
|
||||
v:this.value
|
||||
})
|
||||
|
||||
if (this.split) {
|
||||
var n = 0
|
||||
for (i in this.split) {
|
||||
osc.send({
|
||||
target:this.widgetData.target,
|
||||
address:this.split[i],
|
||||
precision:this.widgetData.precision,
|
||||
args:this.widgetData.preArgs.concat(this.value[n]),
|
||||
sync:false
|
||||
|
||||
})
|
||||
n++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getValue() {
|
||||
|
|
|
|||
|
|
@ -111,13 +111,9 @@ module.exports = class _switchers_base extends _widgets_base {
|
|||
|
||||
sendValue() {
|
||||
|
||||
var args = this.widgetData.preArgs.concat(this.value)
|
||||
|
||||
osc.send({
|
||||
target:this.widgetData.target,
|
||||
address:this.widgetData.address,
|
||||
args:args,
|
||||
syncOnly:true
|
||||
osc.sync({
|
||||
h:this.hash,
|
||||
v:this.value
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue