diff --git a/share/web_surfaces/shared/ardour.js b/share/web_surfaces/shared/ardour.js index 68a0b3e6ab..dc17f15807 100644 --- a/share/web_surfaces/shared/ardour.js +++ b/share/web_surfaces/shared/ardour.js @@ -28,13 +28,13 @@ export class ArdourClient { this._components = []; this._connected = false; - this._channel = new MessageChannel(this._options['host'] || location.host); + this._channel = new MessageChannel(this._getOption('host', location.host)); this._channel.onMessage = (msg, inbound) => { this._handleMessage(msg, inbound); }; - if (!('components' in this._options) || this._options['components']) { + if (this._getOption('components', true)) { this._mixer = new Mixer(this._channel); this._transport = new Transport(this._channel); this._components.push(this._mixer, this._transport); @@ -60,13 +60,13 @@ export class ArdourClient { // Low level control messages flow through a WebSocket - async connect (autoReconnect) { + async connect () { this._channel.onClose = async () => { if (this._connected) { this._setConnected(false); } - if ((autoReconnect == null) || autoReconnect) { + if (this._getOption('autoReconnect', true)) { await this._sleep(1000); await this._connect(); } @@ -156,4 +156,8 @@ export class ArdourClient { return new Error(`HTTP response status ${status}`); } + _getOption (key, defaultValue) { + return key in this._options ? this._options[key] : defaultValue; + } + }