WebSockets: improve JS client message handling code

This commit is contained in:
Luciano Iam 2020-06-01 11:11:01 +02:00 committed by Robin Gareus
parent 176d803a55
commit 8ff4bcfd68
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
6 changed files with 53 additions and 74 deletions

View file

@ -46,20 +46,18 @@ export class Mixer extends RootComponent {
if (node == StateNode.STRIP_DESCRIPTION) {
this._strips[addr] = new Strip(this, addr, val);
this.notifyObservers('strips');
return true;
} else {
const stripAddr = [addr[0]];
if (stripAddr in this._strips) {
this._strips[stripAddr].handle(node, addr, val);
} else {
return false;
return this._strips[stripAddr].handle(node, addr, val);
}
}
return true;
} else {
// all initial strip description messages have been received at this point
if (!this._ready) {
this.updateLocal('ready', true);
// passthrough by allowing to return false
}
}

View file

@ -54,13 +54,12 @@ export class Plugin extends AddressableComponent {
if (node == StateNode.STRIP_PLUGIN_PARAM_DESCRIPTION) {
this._parameters[addr] = new Parameter(this, addr, val);
this.notifyObservers('parameters');
return true;
} else {
if (addr in this._parameters) {
this._parameters[addr].handle(node, addr, val);
return this._parameters[addr].handle(node, addr, val);
}
}
return true;
} else if (node == StateNode.STRIP_PLUGIN_ENABLE) {
this.updateLocal('enable', val[0]);
return true;

View file

@ -20,6 +20,13 @@ import { AddressableComponent } from '../base/component.js';
import { Plugin } from './plugin.js';
import { StateNode } from '../base/protocol.js';
const NodeToProperty = Object.freeze({
[StateNode.STRIP_METER] : 'meter',
[StateNode.STRIP_GAIN] : 'gain',
[StateNode.STRIP_PAN] : 'pan',
[StateNode.STRIP_MUTE] : 'mute'
});
export class Strip extends AddressableComponent {
constructor (parent, addr, desc) {
@ -76,38 +83,18 @@ export class Strip extends AddressableComponent {
handle (node, addr, val) {
if (node.startsWith('strip_plugin')) {
if (node == StateNode.STRIP_PLUGIN_DESCRIPTION) {
this._plugins[addr] = new Plugin(this, addr, val);
this.notifyObservers('plugins');
return true;
} else {
const pluginAddr = [addr[0], addr[1]];
if (pluginAddr in this._plugins) {
this._plugins[pluginAddr].handle(node, addr, val);
} else {
return false;
return this._plugins[pluginAddr].handle(node, addr, val);
}
}
return true;
} else {
switch (node) {
case StateNode.STRIP_METER:
this.updateLocal('meter', val[0]);
break;
case StateNode.STRIP_GAIN:
this.updateLocal('gain', val[0]);
break;
case StateNode.STRIP_PAN:
this.updateLocal('pan', val[0]);
break;
case StateNode.STRIP_MUTE:
this.updateLocal('mute', val[0]);
break;
default:
return false;
}
return true;
} else if (node in NodeToProperty) {
this.updateLocal(NodeToProperty[node], val[0]);
return true;
}
return false;

View file

@ -19,6 +19,13 @@
import { RootComponent } from '../base/component.js';
import { StateNode } from '../base/protocol.js';
const NodeToProperty = Object.freeze({
[StateNode.TRANSPORT_TEMPO] : 'tempo',
[StateNode.TRANSPORT_TIME] : 'time',
[StateNode.TRANSPORT_ROLL] : 'roll',
[StateNode.TRANSPORT_RECORD] : 'record'
});
export class Transport extends RootComponent {
constructor (channel) {
@ -58,24 +65,12 @@ export class Transport extends RootComponent {
}
handle (node, addr, val) {
switch (node) {
case StateNode.TRANSPORT_TEMPO:
this.updateLocal('tempo', val[0]);
break;
case StateNode.TRANSPORT_TIME:
this.updateLocal('time', val[0]);
break;
case StateNode.TRANSPORT_ROLL:
this.updateLocal('roll', val[0]);
break;
case StateNode.TRANSPORT_RECORD:
this.updateLocal('record', val[0]);
break;
default:
return false;
if (node in NodeToProperty) {
this.updateLocal(NodeToProperty[node], val[0]);
return true;
}
return true;
return false;
}
}