Browse Source

fix: soundcloud player still didn't account well for multiple players on the same page

Kristian Vos 1 year ago
parent
commit
d42b856ee0
2 changed files with 10 additions and 5 deletions
  1. 8 5
      frontend/src/composables/useSoundcloudPlayer.ts
  2. 2 0
      frontend/src/types/global.d.ts

+ 8 - 5
frontend/src/composables/useSoundcloudPlayer.ts

@@ -243,7 +243,13 @@ export const useSoundcloudPlayer = () => {
 
 	const changeIframeUrl = url => {
 		iframeUrl.value = url;
-		if (!widgetId.value && window.soundcloudIframeLockUuid !== uuid) return; // Don't change the iframe src if the player hasn't initialized and isn't allowed to initialize yet
+		if (window.soundcloudIframeLockUuid !== uuid) {
+			// Don't change the iframe src if the player hasn't initialized and isn't allowed to initialize yet
+			if (url) window.soundcloudIframeLockUuids.add(uuid);
+			if (!window.soundcloudIframeLockUuid)
+				document.dispatchEvent(new Event("soundcloudUnlock"));
+			return;
+		}
 		soundcloudIframeElement.value.setAttribute("src", url);
 	};
 
@@ -280,8 +286,6 @@ export const useSoundcloudPlayer = () => {
 
 			window.addEventListener("message", onMessageListener);
 
-			window.soundcloudIframeLockUuids.add(uuid);
-
 			document.removeEventListener(
 				"soundcloudUnlock",
 				documentUnlockEventListener
@@ -409,8 +413,7 @@ export const useSoundcloudPlayer = () => {
 	const soundcloudDestroy = () => {
 		if (!soundcloudIframeElement.value) return;
 
-		const url = `${soundcloudDomain}/player?autoplay=false&buying=false&sharing=false&download=false&show_artwork=false&show_playcount=false&show_user=false&url=${`https://api.soundcloud.com/tracks/${0}`}`;
-		changeIframeUrl(url);
+		changeIframeUrl(null);
 
 		currentTrackId.value = null;
 

+ 2 - 0
frontend/src/types/global.d.ts

@@ -19,6 +19,8 @@ declare global {
 				initialItemIndex: number;
 				initialItemListUuid: string;
 		  };
+	var soundcloudIframeLockUuid: string;
+	var soundcloudIframeLockUuids: Set<string>;
 }
 
 export {};