From feeda2c19decd2e88e494c1fcc24e940472bbc11 Mon Sep 17 00:00:00 2001 From: Luciano Iam Date: Sun, 12 Apr 2020 12:07:10 +0200 Subject: [PATCH] WebSockets: avoid duplicated node+addr hash function in JS code --- share/web_surfaces/builtin/mixer-demo/js/main.js | 4 ++-- share/web_surfaces/builtin/mixer-demo/js/widget.js | 4 +++- share/web_surfaces/shared/channel.js | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/share/web_surfaces/builtin/mixer-demo/js/main.js b/share/web_surfaces/builtin/mixer-demo/js/main.js index 703448d7bc..2b8254e090 100644 --- a/share/web_surfaces/builtin/mixer-demo/js/main.js +++ b/share/web_surfaces/builtin/mixer-demo/js/main.js @@ -43,8 +43,8 @@ import { Switch, DiscreteSlider, ContinuousSlider, LogarithmicSlider, } else if (msg.node == 'strip_plugin_param_desc') { createStripPluginParam (msg.addr, ...msg.val); } else if (FEEDBACK_NODES.includes(msg.node)) { - if (widgets[[msg.node, msg.addr]]) { - widgets[[msg.node, msg.addr]].value = msg.val[0]; + if (widgets[msg.hash]) { + widgets[msg.hash].value = msg.val[0]; } } }; diff --git a/share/web_surfaces/builtin/mixer-demo/js/widget.js b/share/web_surfaces/builtin/mixer-demo/js/widget.js index 45231cff18..5d241809de 100644 --- a/share/web_surfaces/builtin/mixer-demo/js/widget.js +++ b/share/web_surfaces/builtin/mixer-demo/js/widget.js @@ -16,6 +16,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +import { nodeAddressHash } from '/shared/channel.js'; + export class Widget { constructor (node, addr, html) { @@ -39,7 +41,7 @@ export class Widget { } get hash () { - return [this.node].concat(this.addr).join('_'); + return nodeAddressHash(this.node, this.addr); } } diff --git a/share/web_surfaces/shared/channel.js b/share/web_surfaces/shared/channel.js index 4bb3c10ade..5173cf2c99 100644 --- a/share/web_surfaces/shared/channel.js +++ b/share/web_surfaces/shared/channel.js @@ -18,6 +18,10 @@ const JSON_INF = 1.0e+128; +export function nodeAddressHash(node, addr) { + return [node].concat(addr).join('_'); +} + export class MessageChannel { constructor (host) { @@ -95,7 +99,7 @@ export class Message { } get hash () { - return [this.node].concat(this.addr).join('_'); + return nodeAddressHash(this.node, this.addr); } toString () {