From b4e52d654b6450a77ad74e541254d20daf990724 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Tue, 15 Dec 2020 12:36:06 +0100 Subject: [PATCH] Pass WebSocket data without additional signal connection --- clapper_src/player.js | 30 +++++++++++++++--------------- clapper_src/playerBase.js | 12 ++---------- clapper_src/webserver.js | 19 +++++++------------ 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/clapper_src/player.js b/clapper_src/player.js index e5884192..dc0091d6 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -251,6 +251,21 @@ class ClapperPlayer extends PlayerBase this[action](); } + receiveWs(action, value) + { + switch(action) { + case 'toggle_play': + case 'play': + case 'pause': + case 'set_media': + this[action](value); + break; + default: + super.receiveWs(action, value); + break; + } + } + _setHideCursorTimeout() { this._clearTimeout('hideCursor'); @@ -642,21 +657,6 @@ class ClapperPlayer extends PlayerBase return true; } - _onWsData(server, action, value) - { - switch(action) { - case 'toggle_play': - case 'play': - case 'pause': - case 'set_media': - this[action](value); - break; - default: - super._onWsData(server, action, value); - break; - } - } - _onCloseRequest(window) { this._performCloseCleanup(window); diff --git a/clapper_src/playerBase.js b/clapper_src/playerBase.js index 3e24179a..7708539c 100644 --- a/clapper_src/playerBase.js +++ b/clapper_src/playerBase.js @@ -69,7 +69,6 @@ class ClapperPlayerBase extends GstPlayer.Player this.visualization_enabled = false; this.webserver = null; - this.websocketSignal = null; this.set_all_plugins_ranks(); this.set_initial_config(); @@ -189,7 +188,7 @@ class ClapperPlayerBase extends GstPlayer.Player this.webserver.sendMessage({ action, value }); } - _onWsData(server, action, value) + receiveWs(action, value) { debug(`unhandled WebSocket action: ${action}`); } @@ -300,16 +299,9 @@ class ClapperPlayerBase extends GstPlayer.Player this.webserver = new WebServer(settings.get_int('webserver-port')); this.webserver.startListening(); - - if(!this.websocketSignal) { - this.websocketSignal = this.webserver.connect( - 'websocket-data', this._onWsData.bind(this) - ); - } + this.webserver.passMsgData = this.receiveWs.bind(this); } else if(this.webserver) { - this.webserver.disconnect(this.websocketSignal); - this.websocketSignal = null; this.webserver.stopListening(); } break; diff --git a/clapper_src/webserver.js b/clapper_src/webserver.js index 2548003a..626a110e 100644 --- a/clapper_src/webserver.js +++ b/clapper_src/webserver.js @@ -4,17 +4,8 @@ const Debug = imports.clapper_src.debug; let { debug } = Debug; -var WebServer = GObject.registerClass({ - Signals: { - 'websocket-data': { - flags: GObject.SignalFlags.RUN_FIRST, - param_types: [ - GObject.TYPE_STRING, - GObject.TYPE_INT || GObject.TYPE_STRING - ] - } - } -}, class ClapperWebServer extends Soup.Server +var WebServer = GObject.registerClass( +class ClapperWebServer extends Soup.Server { _init(port) { @@ -96,6 +87,10 @@ var WebServer = GObject.registerClass({ } } + passMsgData(action, value) + { + } + _closeCleanup() { while(this.wsConns.length) { @@ -140,7 +135,7 @@ var WebServer = GObject.registerClass({ if(!parsedMsg || !parsedMsg.action) return debug('no "action" in parsed WebSocket message'); - this.emit('websocket-data', parsedMsg.action, parsedMsg.value || 0); + this.passMsgData(parsedMsg.action, parsedMsg.value || 0); } _onWsClosed(connection)