headless: make widgets sync between clients only if their targets match

This commit is contained in:
jean-emmanuel 2016-09-30 09:28:40 +02:00
parent da0ed17f23
commit 6d35679719
2 changed files with 11 additions and 2 deletions

View file

@ -11,7 +11,8 @@ module.exports = {
// fetch ids corresponding to the osc path
var path = data.path,
pathref = path,
args = data.args
args = data.args,
target = data.target
if (typeof data.args == 'object') {
for (var i=data.args.length-1;i>=0;i--) {
@ -31,7 +32,13 @@ module.exports = {
else if (args.length==1) args = args[0]
for (i in WIDGETS_BY_PATH[pathref]) {
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,false,true)
// if the message target is provided (when message comes from another client connected to the same server)
// then we only update the widgets that have the same target
// compare arrays using > and < operators (both false = equality)
if (!target || !(WIDGETS_BY_PATH[pathref][i].target < target || WIDGETS_BY_PATH[pathref][i].target > target)) {
// update matching widgets
if (WIDGETS_BY_PATH[pathref][i]) WIDGETS_BY_PATH[pathref][i].setValue(args,false,true)
}
}

View file

@ -155,6 +155,8 @@ module.exports.widgets = function(data,parent) {
// create widget
var widgetInner = createWidget[widgetData.type](widgetData,widgetContainer)
// store widgets target
widgetInner.target = widgetData.target
widgetContainer[0].appendChild(widgetInner[0])