Sfoglia il codice sorgente

feat: Added config option for mediasession

Owen Diffey 2 anni fa
parent
commit
dee391413c

+ 1 - 0
.wiki/Configuration.md

@@ -73,6 +73,7 @@ Location: `frontend/dist/config/default.json`
 | `siteSettings.logo_blue` | Path to the blue logo image, by default it is `/assets/blue_wordmark.png`. |
 | `siteSettings.sitename` | Should be the name of the site. |
 | `siteSettings.github` | URL of GitHub repository, defaults to `https://github.com/Musare/MusareNode`. |
+| `siteSettings.mediasession` | Whether to enable mediasession functionality. |
 | `siteSettings.christmas` | Whether to enable christmas theming. |
 | `messages.accountRemoval` | Message to return to users on account removal. |
 | `shortcutOverrides` | Overwrite keyboard shortcuts, for example `"editSong.useAllDiscogs": { "keyCode": 68, "ctrl": true, "alt": true, "shift": false, "preventDefault": true }`. |

+ 2 - 1
frontend/dist/config/template.json

@@ -23,6 +23,7 @@
 		"logo_blue": "/assets/blue_wordmark.png",
 		"sitename": "Musare",
 		"github": "https://github.com/Musare/Musare",
+		"mediasession": false,
 		"christmas": false
 	},
 	"messages": {
@@ -38,5 +39,5 @@
 	// 	}
 	// },
 	"skipConfigVersionCheck": false,
-	"configVersion": 8
+	"configVersion": 9
 }

+ 2 - 2
frontend/src/main.js

@@ -10,7 +10,7 @@ import store from "./store";
 
 import AppComponent from "./App.vue";
 
-const REQUIRED_CONFIG_VERSION = 8;
+const REQUIRED_CONFIG_VERSION = 9;
 
 const handleMetadata = attrs => {
 	document.title = `Musare | ${attrs.title}`;
@@ -221,7 +221,7 @@ lofig.folder = "../config/default.json";
 	const websocketsDomain = await lofig.get("backend.websocketsDomain");
 	ws.init(websocketsDomain);
 
-	ms.init();
+	if (await lofig.get("siteSettings.mediasession")) ms.init();
 
 	ws.socket.on("ready", res => {
 		const { loggedIn, role, username, userId, email } = res.data;

+ 11 - 6
frontend/src/pages/Station/index.vue

@@ -940,6 +940,7 @@ export default {
 			persistentToastCheckerInterval: null,
 			persistentToasts: [],
 			partyPlaylistLock: false,
+			mediasession: false,
 			christmas: false
 		};
 	},
@@ -1072,7 +1073,7 @@ export default {
 		});
 
 		this.frontendDevMode = await lofig.get("mode");
-
+		this.mediasession = await lofig.get("siteSettings.mediasession");
 		this.christmas = await lofig.get("siteSettings.christmas");
 
 		this.socket.dispatch(
@@ -1301,8 +1302,10 @@ export default {
 	beforeUnmount() {
 		document.body.style.cssText = "";
 
-		ms.removeListeners(0);
-		ms.removeMediaSessionData(0);
+		if (this.mediasession) {
+			ms.removeListeners(0);
+			ms.removeMediaSessionData(0);
+		}
 
 		/** Reset Songslist */
 		this.updateSongsList([]);
@@ -1430,7 +1433,7 @@ export default {
 
 			clearTimeout(window.stationNextSongTimeout);
 
-			this.updateMediaSessionData(currentSong);
+			if (this.mediasession) this.updateMediaSessionData(currentSong);
 
 			this.startedAt = startedAt;
 			this.updateStationPaused(paused);
@@ -1843,7 +1846,8 @@ export default {
 			this.pauseLocalPlayer();
 		},
 		resumeLocalPlayer() {
-			this.updateMediaSessionData(this.currentSong);
+			if (this.mediasession)
+				this.updateMediaSessionData(this.currentSong);
 			if (!this.noSong) {
 				if (this.playerReady) {
 					this.player.seekTo(
@@ -1855,7 +1859,8 @@ export default {
 			}
 		},
 		pauseLocalPlayer() {
-			this.updateMediaSessionData(this.currentSong);
+			if (this.mediasession)
+				this.updateMediaSessionData(this.currentSong);
 			if (!this.noSong) {
 				this.timeBeforePause = this.getTimeElapsed();
 				if (this.playerReady) this.player.pauseVideo();