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