osc-listeners: add support for relative address prefixed with the widget's address (#438)
This commit is contained in:
parent
a2dffa5d93
commit
ff66489eae
4 changed files with 38 additions and 6 deletions
|
|
@ -2,7 +2,9 @@ var osc = require('../../osc')
|
|||
|
||||
module.exports = class OscReceiver {
|
||||
|
||||
constructor(address, value, parent, propName) {
|
||||
constructor(options) {
|
||||
|
||||
var {prefix, address, value, parent, propName} = options
|
||||
|
||||
try {
|
||||
this.value = JSON.parse(value)
|
||||
|
|
@ -13,6 +15,7 @@ module.exports = class OscReceiver {
|
|||
this.parent = parent
|
||||
this.propNames = [propName]
|
||||
this.bindedCallback = this.callback.bind(this)
|
||||
this.prefix = ''
|
||||
this.setAddress(address)
|
||||
|
||||
}
|
||||
|
|
@ -21,10 +24,16 @@ module.exports = class OscReceiver {
|
|||
|
||||
if (this.address !== address) {
|
||||
|
||||
if (this.address) osc.off(this.address, this.bindedCallback, this.parent)
|
||||
if (this.address) osc.off(this.prefix + this.address, this.bindedCallback, this.parent)
|
||||
|
||||
this.address = address
|
||||
osc.on(this.address, this.bindedCallback, {context: this.parent})
|
||||
if (address) this.address = address
|
||||
|
||||
if (this.address[0] !== '/') {
|
||||
this.prefix = this.parent.getProp('address') || this.parent.resolveProp('address', undefined, false, this)
|
||||
if (this.prefix[this.prefix.length - 1] !== '/') this.prefix += '/'
|
||||
}
|
||||
|
||||
osc.on(this.prefix + this.address, this.bindedCallback, {context: this.parent})
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -526,7 +526,12 @@ class Widget extends EventEmitter {
|
|||
})
|
||||
|
||||
if (!this.oscReceivers[address]) {
|
||||
this.oscReceivers[address] = new OscReceiver(resolvedAddress, value, this, propName)
|
||||
this.oscReceivers[address] = new OscReceiver({
|
||||
address: resolvedAddress,
|
||||
value: value,
|
||||
parent: this,
|
||||
propName: propName
|
||||
})
|
||||
if (oscReceiverState[address]) {
|
||||
this.oscReceivers[address].value = oscReceiverState[address]
|
||||
delete oscReceiverState[address]
|
||||
|
|
@ -711,7 +716,15 @@ class Widget extends EventEmitter {
|
|||
case 'preArgs':
|
||||
case 'target':
|
||||
case 'noSync':
|
||||
if (propName == 'precision') this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0))
|
||||
if (propName === 'address') {
|
||||
for (var k in this.oscReceivers) {
|
||||
var receiver = this.oscReceivers[k]
|
||||
if (receiver.prefix !== '') {
|
||||
receiver.setAddress()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (propName === 'precision') this.precision = Math.min(20,Math.max(this.getProp('precision', undefined, false),0))
|
||||
var data = {},
|
||||
oldData = {
|
||||
preArgs: propName == 'preArgs' ? oldPropValue : this.getProp('preArgs'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue