WebSockets: implement a JavaScript object-oriented client API

Replace previous callback based basic client with an easier
to use object-oriented API that further abstracts the low level
details of the WebSockets Server surface messaging protocol.

All built-in web surface demos were updated to use the new API.
This commit is contained in:
Luciano Iam 2020-05-29 11:37:34 +02:00 committed by Robin Gareus
parent 5296ed141f
commit ae4df127ad
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
18 changed files with 812 additions and 361 deletions

View file

@ -0,0 +1,72 @@
/*
* Copyright © 2020 Luciano Iam <lucianito@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import { AddressableComponent } from '../base/component.js';
import { Parameter } from './parameter.js';
import { StateNode } from '../base/protocol.js';
export class Plugin extends AddressableComponent {
constructor (parent, addr, desc) {
super(parent, addr);
this._parameters = {};
this._name = desc[0];
this._enable = false;
}
get strip () {
return this._parent;
}
get parameters () {
return Object.values(this._parameters);
}
get name () {
return this._name;
}
get enable () {
return this._enable;
}
set enable (value) {
this.updateRemote('enable', value, StateNode.STRIP_PLUGIN_ENABLE);
}
handle (node, addr, val) {
if (node.startsWith('strip_plugin_param')) {
if (node == StateNode.STRIP_PLUGIN_PARAM_DESCRIPTION) {
this._parameters[addr] = new Parameter(this, addr, val);
this.notifyObservers('parameters');
} else {
if (addr in this._parameters) {
this._parameters[addr].handle(node, addr, val);
}
}
return true;
} else if (node == StateNode.STRIP_PLUGIN_ENABLE) {
this.updateLocal('enable', val[0]);
return true;
}
return false;
}
}