mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-30 07:42:23 +02:00
Integrate basic web server functionality into player
This commit is contained in:
@@ -639,6 +639,22 @@ class ClapperPlayer extends PlayerBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onWsData(server, action, value)
|
||||||
|
{
|
||||||
|
switch(action) {
|
||||||
|
case 'toggle-play':
|
||||||
|
this.toggle_play();
|
||||||
|
break;
|
||||||
|
case 'play':
|
||||||
|
case 'pause':
|
||||||
|
this[action]();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
super._onWsData(server, action, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_onCloseRequest(window)
|
_onCloseRequest(window)
|
||||||
{
|
{
|
||||||
this._performCloseCleanup(window);
|
this._performCloseCleanup(window);
|
||||||
|
@@ -2,6 +2,8 @@ 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;
|
||||||
|
|
||||||
|
let WebServer;
|
||||||
|
|
||||||
/* PlayFlags are not exported through GI */
|
/* PlayFlags are not exported through GI */
|
||||||
Gst.PlayFlags = {
|
Gst.PlayFlags = {
|
||||||
VIDEO: 1,
|
VIDEO: 1,
|
||||||
@@ -66,6 +68,9 @@ class ClapperPlayerBase extends GstPlayer.Player
|
|||||||
this.state = GstPlayer.PlayerState.STOPPED;
|
this.state = GstPlayer.PlayerState.STOPPED;
|
||||||
this.visualization_enabled = false;
|
this.visualization_enabled = false;
|
||||||
|
|
||||||
|
this.webserver = null;
|
||||||
|
this.websocketSignal = null;
|
||||||
|
|
||||||
this.set_all_plugins_ranks();
|
this.set_all_plugins_ranks();
|
||||||
this.set_initial_config();
|
this.set_initial_config();
|
||||||
this.set_and_bind_settings();
|
this.set_and_bind_settings();
|
||||||
@@ -89,6 +94,7 @@ class ClapperPlayerBase extends GstPlayer.Player
|
|||||||
'audio-offset',
|
'audio-offset',
|
||||||
'subtitle-offset',
|
'subtitle-offset',
|
||||||
'play-flags',
|
'play-flags',
|
||||||
|
'webserver-enabled',
|
||||||
];
|
];
|
||||||
|
|
||||||
for(let key of settingsToSet)
|
for(let key of settingsToSet)
|
||||||
@@ -175,6 +181,11 @@ class ClapperPlayerBase extends GstPlayer.Player
|
|||||||
this.widget.queue_render();
|
this.widget.queue_render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onWsData(server, action, value)
|
||||||
|
{
|
||||||
|
debug(`unhandled WebSocket action: ${action}`);
|
||||||
|
}
|
||||||
|
|
||||||
_onSettingsKeyChanged(settings, key)
|
_onSettingsKeyChanged(settings, key)
|
||||||
{
|
{
|
||||||
let root, value, action;
|
let root, value, action;
|
||||||
@@ -267,6 +278,29 @@ class ClapperPlayerBase extends GstPlayer.Player
|
|||||||
this.pipeline.flags = settingsFlags;
|
this.pipeline.flags = settingsFlags;
|
||||||
debug(`changed play flags: ${initialFlags} -> ${settingsFlags}`);
|
debug(`changed play flags: ${initialFlags} -> ${settingsFlags}`);
|
||||||
break;
|
break;
|
||||||
|
case 'webserver-enabled':
|
||||||
|
const webserverEnabled = settings.get_boolean(key);
|
||||||
|
|
||||||
|
if(webserverEnabled) {
|
||||||
|
if(!WebServer) {
|
||||||
|
/* Probably most users will not use this,
|
||||||
|
* so conditional import for faster startup */
|
||||||
|
WebServer = imports.clapper_src.webserver.WebServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!this.webserver)
|
||||||
|
this.webserver = new WebServer(settings.get_int('webserver-port'));
|
||||||
|
|
||||||
|
this.webserver.startListening();
|
||||||
|
this.websocketSignal = this.webserver.connect(
|
||||||
|
'websocket-data', this._onWsData.bind(this)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if(this.webserver) {
|
||||||
|
this.webserver.disconnect(this.websocketSignal);
|
||||||
|
this.webserver.stopListening();
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -49,6 +49,16 @@
|
|||||||
<summary>The subtitles font description</summary>
|
<summary>The subtitles font description</summary>
|
||||||
</key>
|
</key>
|
||||||
|
|
||||||
|
<!-- Network -->
|
||||||
|
<key name="webserver-enabled" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Enable WebSocket server for remote playback control</summary>
|
||||||
|
</key>
|
||||||
|
<key name="webserver-port" type="i">
|
||||||
|
<default>6446</default>
|
||||||
|
<summary>Listening port to use for incoming WebSocket connections</summary>
|
||||||
|
</key>
|
||||||
|
|
||||||
<!-- Tweaks -->
|
<!-- Tweaks -->
|
||||||
<key name="dark-theme" type="b">
|
<key name="dark-theme" type="b">
|
||||||
<default>true</default>
|
<default>true</default>
|
||||||
|
Reference in New Issue
Block a user