mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-29 23:32:04 +02:00
Add logic responsible for starting web app
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const { Gio, GLib, GObject, Gst, GstPlayer, Gtk } = imports.gi;
|
||||
const Debug = imports.clapper_src.debug;
|
||||
const Misc = imports.clapper_src.misc;
|
||||
const { WebApp } = imports.clapper_src.webApp;
|
||||
|
||||
let WebServer;
|
||||
|
||||
@@ -69,6 +70,7 @@ class ClapperPlayerBase extends GstPlayer.Player
|
||||
this.visualization_enabled = false;
|
||||
|
||||
this.webserver = null;
|
||||
this.webapp = null;
|
||||
|
||||
this.set_all_plugins_ranks();
|
||||
this.set_initial_config();
|
||||
@@ -93,7 +95,7 @@ class ClapperPlayerBase extends GstPlayer.Player
|
||||
'audio-offset',
|
||||
'subtitle-offset',
|
||||
'play-flags',
|
||||
'webserver-enabled',
|
||||
'webserver-enabled'
|
||||
];
|
||||
|
||||
for(let key of settingsToSet)
|
||||
@@ -286,7 +288,8 @@ class ClapperPlayerBase extends GstPlayer.Player
|
||||
debug(`changed play flags: ${initialFlags} -> ${settingsFlags}`);
|
||||
break;
|
||||
case 'webserver-enabled':
|
||||
const webserverEnabled = settings.get_boolean(key);
|
||||
case 'webapp-enabled':
|
||||
const webserverEnabled = settings.get_boolean('webserver-enabled');
|
||||
|
||||
if(webserverEnabled) {
|
||||
if(!WebServer) {
|
||||
@@ -295,13 +298,28 @@ class ClapperPlayerBase extends GstPlayer.Player
|
||||
WebServer = imports.clapper_src.webServer.WebServer;
|
||||
}
|
||||
|
||||
if(!this.webserver)
|
||||
if(!this.webserver) {
|
||||
this.webserver = new WebServer(settings.get_int('webserver-port'));
|
||||
|
||||
this.webserver.passMsgData = this.receiveWs.bind(this);
|
||||
}
|
||||
this.webserver.startListening();
|
||||
this.webserver.passMsgData = this.receiveWs.bind(this);
|
||||
|
||||
const webappEnabled = settings.get_boolean('webapp-enabled');
|
||||
|
||||
if(!this.webapp && !webappEnabled)
|
||||
break;
|
||||
|
||||
if(webappEnabled) {
|
||||
if(!this.webapp)
|
||||
this.webapp = new WebApp();
|
||||
|
||||
this.webapp.startRemoteApp();
|
||||
}
|
||||
else
|
||||
this.webapp.stopRemoteApp();
|
||||
}
|
||||
else if(this.webserver) {
|
||||
/* remote app will close too when connection is lost */
|
||||
this.webserver.stopListening();
|
||||
}
|
||||
break;
|
||||
|
@@ -1,9 +1,6 @@
|
||||
const { GObject } = imports.gi;
|
||||
const Misc = imports.clapper_src.misc;
|
||||
const { WebClient } = imports.clapper_src.webClient;
|
||||
|
||||
let { settings } = Misc;
|
||||
|
||||
var PlayerRemote = GObject.registerClass(
|
||||
class ClapperPlayerRemote extends GObject.Object
|
||||
{
|
||||
@@ -11,7 +8,7 @@ class ClapperPlayerRemote extends GObject.Object
|
||||
{
|
||||
super._init();
|
||||
|
||||
this.webclient = new WebClient(settings.get_int('webserver-port'));
|
||||
this.webclient = new WebClient();
|
||||
}
|
||||
|
||||
set_playlist(playlist)
|
||||
|
@@ -95,16 +95,15 @@ class ClapperNetworkPage extends PrefsBase.Grid
|
||||
{
|
||||
super._init();
|
||||
|
||||
let checkButton;
|
||||
let spinButton;
|
||||
|
||||
this.addTitle('Client');
|
||||
this.addPlayFlagCheckButton('Progressive download buffering', Gst.PlayFlags.DOWNLOAD);
|
||||
|
||||
this.addTitle('Server');
|
||||
checkButton = this.addCheckButton('Allow remote control of the player', 'webserver-enabled');
|
||||
spinButton = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port');
|
||||
checkButton.bind_property('active', spinButton, 'visible', GObject.BindingFlags.SYNC_CREATE);
|
||||
let webServer = this.addCheckButton('Control player remotely', 'webserver-enabled');
|
||||
let serverPort = this.addSpinButton('Listening port', 1024, 65535, 'webserver-port');
|
||||
webServer.bind_property('active', serverPort, 'visible', GObject.BindingFlags.SYNC_CREATE);
|
||||
//let webApp = this.addCheckButton('Run built-in web application', 'webapp-enabled');
|
||||
//webServer.bind_property('active', webApp, 'visible', GObject.BindingFlags.SYNC_CREATE);
|
||||
}
|
||||
});
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
const { Soup, GObject } = imports.gi;
|
||||
const { Gio, GObject, Soup } = imports.gi;
|
||||
const Debug = imports.clapper_src.debug;
|
||||
const Misc = imports.clapper_src.misc;
|
||||
const WebHelpers = imports.clapper_src.webHelpers;
|
||||
|
||||
let { debug } = Debug;
|
||||
let { settings } = Misc;
|
||||
|
||||
var WebClient = GObject.registerClass(
|
||||
class ClapperWebClient extends Soup.Session
|
||||
@@ -16,15 +18,16 @@ class ClapperWebClient extends Soup.Session
|
||||
|
||||
this.wsConn = null;
|
||||
|
||||
this.connectWebsocket(port);
|
||||
this.connectWebsocket();
|
||||
}
|
||||
|
||||
connectWebsocket(port)
|
||||
connectWebsocket()
|
||||
{
|
||||
if(this.wsConn)
|
||||
return;
|
||||
|
||||
let message = Soup.Message.new('GET', `ws://127.0.0.1:${port}/websocket`);
|
||||
const port = settings.get_int('webserver-port');
|
||||
const message = Soup.Message.new('GET', `ws://127.0.0.1:${port}/websocket`);
|
||||
this.websocket_connect_async(message, null, null, null, this._onWsConnect.bind(this));
|
||||
|
||||
debug('connecting WebSocket to Clapper app');
|
||||
@@ -78,6 +81,7 @@ class ClapperWebClient extends Soup.Session
|
||||
_onWsClosed(connection)
|
||||
{
|
||||
debug('closed WebSocket connection');
|
||||
this.wsConn = null;
|
||||
|
||||
this.passMsgData('close');
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ class ClapperWebServer extends Soup.Server
|
||||
if(isListening) {
|
||||
const uris = this.get_uris();
|
||||
const usedPort = uris[0].get_port();
|
||||
debug(`WebSocket server listening on port: ${usedPort}`);
|
||||
debug(`WebSocket server started listening on port: ${usedPort}`);
|
||||
}
|
||||
else {
|
||||
debug(new Error('WebSocket server could not start listening'));
|
||||
|
@@ -58,6 +58,10 @@
|
||||
<default>6446</default>
|
||||
<summary>Listening port to use for incoming WebSocket connections</summary>
|
||||
</key>
|
||||
<key name="webapp-enabled" type="b">
|
||||
<default>false</default>
|
||||
<summary>Run built-in broadway based web application</summary>
|
||||
</key>
|
||||
|
||||
<!-- Tweaks -->
|
||||
<key name="dark-theme" type="b">
|
||||
|
Reference in New Issue
Block a user