index.vue 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671
  1. <script setup lang="ts">
  2. import {
  3. defineAsyncComponent,
  4. ref,
  5. computed,
  6. watch,
  7. onMounted,
  8. onBeforeUnmount
  9. } from "vue";
  10. import { useRoute, useRouter } from "vue-router";
  11. import Toast from "toasters";
  12. import { storeToRefs } from "pinia";
  13. import { ContentLoader } from "vue-content-loader";
  14. import canAutoPlay from "can-autoplay";
  15. import { useSoundcloudPlayer } from "@/composables/useSoundcloudPlayer";
  16. import { useWebsocketsStore } from "@/stores/websockets";
  17. import { useConfigStore } from "@/stores/config";
  18. import { useStationStore } from "@/stores/station";
  19. import { useUserAuthStore } from "@/stores/userAuth";
  20. import { useUserPreferencesStore } from "@/stores/userPreferences";
  21. import { useModalsStore } from "@/stores/modals";
  22. import aw from "@/aw";
  23. import ms from "@/ms";
  24. import keyboardShortcuts from "@/keyboardShortcuts";
  25. import utils from "@/utils";
  26. const TAG = "[STATION]";
  27. const MainHeader = defineAsyncComponent(
  28. () => import("@/components/MainHeader.vue")
  29. );
  30. const MainFooter = defineAsyncComponent(
  31. () => import("@/components/MainFooter.vue")
  32. );
  33. const FloatingBox = defineAsyncComponent(
  34. () => import("@/components/FloatingBox.vue")
  35. );
  36. const StationInfoBox = defineAsyncComponent(
  37. () => import("@/components/StationInfoBox.vue")
  38. );
  39. const AddToPlaylistDropdown = defineAsyncComponent(
  40. () => import("@/components/AddToPlaylistDropdown.vue")
  41. );
  42. const SongItem = defineAsyncComponent(
  43. () => import("@/components/SongItem.vue")
  44. );
  45. const Z404 = defineAsyncComponent(() => import("@/pages/404.vue"));
  46. const StationSidebar = defineAsyncComponent(
  47. () => import("./Sidebar/index.vue")
  48. );
  49. const route = useRoute();
  50. const router = useRouter();
  51. const { socket } = useWebsocketsStore();
  52. const configStore = useConfigStore();
  53. const stationStore = useStationStore();
  54. const userAuthStore = useUserAuthStore();
  55. const userPreferencesStore = useUserPreferencesStore();
  56. const {
  57. soundcloudIframeElement,
  58. soundcloudLoadTrack,
  59. soundcloudSeekTo,
  60. soundcloudPlay,
  61. soundcloudPause,
  62. soundcloudSetVolume,
  63. soundcloudGetPosition,
  64. soundcloudBindListener,
  65. soundcloudOnTrackStateChange,
  66. soundcloudDestroy,
  67. soundcloudUnload
  68. } = useSoundcloudPlayer();
  69. // TODO this might need a different place, like onMounted
  70. const isApple = ref(
  71. navigator.platform.match(/iPhone|iPod|iPad/) ||
  72. navigator.vendor === "Apple Computer, Inc."
  73. );
  74. const loading = ref(true);
  75. const exists = ref(true);
  76. const youtubePlayerReady = ref(false);
  77. const youtubePlayer = ref(undefined);
  78. const timePaused = ref(0);
  79. const muted = ref(false);
  80. const timeElapsed = ref("0:00");
  81. const timeBeforePause = ref(0);
  82. const systemDifference = ref(0);
  83. const attemptsToPlayVideo = ref(0);
  84. const canAutoplay = ref(true);
  85. const lastTimeRequestedIfCanAutoplay = ref(0);
  86. const seeking = ref(false);
  87. const playbackRate = ref(1);
  88. const volumeSliderValue = ref(0);
  89. const showPlaylistDropdown = ref(false);
  90. const seekerbarPercentage = ref(0);
  91. const frontendDevMode = ref("production");
  92. const activityWatchMediaDataInterval = ref(null);
  93. const activityWatchMediaLastStatus = ref("");
  94. const activityWatchMediaLastMediaSource = ref("");
  95. const activityWatchMediaLastStartDuration = ref(0);
  96. const reportStationStateInterval = ref(null);
  97. const nextCurrentSong = ref(null);
  98. const mediaModalWatcher = ref(null);
  99. const beforeMediaModalLocalPausedLock = ref(false);
  100. const beforeMediaModalLocalPaused = ref(null);
  101. const persistentToastCheckerInterval = ref(null);
  102. const persistentToasts = ref([]);
  103. // Experimental options
  104. const experimentalChangableListenModeEnabled = ref(false);
  105. const experimentalChangableListenMode = ref("listen_and_participate"); // Can be either listen_and_participate or participate
  106. // End experimental options
  107. // NEW
  108. const videoLoading = ref();
  109. const startedAt = ref();
  110. const pausedAt = ref();
  111. const stationIdentifier = ref();
  112. // ENDNEW
  113. const playerDebugBox = ref();
  114. const keyboardShortcutsHelper = ref();
  115. const autoPaused = ref(false);
  116. const modalsStore = useModalsStore();
  117. const { activeModals } = storeToRefs(modalsStore);
  118. // TODO fix this if it still has some use, as this is no longer accurate
  119. // const video = computed(() => store.state.modals.editSong);
  120. const { loggedIn, userId } = storeToRefs(userAuthStore);
  121. const { nightmode, autoSkipDisliked } = storeToRefs(userPreferencesStore);
  122. const {
  123. station,
  124. currentSong,
  125. nextSong,
  126. songsList,
  127. stationPaused,
  128. localPaused,
  129. noSong,
  130. autoRequest,
  131. autoRequestLock,
  132. history
  133. } = storeToRefs(stationStore);
  134. const youtubePlayerState = ref<
  135. null | "UNSTARTED" | "ENDED" | "PLAYING" | "PAUSED" | "BUFFERING" | "CUED"
  136. >(null);
  137. const skipVotesLoaded = computed(
  138. () =>
  139. !noSong.value &&
  140. Number.isInteger(currentSong.value.skipVotes) &&
  141. currentSong.value.skipVotes >= 0
  142. );
  143. const ratingsLoaded = computed(
  144. () =>
  145. !noSong.value &&
  146. Number.isInteger(currentSong.value.likes) &&
  147. Number.isInteger(currentSong.value.dislikes) &&
  148. currentSong.value.likes >= 0 &&
  149. currentSong.value.dislikes >= 0
  150. );
  151. const ownRatingsLoaded = computed(
  152. () =>
  153. !noSong.value &&
  154. typeof currentSong.value.liked === "boolean" &&
  155. typeof currentSong.value.disliked === "boolean"
  156. );
  157. const aModalIsOpen = computed(() => Object.keys(activeModals.value).length > 0);
  158. const currentUserQueueSongs = computed(
  159. () =>
  160. songsList.value.filter(
  161. queueSong => queueSong.requestedBy === userId.value
  162. ).length
  163. );
  164. const stationState = computed(() => {
  165. if (noSong.value) return "no_song";
  166. if (stationPaused.value) return "station_paused";
  167. if (
  168. experimentalChangableListenModeEnabled.value &&
  169. experimentalChangableListenMode.value === "participate"
  170. )
  171. return "participate";
  172. if (localPaused.value || autoPaused.value) return "local_paused";
  173. if (volumeSliderValue.value === 0 || muted.value) return "muted";
  174. if (youtubePlayerReady.value && youtubePlayerState.value === "PLAYING")
  175. return "playing";
  176. if (youtubePlayerReady.value && youtubePlayerState.value === "BUFFERING")
  177. return "buffering";
  178. return "unknown";
  179. });
  180. const currentSongMediaType = computed(() => {
  181. if (
  182. !currentSong.value ||
  183. !currentSong.value.mediaSource ||
  184. currentSong.value.mediaSource.indexOf(":") === -1
  185. )
  186. return "none";
  187. return currentSong.value.mediaSource.split(":")[0];
  188. });
  189. const currentSongMediaValue = computed(() => {
  190. if (
  191. !currentSong.value ||
  192. !currentSong.value.mediaSource ||
  193. currentSong.value.mediaSource.indexOf(":") === -1
  194. )
  195. return null;
  196. return currentSong.value.mediaSource.split(":")[1];
  197. });
  198. const currentYoutubeId = computed(() => {
  199. if (
  200. !currentSong.value ||
  201. !currentSong.value.mediaSource.startsWith("youtube:")
  202. )
  203. return null;
  204. return currentSong.value.mediaSource.split(":")[1];
  205. });
  206. const currentSongIsYoutube = computed(() => {
  207. if (
  208. !currentSong.value ||
  209. !currentSong.value.mediaSource.startsWith("youtube:")
  210. )
  211. return false;
  212. return true;
  213. });
  214. const {
  215. joinStation,
  216. leaveStation,
  217. updateStation,
  218. updateUserCount,
  219. updateUsers,
  220. updateCurrentSong,
  221. updateNextSong,
  222. updateSongsList,
  223. repositionSongInList,
  224. updateStationPaused,
  225. updateLocalPaused,
  226. updateNoSong,
  227. updateIfStationIsFavorited,
  228. setAutofillPlaylists,
  229. setBlacklist,
  230. updateCurrentSongRatings,
  231. updateOwnCurrentSongRatings,
  232. updateCurrentSongSkipVotes,
  233. updateAutoRequestLock,
  234. updateAutorequestLocalStorage,
  235. hasPermission,
  236. addDj,
  237. removeDj,
  238. updatePermissions,
  239. addHistoryItem,
  240. setHistory
  241. } = stationStore;
  242. // TODO fix this if it still has some use
  243. // const stopVideo = payload =>
  244. // store.dispatch("modals/editSong/stopVideo", payload);
  245. const recentlyPlayedYoutubeIds = (max: number) => {
  246. const mediaSources = new Set();
  247. history.value.forEach((historyItem, index) => {
  248. if (index < max) mediaSources.add(historyItem.payload.song.mediaSource);
  249. });
  250. return Array.from(mediaSources);
  251. };
  252. const updateMediaSessionData = song => {
  253. if (song) {
  254. ms.setMediaSessionData(
  255. 0,
  256. !localPaused.value && !stationPaused.value && !autoPaused.value, // This should be improved later
  257. song.title,
  258. song.artists ? song.artists.join(", ") : null,
  259. null,
  260. song.thumbnail ||
  261. `https://img.youtube.com/vi/${song.youtubeId}/mqdefault.jpg`
  262. );
  263. } else ms.removeMediaSessionData(0);
  264. };
  265. const autoRequestSong = () => {
  266. const {
  267. limit,
  268. allowAutorequest,
  269. autorequestLimit,
  270. autorequestDisallowRecentlyPlayedEnabled,
  271. autorequestDisallowRecentlyPlayedNumber
  272. } = station.value.requests;
  273. if (autoRequestLock.value) return;
  274. if (!allowAutorequest) return;
  275. if (autoRequest.value.length === 0) return;
  276. updateAutorequestLocalStorage();
  277. if (currentUserQueueSongs.value >= limit) return;
  278. if (currentUserQueueSongs.value >= autorequestLimit) return;
  279. if (songsList.value.length >= 50) return;
  280. let excludedYoutubeIds = [];
  281. if (autorequestDisallowRecentlyPlayedEnabled) {
  282. excludedYoutubeIds = recentlyPlayedYoutubeIds(
  283. autorequestDisallowRecentlyPlayedNumber
  284. );
  285. }
  286. if (songsList.value) {
  287. songsList.value.forEach(song => {
  288. excludedYoutubeIds.push(song.mediaSource);
  289. });
  290. }
  291. if (!noSong.value) {
  292. excludedYoutubeIds.push(currentSong.value.mediaSource);
  293. }
  294. const uniqueYoutubeIds = new Set();
  295. autoRequest.value.forEach(playlist => {
  296. playlist.songs.forEach(song => {
  297. if (
  298. excludedYoutubeIds.indexOf(song.mediaSource) === -1 &&
  299. !song.mediaSource.startsWith("spotify:")
  300. )
  301. uniqueYoutubeIds.add(song.mediaSource);
  302. });
  303. });
  304. if (uniqueYoutubeIds.size > 0) {
  305. const mediaSource = Array.from(uniqueYoutubeIds.values())[
  306. Math.floor(Math.random() * uniqueYoutubeIds.size)
  307. ];
  308. updateAutoRequestLock(true);
  309. socket.dispatch(
  310. "stations.addToQueue",
  311. station.value._id,
  312. mediaSource,
  313. "autorequest",
  314. data => {
  315. updateAutoRequestLock(false);
  316. if (data.status !== "success") {
  317. setTimeout(
  318. () => {
  319. autoRequestSong();
  320. },
  321. data.message === "That song is already in the queue."
  322. ? 5000
  323. : 1000
  324. );
  325. }
  326. }
  327. );
  328. }
  329. };
  330. const dateCurrently = () => new Date().getTime() + systemDifference.value;
  331. const getTimeElapsed = () => {
  332. if (currentSong.value) {
  333. let localTimePaused = timePaused.value;
  334. if (stationPaused.value)
  335. localTimePaused += dateCurrently() - pausedAt.value;
  336. return dateCurrently() - startedAt.value - localTimePaused;
  337. }
  338. return 0;
  339. };
  340. const getTimeRemaining = () => {
  341. if (currentSong.value) {
  342. return currentSong.value.duration * 1000 - getTimeElapsed();
  343. }
  344. return 0;
  345. };
  346. const getCurrentPlayerTime = () =>
  347. new Promise<number>((resolve, reject) => {
  348. if (
  349. currentSongMediaType.value === "youtube" &&
  350. youtubePlayerReady.value
  351. ) {
  352. resolve(
  353. Math.max(
  354. youtubePlayer.value.getCurrentTime() -
  355. currentSong.value.skipDuration,
  356. 0
  357. ) * 1000
  358. );
  359. return;
  360. }
  361. if (currentSongMediaType.value === "soundcloud") {
  362. soundcloudGetPosition(position => {
  363. resolve(
  364. Math.max(
  365. position / 1000 - currentSong.value.skipDuration,
  366. 0
  367. ) * 1000
  368. );
  369. });
  370. return;
  371. }
  372. resolve(0);
  373. });
  374. const skipSong = () => {
  375. if (nextCurrentSong.value && nextCurrentSong.value.currentSong) {
  376. const _songsList = songsList.value.concat([]);
  377. if (
  378. _songsList.length > 0 &&
  379. _songsList[0].mediaSource ===
  380. nextCurrentSong.value.currentSong.mediaSource
  381. ) {
  382. _songsList.splice(0, 1);
  383. updateSongsList(_songsList);
  384. }
  385. // TODO fix
  386. // eslint-disable-next-line
  387. setCurrentSong(nextCurrentSong.value);
  388. } else {
  389. // TODO fix
  390. // eslint-disable-next-line
  391. setCurrentSong({
  392. currentSong: null,
  393. startedAt: 0,
  394. paused: stationPaused.value,
  395. timePaused: 0,
  396. pausedAt: 0
  397. });
  398. }
  399. };
  400. const setNextCurrentSong = (_nextCurrentSong, skipSkipCheck = false) => {
  401. nextCurrentSong.value = _nextCurrentSong;
  402. // If skipSkipCheck is true, it won't try to skip the song
  403. if (getTimeRemaining() <= 0 && !skipSkipCheck) {
  404. skipSong();
  405. }
  406. };
  407. const resizeSeekerbar = () => {
  408. seekerbarPercentage.value =
  409. (getTimeElapsed() / 1000 / currentSong.value.duration) * 100;
  410. };
  411. const calculateTimeElapsed = async () => {
  412. if (experimentalChangableListenMode.value === "participate") return;
  413. if (
  414. youtubePlayerReady.value &&
  415. currentSongMediaType.value === "youtube" &&
  416. !noSong.value &&
  417. currentSong.value &&
  418. youtubePlayer.value.getPlayerState() === -1
  419. ) {
  420. if (!canAutoplay.value) {
  421. if (Date.now() - lastTimeRequestedIfCanAutoplay.value > 2000) {
  422. lastTimeRequestedIfCanAutoplay.value = Date.now();
  423. canAutoPlay.video().then(({ result }) => {
  424. if (result) {
  425. attemptsToPlayVideo.value = 0;
  426. canAutoplay.value = true;
  427. } else {
  428. canAutoplay.value = false;
  429. }
  430. });
  431. }
  432. } else {
  433. youtubePlayer.value.playVideo();
  434. attemptsToPlayVideo.value += 1;
  435. }
  436. }
  437. if (
  438. !stationPaused.value &&
  439. !localPaused.value &&
  440. !autoPaused.value &&
  441. !isApple.value
  442. ) {
  443. const timeElapsed = getTimeElapsed();
  444. const currentPlayerTime = await getCurrentPlayerTime();
  445. const difference = timeElapsed - currentPlayerTime;
  446. let _playbackRate = 1;
  447. if (difference < -2000) {
  448. if (!seeking.value) {
  449. seeking.value = true;
  450. playerSeekTo(
  451. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  452. );
  453. }
  454. } else if (difference < -200) {
  455. _playbackRate = 0.8;
  456. } else if (difference < -50) {
  457. _playbackRate = 0.9;
  458. } else if (difference < -25) {
  459. _playbackRate = 0.95;
  460. } else if (difference > 2000) {
  461. if (!seeking.value) {
  462. seeking.value = true;
  463. playerSeekTo(
  464. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  465. );
  466. }
  467. } else if (difference > 200) {
  468. _playbackRate = 1.2;
  469. } else if (difference > 50) {
  470. _playbackRate = 1.1;
  471. } else if (difference > 25) {
  472. _playbackRate = 1.05;
  473. } else if (
  474. currentSongMediaType.value === "youtube" &&
  475. youtubeReady.value &&
  476. youtubePlayer.value.getPlaybackRate !== 1.0
  477. ) {
  478. youtubePlayer.value.setPlaybackRate(1.0);
  479. }
  480. if (
  481. currentSongMediaType.value === "youtube" &&
  482. youtubeReady.value &&
  483. playbackRate.value !== _playbackRate
  484. ) {
  485. youtubePlayer.value.setPlaybackRate(_playbackRate);
  486. playbackRate.value = _playbackRate;
  487. }
  488. }
  489. let localTimePaused = timePaused.value;
  490. if (stationPaused.value)
  491. localTimePaused += dateCurrently() - pausedAt.value;
  492. const duration =
  493. (dateCurrently() - startedAt.value - localTimePaused) / 1000;
  494. const songDuration = currentSong.value.duration;
  495. if (youtubePlayerReady.value && songDuration <= duration) playerPause();
  496. if (duration <= songDuration)
  497. timeElapsed.value =
  498. typeof duration === "number" ? utils.formatTime(duration) : "0";
  499. };
  500. const playVideo = () => {
  501. console.debug(TAG, "Play video start");
  502. if (currentSongMediaType.value === "youtube") {
  503. if (youtubePlayerReady.value) {
  504. videoLoading.value = true;
  505. youtubePlayer.value.loadVideoById(
  506. currentYoutubeId.value,
  507. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  508. );
  509. }
  510. } else if (currentSongMediaType.value === "soundcloud") {
  511. const soundcloudId = currentSongMediaValue.value;
  512. soundcloudLoadTrack(
  513. soundcloudId,
  514. getTimeElapsed() / 1000 + currentSong.value.skipDuration,
  515. localPaused.value || stationPaused.value
  516. );
  517. }
  518. if (window.stationInterval !== 0) clearInterval(window.stationInterval);
  519. window.stationInterval = window.setInterval(() => {
  520. if (!stationPaused.value) {
  521. resizeSeekerbar();
  522. calculateTimeElapsed();
  523. }
  524. }, 150);
  525. console.debug(TAG, "Play video end");
  526. };
  527. const changeSoundcloudPlayerVolume = () => {
  528. if (muted.value) soundcloudSetVolume(0);
  529. else soundcloudSetVolume(volumeSliderValue.value);
  530. };
  531. const changePlayerVolume = () => {
  532. if (youtubePlayerReady.value) {
  533. youtubePlayer.value.setVolume(volumeSliderValue.value);
  534. if (muted.value) youtubePlayer.value.mute();
  535. else youtubePlayer.value.unMute();
  536. }
  537. changeSoundcloudPlayerVolume();
  538. };
  539. const playerPlay = () => {
  540. console.debug(
  541. TAG,
  542. "PLAYER PLAY",
  543. currentSongMediaType.value,
  544. youtubePlayerReady.value
  545. );
  546. if (currentSongMediaType.value === "youtube" && youtubePlayerReady.value) {
  547. youtubePlayer.value.playVideo();
  548. }
  549. if (currentSongMediaType.value === "soundcloud") {
  550. soundcloudPlay();
  551. }
  552. };
  553. const playerStop = () => {
  554. if (youtubePlayerReady.value) {
  555. youtubePlayer.value.stopVideo();
  556. }
  557. autoPaused.value = false;
  558. soundcloudDestroy();
  559. };
  560. const playerPause = () => {
  561. if (youtubePlayerReady.value) {
  562. youtubePlayer.value.pauseVideo();
  563. }
  564. soundcloudPause();
  565. };
  566. const playerSeekTo = position => {
  567. console.debug("PLAYER SEEK TO", position);
  568. // Position is in seconds
  569. if (currentSongMediaType.value === "youtube" && youtubePlayerReady.value) {
  570. youtubePlayer.value.seekTo(position);
  571. }
  572. if (currentSongMediaType.value === "soundcloud") {
  573. soundcloudSeekTo(position * 1000);
  574. }
  575. };
  576. const toggleSkipVote = (message?) => {
  577. socket.dispatch("stations.toggleSkipVote", station.value._id, data => {
  578. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  579. else
  580. new Toast(
  581. message || "Successfully toggled vote to skip the current song."
  582. );
  583. });
  584. };
  585. const youtubeReady = () => {
  586. if (experimentalChangableListenMode.value === "participate") return;
  587. if (!youtubePlayer.value) {
  588. ms.setYTReady(false);
  589. youtubePlayer.value = new window.YT.Player("youtubeStationPlayer", {
  590. height: 270,
  591. width: 480,
  592. // TODO CHECK TYPE
  593. videoId: currentYoutubeId.value,
  594. host: "https://www.youtube-nocookie.com",
  595. startSeconds:
  596. getTimeElapsed() / 1000 + currentSong.value.skipDuration,
  597. playerVars: {
  598. controls: 0,
  599. iv_load_policy: 3,
  600. rel: 0,
  601. showinfo: 0,
  602. disablekb: 1,
  603. playsinline: 1
  604. },
  605. events: {
  606. onReady: () => {
  607. youtubePlayerReady.value = true;
  608. ms.setYTReady(true);
  609. changePlayerVolume();
  610. playVideo();
  611. const duration =
  612. (dateCurrently() - startedAt.value - timePaused.value) /
  613. 1000;
  614. const songDuration = currentSong.value.duration;
  615. if (songDuration <= duration)
  616. youtubePlayer.value.pauseVideo();
  617. // on ios, playback will be forcibly paused locally
  618. if (isApple.value) {
  619. updateLocalPaused(true);
  620. new Toast(
  621. `Please click play manually to use ${configStore.get(
  622. "sitename"
  623. )} on iOS.`
  624. );
  625. }
  626. },
  627. onError: err => {
  628. console.log("error with youtube video", err);
  629. if (err.data === 150 && loggedIn.value) {
  630. if (
  631. !(
  632. localPaused.value ||
  633. stationPaused.value ||
  634. autoPaused.value
  635. ) &&
  636. !currentSong.value.voted
  637. ) {
  638. // automatically vote to skip
  639. toggleSkipVote(
  640. "Automatically voted to skip as this song isn't available for you."
  641. );
  642. }
  643. // persistent message while song is playing
  644. const persistentToast = new Toast({
  645. content:
  646. "This song is unavailable for you, but is playing for everyone else.",
  647. persistent: true
  648. });
  649. // save current song id
  650. const erroredYoutubeId = currentSong.value.mediaSource;
  651. persistentToasts.value.push({
  652. toast: persistentToast,
  653. checkIfCanRemove: () => {
  654. if (
  655. currentSong.value.mediaSource ===
  656. erroredYoutubeId
  657. ) {
  658. persistentToast.destroy();
  659. return true;
  660. }
  661. return false;
  662. }
  663. });
  664. } else {
  665. new Toast(
  666. "There has been an error with the YouTube Embed"
  667. );
  668. }
  669. },
  670. onStateChange: event => {
  671. switch (event.data) {
  672. case window.YT.PlayerState.UNSTARTED:
  673. youtubePlayerState.value = "UNSTARTED";
  674. break;
  675. case window.YT.PlayerState.ENDED:
  676. youtubePlayerState.value = "ENDED";
  677. break;
  678. case window.YT.PlayerState.PLAYING:
  679. youtubePlayerState.value = "PLAYING";
  680. break;
  681. case window.YT.PlayerState.PAUSED:
  682. youtubePlayerState.value = "PAUSED";
  683. break;
  684. case window.YT.PlayerState.BUFFERING:
  685. youtubePlayerState.value = "BUFFERING";
  686. break;
  687. case window.YT.PlayerState.CUED:
  688. youtubePlayerState.value = "CUED";
  689. break;
  690. default:
  691. youtubePlayerState.value = null;
  692. }
  693. if (
  694. event.data === window.YT.PlayerState.PLAYING &&
  695. (noSong.value ||
  696. currentSongMediaType.value !== "youtube")
  697. ) {
  698. youtubePlayer.value.stopVideo();
  699. } else if (
  700. event.data === window.YT.PlayerState.PLAYING &&
  701. videoLoading.value === true
  702. ) {
  703. videoLoading.value = false;
  704. youtubePlayer.value.seekTo(
  705. getTimeElapsed() / 1000 +
  706. currentSong.value.skipDuration,
  707. true
  708. );
  709. canAutoplay.value = true;
  710. if (stationPaused.value)
  711. youtubePlayer.value.pauseVideo();
  712. else if (localPaused.value) {
  713. resumeLocalStation();
  714. }
  715. } else if (
  716. event.data === window.YT.PlayerState.PLAYING &&
  717. (localPaused.value || stationPaused.value)
  718. ) {
  719. youtubePlayer.value.seekTo(
  720. timeBeforePause.value / 1000,
  721. true
  722. );
  723. if (stationPaused.value)
  724. youtubePlayer.value.pauseVideo();
  725. else resumeLocalStation();
  726. } else if (
  727. event.data === window.YT.PlayerState.PLAYING &&
  728. seeking.value === true
  729. )
  730. seeking.value = false;
  731. if (
  732. event.data === window.YT.PlayerState.PAUSED &&
  733. !localPaused.value &&
  734. !stationPaused.value &&
  735. !noSong.value &&
  736. currentSongMediaType.value === "youtube" &&
  737. youtubePlayer.value.getDuration() / 1000 <
  738. currentSong.value.duration
  739. ) {
  740. youtubePlayer.value.seekTo(
  741. getTimeElapsed() / 1000 +
  742. currentSong.value.skipDuration,
  743. true
  744. );
  745. pauseLocalStation();
  746. }
  747. }
  748. }
  749. });
  750. }
  751. };
  752. const setCurrentSong = data => {
  753. console.debug(TAG, "Set current song start");
  754. const {
  755. currentSong: _currentSong,
  756. startedAt: _startedAt,
  757. paused: _paused,
  758. timePaused: _timePaused,
  759. pausedAt: _pausedAt
  760. } = data;
  761. if (_currentSong) {
  762. if (!_currentSong.skipDuration || _currentSong.skipDuration < 0)
  763. _currentSong.skipDuration = 0;
  764. if (!_currentSong.duration || _currentSong.duration < 0)
  765. _currentSong.duration = 0;
  766. }
  767. updateCurrentSong(_currentSong || {});
  768. let nextSong = null;
  769. if (songsList.value[0])
  770. nextSong = songsList.value[0].mediaSource ? songsList.value[0] : null;
  771. updateNextSong(nextSong);
  772. setNextCurrentSong(
  773. {
  774. currentSong: null,
  775. startedAt: 0,
  776. _paused,
  777. timePaused: 0,
  778. pausedAt: 0
  779. },
  780. true
  781. );
  782. clearTimeout(window.stationNextSongTimeout);
  783. if (configStore.get("experimental.media_session"))
  784. updateMediaSessionData(_currentSong);
  785. startedAt.value = _startedAt;
  786. updateStationPaused(_paused);
  787. timePaused.value = _timePaused;
  788. pausedAt.value = _pausedAt;
  789. playerStop();
  790. if (_currentSong) {
  791. updateNoSong(false);
  792. if (currentSongMediaType.value === "youtube") {
  793. if (!youtubePlayerReady.value) youtubeReady();
  794. else playVideo();
  795. } else if (currentSongMediaType.value === "soundcloud") {
  796. playVideo();
  797. }
  798. // If the station is playing and the backend is not connected, set the next song to skip to after this song and set a timer to skip
  799. if (!stationPaused.value && !socket.ready) {
  800. if (nextSong)
  801. setNextCurrentSong(
  802. {
  803. currentSong: nextSong,
  804. startedAt: Date.now() + getTimeRemaining(),
  805. paused: false,
  806. timePaused: 0
  807. },
  808. true
  809. );
  810. else
  811. setNextCurrentSong(
  812. {
  813. currentSong: null,
  814. startedAt: 0,
  815. paused: false,
  816. timePaused: 0,
  817. pausedAt: 0
  818. },
  819. true
  820. );
  821. window.stationNextSongTimeout = setTimeout(() => {
  822. if (
  823. !noSong.value &&
  824. _currentSong.value._id === _currentSong._id
  825. )
  826. skipSong();
  827. }, getTimeRemaining());
  828. }
  829. const currentSongId = currentSong.value._id;
  830. socket.dispatch(
  831. "stations.getSkipVotes",
  832. station.value._id,
  833. currentSongId,
  834. res => {
  835. if (res.status === "success") {
  836. const { skipVotes, skipVotesCurrent, voted } = res.data;
  837. if (
  838. !noSong.value &&
  839. currentSong.value._id === currentSongId
  840. ) {
  841. updateCurrentSongSkipVotes({
  842. skipVotes,
  843. skipVotesCurrent,
  844. voted
  845. });
  846. }
  847. }
  848. }
  849. );
  850. socket.dispatch("media.getRatings", _currentSong.mediaSource, res => {
  851. if (_currentSong.mediaSource === currentSong.value.mediaSource) {
  852. const { likes, dislikes } = res.data;
  853. updateCurrentSongRatings({ likes, dislikes });
  854. }
  855. });
  856. if (loggedIn.value) {
  857. socket.dispatch(
  858. "media.getOwnRatings",
  859. _currentSong.mediaSource,
  860. res => {
  861. console.log("getOwnSongRatings", res);
  862. if (
  863. res.status === "success" &&
  864. currentSong.value.mediaSource === res.data.mediaSource
  865. ) {
  866. updateOwnCurrentSongRatings(res.data);
  867. if (
  868. autoSkipDisliked.value &&
  869. res.data.disliked === true &&
  870. !(
  871. localPaused.value ||
  872. stationPaused.value ||
  873. autoPaused.value
  874. ) &&
  875. !currentSong.value.voted
  876. ) {
  877. toggleSkipVote(
  878. "Automatically voted to skip disliked song."
  879. );
  880. }
  881. }
  882. }
  883. );
  884. }
  885. } else {
  886. updateNoSong(true);
  887. }
  888. calculateTimeElapsed();
  889. resizeSeekerbar();
  890. console.debug(TAG, "Set current song end");
  891. };
  892. const changeVolume = () => {
  893. const volume = volumeSliderValue.value;
  894. localStorage.setItem("volume", `${volume}`);
  895. muted.value = volume <= 0;
  896. localStorage.setItem("muted", `${muted.value}`);
  897. changePlayerVolume();
  898. };
  899. const resumeLocalPlayer = () => {
  900. if (configStore.get("experimental.media_session"))
  901. updateMediaSessionData(currentSong.value);
  902. if (!noSong.value) {
  903. playerSeekTo(getTimeElapsed() / 1000 + currentSong.value.skipDuration);
  904. playerPlay();
  905. }
  906. };
  907. const pauseLocalPlayer = () => {
  908. if (configStore.get("experimental.media_session"))
  909. updateMediaSessionData(currentSong.value);
  910. if (!noSong.value) {
  911. timeBeforePause.value = getTimeElapsed();
  912. playerPause();
  913. }
  914. };
  915. const resumeLocalStation = () => {
  916. updateLocalPaused(false);
  917. autoPaused.value = false;
  918. if (!stationPaused.value) resumeLocalPlayer();
  919. };
  920. const pauseLocalStation = () => {
  921. updateLocalPaused(true);
  922. pauseLocalPlayer();
  923. };
  924. const skipStation = () => {
  925. socket.dispatch("stations.forceSkip", station.value._id, data => {
  926. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  927. else new Toast("Successfully skipped the station's current song.");
  928. });
  929. };
  930. const resumeStation = () => {
  931. socket.dispatch("stations.resume", station.value._id, data => {
  932. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  933. else new Toast("Successfully resumed the station.");
  934. });
  935. };
  936. const pauseStation = () => {
  937. socket.dispatch("stations.pause", station.value._id, data => {
  938. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  939. else new Toast("Successfully paused the station.");
  940. });
  941. };
  942. const toggleMute = () => {
  943. muted.value = !muted.value;
  944. changePlayerVolume();
  945. };
  946. const increaseVolume = () => {
  947. const previousVolume = parseFloat(localStorage.getItem("volume"));
  948. let volume = previousVolume + 5;
  949. if (previousVolume === 0) {
  950. muted.value = false;
  951. localStorage.setItem("muted", "false");
  952. }
  953. if (volume > 100) volume = 100;
  954. volumeSliderValue.value = volume;
  955. localStorage.setItem("volume", `${volume}`);
  956. changePlayerVolume();
  957. };
  958. const toggleLike = () => {
  959. if (currentSong.value.liked)
  960. socket.dispatch("media.unlike", currentSong.value.mediaSource, res => {
  961. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  962. });
  963. else
  964. socket.dispatch("media.like", currentSong.value.mediaSource, res => {
  965. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  966. });
  967. };
  968. const toggleDislike = () => {
  969. if (currentSong.value.disliked)
  970. return socket.dispatch(
  971. "media.undislike",
  972. currentSong.value.mediaSource,
  973. res => {
  974. if (res.status !== "success")
  975. new Toast(`Error: ${res.message}`);
  976. }
  977. );
  978. return socket.dispatch(
  979. "media.dislike",
  980. currentSong.value.mediaSource,
  981. res => {
  982. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  983. }
  984. );
  985. };
  986. const togglePlayerDebugBox = () => {
  987. playerDebugBox.value.toggleBox();
  988. };
  989. const resetPlayerDebugBox = () => {
  990. playerDebugBox.value.resetBox();
  991. };
  992. const toggleKeyboardShortcutsHelper = () => {
  993. keyboardShortcutsHelper.value.toggleBox();
  994. };
  995. const resetKeyboardShortcutsHelper = () => {
  996. keyboardShortcutsHelper.value.resetBox();
  997. };
  998. const sendActivityWatchMediaData = () => {
  999. // TODO have this support soundcloud
  1000. if (
  1001. !autoPaused.value &&
  1002. !stationPaused.value &&
  1003. (!localPaused.value ||
  1004. experimentalChangableListenMode.value === "participate") &&
  1005. !noSong.value &&
  1006. (experimentalChangableListenMode.value === "participate" ||
  1007. currentSongMediaType.value !== "youtube" ||
  1008. youtubePlayer.value.getPlayerState() ===
  1009. window.YT.PlayerState.PLAYING)
  1010. ) {
  1011. if (activityWatchMediaLastStatus.value !== "playing") {
  1012. activityWatchMediaLastStatus.value = "playing";
  1013. activityWatchMediaLastStartDuration.value =
  1014. currentSong.value.skipDuration + getTimeElapsed();
  1015. }
  1016. if (
  1017. activityWatchMediaLastMediaSource.value !==
  1018. currentSong.value.mediaSource
  1019. ) {
  1020. activityWatchMediaLastMediaSource.value =
  1021. currentSong.value.mediaSource;
  1022. activityWatchMediaLastStartDuration.value =
  1023. currentSong.value.skipDuration + getTimeElapsed();
  1024. }
  1025. const videoData = {
  1026. title: currentSong.value ? currentSong.value.title : null,
  1027. artists:
  1028. currentSong.value && currentSong.value.artists
  1029. ? currentSong.value.artists.join(", ")
  1030. : null,
  1031. mediaSource: currentSong.value.mediaSource,
  1032. muted: muted.value,
  1033. volume: volumeSliderValue.value,
  1034. startedDuration:
  1035. activityWatchMediaLastStartDuration.value <= 0
  1036. ? 0
  1037. : Math.floor(
  1038. activityWatchMediaLastStartDuration.value / 1000
  1039. ),
  1040. source: `station#${station.value.name}`,
  1041. hostname: window.location.hostname,
  1042. experimentalChangableListenMode:
  1043. experimentalChangableListenMode.value,
  1044. playerState: "",
  1045. playbackRate: -1
  1046. };
  1047. if (currentSongMediaType.value === "youtube") {
  1048. videoData.playerState =
  1049. experimentalChangableListenMode.value === "participate"
  1050. ? "none"
  1051. : Object.keys(window.YT.PlayerState).find(
  1052. key =>
  1053. window.YT.PlayerState[key] ===
  1054. youtubePlayer.value.getPlayerState()
  1055. );
  1056. videoData.playbackRate = playbackRate.value;
  1057. } else {
  1058. delete videoData.playerState;
  1059. delete videoData.playbackRate;
  1060. }
  1061. const success = aw.sendMediaData(videoData);
  1062. if (!success) pauseLocalStation();
  1063. } else {
  1064. activityWatchMediaLastStatus.value = "not_playing";
  1065. }
  1066. };
  1067. const experimentalChangableListenModeChange = newMode => {
  1068. experimentalChangableListenMode.value = newMode;
  1069. localStorage.setItem(
  1070. `experimental_changeable_listen_mode_${station.value._id}`,
  1071. newMode
  1072. );
  1073. if (newMode === "participate") {
  1074. // Destroy the YouTube player
  1075. if (youtubePlayer.value) {
  1076. youtubePlayer.value.destroy();
  1077. youtubePlayer.value = null;
  1078. youtubePlayerReady.value = false;
  1079. youtubePlayerState.value = null;
  1080. }
  1081. autoPaused.value = false;
  1082. soundcloudDestroy();
  1083. } else {
  1084. // Recreate the YouTube player
  1085. youtubeReady();
  1086. }
  1087. };
  1088. watch(
  1089. () => autoRequest.value.length,
  1090. () => {
  1091. autoRequestSong();
  1092. }
  1093. );
  1094. onMounted(async () => {
  1095. console.debug(TAG, "On mounted start");
  1096. mediaModalWatcher.value = stationStore.$onAction(({ name, args }) => {
  1097. if (name === "updateMediaModalPlayingAudio") {
  1098. const [mediaModalPlayingAudio] = args;
  1099. if (mediaModalPlayingAudio) {
  1100. if (!beforeMediaModalLocalPausedLock.value) {
  1101. beforeMediaModalLocalPausedLock.value = true;
  1102. beforeMediaModalLocalPaused.value = localPaused.value;
  1103. pauseLocalStation();
  1104. }
  1105. } else {
  1106. beforeMediaModalLocalPausedLock.value = false;
  1107. if (!beforeMediaModalLocalPaused.value) resumeLocalStation();
  1108. }
  1109. }
  1110. });
  1111. document.body.scrollTo(0, 0);
  1112. stationIdentifier.value = route.params.id;
  1113. window.stationInterval = 0;
  1114. activityWatchMediaDataInterval.value = setInterval(() => {
  1115. sendActivityWatchMediaData();
  1116. }, 1000);
  1117. reportStationStateInterval.value = setInterval(() => {
  1118. socket.dispatch(
  1119. "stations.setStationState",
  1120. stationState.value,
  1121. () => {}
  1122. );
  1123. }, 5000);
  1124. persistentToastCheckerInterval.value = setInterval(() => {
  1125. persistentToasts.value.filter(
  1126. persistentToast => !persistentToast.checkIfCanRemove()
  1127. );
  1128. }, 1000);
  1129. const experimental = configStore.get("experimental");
  1130. socket.onConnect(() => {
  1131. console.debug(TAG, "On socked connect start");
  1132. clearTimeout(window.stationNextSongTimeout);
  1133. socket.dispatch("stations.join", stationIdentifier.value, async res => {
  1134. if (res.status === "success") {
  1135. console.debug(TAG, "Station join start");
  1136. setTimeout(() => {
  1137. loading.value = false;
  1138. }, 1000); // prevents popping in of youtube embed etc.
  1139. const {
  1140. _id,
  1141. displayName,
  1142. name,
  1143. description,
  1144. privacy,
  1145. owner,
  1146. autofill,
  1147. blacklist,
  1148. type,
  1149. isFavorited,
  1150. theme,
  1151. requests,
  1152. djs
  1153. } = res.data;
  1154. if (experimental && experimental.changable_listen_mode) {
  1155. if (experimental.changable_listen_mode === true)
  1156. experimentalChangableListenModeEnabled.value = true;
  1157. else if (
  1158. Array.isArray(experimental.changable_listen_mode) &&
  1159. experimental.changable_listen_mode.indexOf(_id) !== -1
  1160. )
  1161. experimentalChangableListenModeEnabled.value = true;
  1162. }
  1163. if (experimentalChangableListenModeEnabled.value) {
  1164. console.log(
  1165. `Experimental changeable listen mode is enabled`
  1166. );
  1167. const experimentalChangeableListenModeLS =
  1168. localStorage.getItem(
  1169. `experimental_changeable_listen_mode_${_id}`
  1170. );
  1171. if (experimentalChangeableListenModeLS)
  1172. experimentalChangableListenMode.value =
  1173. experimentalChangeableListenModeLS;
  1174. }
  1175. // change url to use station name instead of station id
  1176. if (name !== stationIdentifier.value) {
  1177. // eslint-disable-next-line no-restricted-globals
  1178. router.replace(name);
  1179. }
  1180. joinStation({
  1181. _id,
  1182. name,
  1183. displayName,
  1184. description,
  1185. privacy,
  1186. owner,
  1187. autofill,
  1188. blacklist,
  1189. type,
  1190. isFavorited,
  1191. theme,
  1192. requests,
  1193. djs
  1194. });
  1195. document.getElementsByTagName(
  1196. "html"
  1197. )[0].style.cssText = `--primary-color: var(--${res.data.theme})`;
  1198. setCurrentSong({
  1199. currentSong: res.data.currentSong,
  1200. startedAt: res.data.startedAt,
  1201. paused: res.data.paused,
  1202. timePaused: res.data.timePaused,
  1203. pausedAt: res.data.pausedAt
  1204. });
  1205. updateUserCount(res.data.userCount);
  1206. updateUsers(res.data.users);
  1207. await updatePermissions();
  1208. socket.dispatch(
  1209. "stations.getStationAutofillPlaylistsById",
  1210. station.value._id,
  1211. res => {
  1212. if (res.status === "success") {
  1213. setAutofillPlaylists(res.data.playlists);
  1214. }
  1215. }
  1216. );
  1217. socket.dispatch(
  1218. "stations.getStationBlacklistById",
  1219. station.value._id,
  1220. res => {
  1221. if (res.status === "success") {
  1222. setBlacklist(res.data.playlists);
  1223. }
  1224. }
  1225. );
  1226. socket.dispatch("stations.getQueue", _id, res => {
  1227. if (res.status === "success") {
  1228. const { queue } = res.data;
  1229. updateSongsList(queue);
  1230. const [nextSong] = queue;
  1231. updateNextSong(nextSong);
  1232. }
  1233. });
  1234. socket.dispatch("stations.getHistory", _id, res => {
  1235. if (res.status === "success") {
  1236. const { history } = res.data;
  1237. setHistory(history);
  1238. }
  1239. });
  1240. if (hasPermission("stations.playback.toggle"))
  1241. keyboardShortcuts.registerShortcut("station.pauseResume", {
  1242. keyCode: 32, // Spacebar
  1243. shift: false,
  1244. ctrl: true,
  1245. preventDefault: true,
  1246. handler: () => {
  1247. if (aModalIsOpen.value) return;
  1248. if (stationPaused.value) resumeStation();
  1249. else pauseStation();
  1250. }
  1251. });
  1252. if (hasPermission("stations.skip"))
  1253. keyboardShortcuts.registerShortcut("station.skipStation", {
  1254. keyCode: 39, // Right arrow key
  1255. shift: false,
  1256. ctrl: true,
  1257. preventDefault: true,
  1258. handler: () => {
  1259. if (aModalIsOpen.value) return;
  1260. skipStation();
  1261. }
  1262. });
  1263. keyboardShortcuts.registerShortcut("station.lowerVolumeLarge", {
  1264. keyCode: 40, // Down arrow key
  1265. shift: false,
  1266. ctrl: true,
  1267. preventDefault: true,
  1268. handler: () => {
  1269. if (aModalIsOpen.value) return;
  1270. volumeSliderValue.value -= 10;
  1271. changeVolume();
  1272. }
  1273. });
  1274. keyboardShortcuts.registerShortcut("station.lowerVolumeSmall", {
  1275. keyCode: 40, // Down arrow key
  1276. shift: true,
  1277. ctrl: true,
  1278. preventDefault: true,
  1279. handler: () => {
  1280. if (aModalIsOpen.value) return;
  1281. volumeSliderValue.value -= 1;
  1282. changeVolume();
  1283. }
  1284. });
  1285. keyboardShortcuts.registerShortcut(
  1286. "station.increaseVolumeLarge",
  1287. {
  1288. keyCode: 38, // Up arrow key
  1289. shift: false,
  1290. ctrl: true,
  1291. preventDefault: true,
  1292. handler: () => {
  1293. if (aModalIsOpen.value) return;
  1294. volumeSliderValue.value += 10;
  1295. changeVolume();
  1296. }
  1297. }
  1298. );
  1299. keyboardShortcuts.registerShortcut(
  1300. "station.increaseVolumeSmall",
  1301. {
  1302. keyCode: 38, // Up arrow key
  1303. shift: true,
  1304. ctrl: true,
  1305. preventDefault: true,
  1306. handler: () => {
  1307. if (aModalIsOpen.value) return;
  1308. volumeSliderValue.value += 1;
  1309. changeVolume();
  1310. }
  1311. }
  1312. );
  1313. keyboardShortcuts.registerShortcut("station.toggleDebug", {
  1314. keyCode: 68, // D key
  1315. shift: false,
  1316. ctrl: true,
  1317. preventDefault: true,
  1318. handler: () => {
  1319. if (aModalIsOpen.value) return;
  1320. togglePlayerDebugBox();
  1321. }
  1322. });
  1323. keyboardShortcuts.registerShortcut(
  1324. "station.toggleKeyboardShortcutsHelper",
  1325. {
  1326. keyCode: 191, // '/' key
  1327. ctrl: true,
  1328. preventDefault: true,
  1329. handler: () => {
  1330. if (aModalIsOpen.value) return;
  1331. toggleKeyboardShortcutsHelper();
  1332. }
  1333. }
  1334. );
  1335. keyboardShortcuts.registerShortcut(
  1336. "station.resetKeyboardShortcutsHelper",
  1337. {
  1338. keyCode: 191, // '/' key
  1339. ctrl: true,
  1340. shift: true,
  1341. preventDefault: true,
  1342. handler: () => {
  1343. if (aModalIsOpen.value) return;
  1344. resetKeyboardShortcutsHelper();
  1345. }
  1346. }
  1347. );
  1348. // UNIX client time before ping
  1349. const beforePing = Date.now();
  1350. socket.dispatch("apis.ping", res => {
  1351. if (res.status === "success") {
  1352. // UNIX client time after ping
  1353. const afterPing = Date.now();
  1354. // Average time in MS it took between the server responding and the client receiving
  1355. const connectionLatency = (afterPing - beforePing) / 2;
  1356. console.log(connectionLatency, beforePing - afterPing);
  1357. // UNIX server time
  1358. const serverDate = res.data.date;
  1359. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  1360. const difference =
  1361. serverDate + connectionLatency - afterPing;
  1362. console.log("Difference: ", difference);
  1363. if (difference > 3000 || difference < -3000) {
  1364. console.log(
  1365. "System time difference is bigger than 3 seconds."
  1366. );
  1367. }
  1368. systemDifference.value = difference;
  1369. }
  1370. });
  1371. console.debug(TAG, "Station join end");
  1372. } else {
  1373. loading.value = false;
  1374. exists.value = false;
  1375. }
  1376. });
  1377. socket.dispatch(
  1378. "stations.existsByName",
  1379. stationIdentifier.value,
  1380. res => {
  1381. if (res.status === "error" || !res.data.exists) {
  1382. // station identifier may be using stationid instead
  1383. socket.dispatch(
  1384. "stations.existsById",
  1385. stationIdentifier.value,
  1386. res => {
  1387. if (res.status === "error" || !res.data.exists) {
  1388. loading.value = false;
  1389. exists.value = false;
  1390. }
  1391. }
  1392. );
  1393. }
  1394. }
  1395. );
  1396. console.debug(TAG, "On socked connect end");
  1397. });
  1398. socket.onDisconnect(() => {
  1399. const _currentSong = currentSong.value;
  1400. if (nextSong.value)
  1401. setNextCurrentSong(
  1402. {
  1403. currentSong: nextSong.value,
  1404. startedAt: Date.now() + getTimeRemaining(),
  1405. paused: false,
  1406. timePaused: 0
  1407. },
  1408. true
  1409. );
  1410. else
  1411. setNextCurrentSong(
  1412. {
  1413. currentSong: null,
  1414. startedAt: 0,
  1415. paused: false,
  1416. timePaused: 0,
  1417. pausedAt: 0
  1418. },
  1419. true
  1420. );
  1421. window.stationNextSongTimeout = setTimeout(() => {
  1422. if (!noSong.value && currentSong.value._id === _currentSong._id)
  1423. skipSong();
  1424. }, getTimeRemaining());
  1425. }, true);
  1426. socket.on("event:station.nextSong", res => {
  1427. const { currentSong, startedAt, paused, timePaused } = res.data;
  1428. setCurrentSong({
  1429. currentSong,
  1430. startedAt,
  1431. paused,
  1432. timePaused,
  1433. pausedAt: 0
  1434. });
  1435. });
  1436. socket.on("event:station.pause", res => {
  1437. pausedAt.value = res.data.pausedAt;
  1438. updateStationPaused(true);
  1439. pauseLocalPlayer();
  1440. clearTimeout(window.stationNextSongTimeout);
  1441. });
  1442. socket.on("event:station.resume", res => {
  1443. timePaused.value = res.data.timePaused;
  1444. updateStationPaused(false);
  1445. if (!localPaused.value) resumeLocalPlayer();
  1446. autoRequestSong();
  1447. });
  1448. socket.on("event:station.deleted", () => {
  1449. router.push({
  1450. path: "/",
  1451. query: {
  1452. toast: "The station you were in was deleted."
  1453. }
  1454. });
  1455. });
  1456. socket.on("event:ratings.liked", res => {
  1457. if (!noSong.value) {
  1458. if (res.data.mediaSource === currentSong.value.mediaSource) {
  1459. updateCurrentSongRatings(res.data);
  1460. }
  1461. }
  1462. });
  1463. socket.on("event:ratings.disliked", res => {
  1464. if (!noSong.value) {
  1465. if (res.data.mediaSource === currentSong.value.mediaSource) {
  1466. updateCurrentSongRatings(res.data);
  1467. }
  1468. }
  1469. });
  1470. socket.on("event:ratings.unliked", res => {
  1471. if (!noSong.value) {
  1472. if (res.data.mediaSource === currentSong.value.mediaSource) {
  1473. updateCurrentSongRatings(res.data);
  1474. }
  1475. }
  1476. });
  1477. socket.on("event:ratings.undisliked", res => {
  1478. if (!noSong.value) {
  1479. if (res.data.mediaSource === currentSong.value.mediaSource) {
  1480. updateCurrentSongRatings(res.data);
  1481. }
  1482. }
  1483. });
  1484. socket.on("event:ratings.updated", res => {
  1485. if (!noSong.value) {
  1486. if (res.data.mediaSource === currentSong.value.mediaSource) {
  1487. updateOwnCurrentSongRatings(res.data);
  1488. }
  1489. }
  1490. });
  1491. socket.on("event:station.queue.updated", res => {
  1492. updateSongsList(res.data.queue);
  1493. let nextSong = null;
  1494. if (songsList.value[0])
  1495. nextSong = songsList.value[0].mediaSource
  1496. ? songsList.value[0]
  1497. : null;
  1498. updateNextSong(nextSong);
  1499. autoRequestSong();
  1500. });
  1501. socket.on("event:station.queue.song.repositioned", res => {
  1502. repositionSongInList(res.data.song);
  1503. let nextSong = null;
  1504. if (songsList.value[0])
  1505. nextSong = songsList.value[0].mediaSource
  1506. ? songsList.value[0]
  1507. : null;
  1508. updateNextSong(nextSong);
  1509. });
  1510. socket.on("event:station.toggleSkipVote", res => {
  1511. if (currentSong.value)
  1512. updateCurrentSongSkipVotes({
  1513. skipVotes: res.data.voted
  1514. ? currentSong.value.skipVotes + 1
  1515. : currentSong.value.skipVotes - 1,
  1516. skipVotesCurrent: null,
  1517. voted:
  1518. res.data.userId === userId.value
  1519. ? res.data.voted
  1520. : currentSong.value.voted
  1521. });
  1522. });
  1523. socket.on("event:station.updated", async res => {
  1524. const { name, theme, privacy } = res.data.station;
  1525. if (!hasPermission("stations.view") && privacy === "private") {
  1526. router.push({
  1527. path: "/",
  1528. query: {
  1529. toast: "The station you were in was made private."
  1530. }
  1531. });
  1532. } else {
  1533. if (station.value.name !== name) {
  1534. await router.push(
  1535. `${name}?${Object.keys(route.query)
  1536. .map(
  1537. key =>
  1538. `${encodeURIComponent(
  1539. key
  1540. )}=${encodeURIComponent(
  1541. JSON.stringify(route.query[key])
  1542. )}`
  1543. )
  1544. .join("&")}`
  1545. );
  1546. // eslint-disable-next-line no-restricted-globals
  1547. history.replaceState({ ...history.state, ...{} }, null);
  1548. }
  1549. if (station.value.theme !== theme)
  1550. document.getElementsByTagName(
  1551. "html"
  1552. )[0].style.cssText = `--primary-color: var(--${theme})`;
  1553. updateStation(res.data.station);
  1554. }
  1555. });
  1556. socket.on("event:station.users.updated", res =>
  1557. updateUsers(res.data.users)
  1558. );
  1559. socket.on("event:station.userCount.updated", res =>
  1560. updateUserCount(res.data.userCount)
  1561. );
  1562. socket.on("event:user.station.favorited", res => {
  1563. if (res.data.stationId === station.value._id)
  1564. updateIfStationIsFavorited({ isFavorited: true });
  1565. });
  1566. socket.on("event:user.station.unfavorited", res => {
  1567. if (res.data.stationId === station.value._id)
  1568. updateIfStationIsFavorited({ isFavorited: false });
  1569. });
  1570. socket.on("event:station.djs.added", res => {
  1571. if (res.data.user._id === userId.value)
  1572. updatePermissions().then(() => {
  1573. if (
  1574. !hasPermission("stations.view") &&
  1575. station.value.privacy === "private"
  1576. )
  1577. router.push({
  1578. path: "/",
  1579. query: {
  1580. toast: "You no longer have access to the station you were in."
  1581. }
  1582. });
  1583. });
  1584. addDj(res.data.user);
  1585. });
  1586. socket.on("event:station.djs.removed", res => {
  1587. if (res.data.user._id === userId.value)
  1588. updatePermissions().then(() => {
  1589. if (
  1590. !hasPermission("stations.view") &&
  1591. station.value.privacy === "private"
  1592. )
  1593. router.push({
  1594. path: "/",
  1595. query: {
  1596. toast: "You no longer have access to the station you were in."
  1597. }
  1598. });
  1599. });
  1600. removeDj(res.data.user);
  1601. });
  1602. socket.on("event:station.history.new", res => {
  1603. addHistoryItem(res.data.historyItem);
  1604. });
  1605. socket.on("keep.event:user.role.updated", () => {
  1606. updatePermissions().then(() => {
  1607. if (
  1608. !hasPermission("stations.view") &&
  1609. station.value.privacy === "private"
  1610. )
  1611. router.push({
  1612. path: "/",
  1613. query: {
  1614. toast: "You no longer have access to the station you were in."
  1615. }
  1616. });
  1617. });
  1618. });
  1619. frontendDevMode.value = process.env.NODE_ENV;
  1620. ms.setListeners(0, {
  1621. play: () => {
  1622. if (hasPermission("stations.playback.toggle")) resumeStation();
  1623. else resumeLocalStation();
  1624. },
  1625. pause: () => {
  1626. if (hasPermission("stations.playback.toggle")) pauseStation();
  1627. else pauseLocalStation();
  1628. },
  1629. nexttrack: () => {
  1630. if (hasPermission("stations.skip")) skipStation();
  1631. else if (!currentSong.value.voted) toggleSkipVote();
  1632. }
  1633. });
  1634. if (JSON.parse(localStorage.getItem("muted"))) {
  1635. muted.value = true;
  1636. volumeSliderValue.value = 0;
  1637. } else {
  1638. let volume = parseFloat(localStorage.getItem("volume"));
  1639. volume =
  1640. typeof volume === "number" && !Number.isNaN(volume) ? volume : 20;
  1641. localStorage.setItem("volume", `${volume}`);
  1642. volumeSliderValue.value = volume;
  1643. }
  1644. changePlayerVolume();
  1645. soundcloudOnTrackStateChange(newState => {
  1646. console.debug(TAG, `New state: ${newState}`);
  1647. if (
  1648. newState === "attempting_to_play" ||
  1649. newState === "failed_to_play"
  1650. ) {
  1651. if (currentSongMediaType.value !== "soundcloud") return;
  1652. if (!localPaused.value && !stationPaused.value) {
  1653. if (newState === "failed_to_play")
  1654. new Toast(
  1655. "Failed to start SoundCloud player. Please try to manually start it."
  1656. );
  1657. autoPaused.value = true;
  1658. }
  1659. } else if (newState === "paused") {
  1660. if (currentSongMediaType.value !== "soundcloud") return;
  1661. if (!localPaused.value && !stationPaused.value) {
  1662. pauseLocalStation();
  1663. }
  1664. } else if (newState === "playing") {
  1665. if (currentSongMediaType.value !== "soundcloud") {
  1666. soundcloudDestroy();
  1667. return;
  1668. }
  1669. if (autoPaused.value) {
  1670. autoPaused.value = false;
  1671. }
  1672. if (localPaused.value) resumeLocalStation();
  1673. if (stationPaused.value) {
  1674. soundcloudPause();
  1675. }
  1676. soundcloudSeekTo(
  1677. (getTimeElapsed() / 1000 + currentSong.value.skipDuration) *
  1678. 1000
  1679. );
  1680. } else if (newState === "error") {
  1681. autoPaused.value = true;
  1682. }
  1683. });
  1684. soundcloudBindListener("seek", () => {
  1685. console.debug(TAG, "Bind on seek");
  1686. if (seeking.value) seeking.value = false;
  1687. });
  1688. soundcloudBindListener("error", value => {
  1689. console.debug(TAG, "Bind on error", value);
  1690. });
  1691. console.debug(TAG, "On mounted end");
  1692. });
  1693. onBeforeUnmount(() => {
  1694. document.getElementsByTagName("html")[0].style.cssText = "";
  1695. if (configStore.get("experimental.media_session")) {
  1696. ms.removeListeners(0);
  1697. ms.removeMediaSessionData(0);
  1698. }
  1699. /** Reset Songslist */
  1700. updateSongsList([]);
  1701. const shortcutNames = [
  1702. "station.pauseResume",
  1703. "station.skipStation",
  1704. "station.lowerVolumeLarge",
  1705. "station.lowerVolumeSmall",
  1706. "station.increaseVolumeLarge",
  1707. "station.increaseVolumeSmall",
  1708. "station.toggleDebug"
  1709. ];
  1710. shortcutNames.forEach(shortcutName => {
  1711. keyboardShortcuts.unregisterShortcut(shortcutName);
  1712. });
  1713. mediaModalWatcher.value(); // removes the watcher
  1714. clearInterval(activityWatchMediaDataInterval.value);
  1715. clearTimeout(window.stationNextSongTimeout);
  1716. clearTimeout(persistentToastCheckerInterval.value);
  1717. clearInterval(reportStationStateInterval.value);
  1718. persistentToasts.value.forEach(persistentToast => {
  1719. persistentToast.toast.destroy();
  1720. });
  1721. socket.dispatch("stations.leave", station.value._id, () => {});
  1722. const { allowAutorequest } = station.value.requests;
  1723. if (
  1724. !autoRequestLock.value &&
  1725. allowAutorequest &&
  1726. autoRequest.value.length > 0
  1727. )
  1728. updateAutorequestLocalStorage();
  1729. leaveStation();
  1730. soundcloudUnload();
  1731. // Delete the Pinia store that was created for this station, after all other cleanup tasks are performed
  1732. stationStore.$dispose();
  1733. });
  1734. </script>
  1735. <template>
  1736. <div>
  1737. <page-metadata
  1738. v-if="exists && !loading"
  1739. :title="`${station.displayName}`"
  1740. />
  1741. <page-metadata v-else-if="!exists && !loading" :title="`Not found`" />
  1742. <div id="page-loader-container" v-if="loading">
  1743. <content-loader
  1744. width="1920"
  1745. height="1080"
  1746. :primary-color="nightmode ? '#222' : '#fff'"
  1747. :secondary-color="nightmode ? '#444' : '#ddd'"
  1748. preserve-aspect-ratio="none"
  1749. id="page-loader-content"
  1750. >
  1751. <rect x="55" y="105" rx="5" ry="5" width="670" height="149" />
  1752. <rect x="55" y="283" rx="5" ry="5" width="670" height="640" />
  1753. <rect x="745" y="108" rx="5" ry="5" width="1120" height="672" />
  1754. <rect x="745" y="810" rx="5" ry="5" width="1120" height="110" />
  1755. </content-loader>
  1756. <content-loader
  1757. width="1920"
  1758. height="1080"
  1759. :primary-color="nightmode ? '#222' : '#fff'"
  1760. :secondary-color="nightmode ? '#444' : '#ddd'"
  1761. preserve-aspect-ratio="none"
  1762. id="page-loader-layout"
  1763. >
  1764. <rect x="0" y="0" rx="0" ry="0" width="1920" height="64" />
  1765. <rect x="0" y="980" rx="0" ry="0" width="1920" height="100" />
  1766. </content-loader>
  1767. </div>
  1768. <!-- More simplistic loading animation for mobile users -->
  1769. <div v-show="loading" id="mobile-progress-animation" />
  1770. <ul
  1771. v-if="
  1772. currentSong &&
  1773. (currentSong.mediaSource === 'l9PxOanFjxQ' ||
  1774. currentSong.mediaSource === 'xKVcVSYmesU' ||
  1775. currentSong.mediaSource === '60ItHLz5WEA' ||
  1776. currentSong.mediaSource === 'e6vkFbtSGm0')
  1777. "
  1778. class="bg-bubbles"
  1779. >
  1780. <li></li>
  1781. <li></li>
  1782. <li></li>
  1783. <li></li>
  1784. <li></li>
  1785. <li></li>
  1786. <li></li>
  1787. <li></li>
  1788. <li></li>
  1789. <li></li>
  1790. </ul>
  1791. <div v-show="!loading && exists">
  1792. <main-header />
  1793. <div id="station-outer-container">
  1794. <div
  1795. id="station-inner-container"
  1796. :class="{ 'nothing-here': noSong }"
  1797. >
  1798. <div id="station-left-column" class="column">
  1799. <!-- div with quadrant class -->
  1800. <div class="quadrant">
  1801. <station-info-box
  1802. :station="station"
  1803. :station-paused="stationPaused"
  1804. :show-manage-station="true"
  1805. />
  1806. </div>
  1807. <div id="sidebar-container" class="quadrant">
  1808. <station-sidebar />
  1809. </div>
  1810. </div>
  1811. <div id="station-right-column" class="column">
  1812. <div
  1813. class="experimental-listen-mode-container quadrant"
  1814. v-if="
  1815. experimentalChangableListenModeEnabled &&
  1816. !noSong
  1817. "
  1818. v-show="
  1819. experimentalChangableListenMode ===
  1820. 'participate'
  1821. "
  1822. >
  1823. <button
  1824. class="button is-primary"
  1825. @click="
  1826. experimentalChangableListenModeChange(
  1827. 'listen_and_participate'
  1828. )
  1829. "
  1830. >
  1831. <i class="material-icons icon-with-button"
  1832. >music_note</i
  1833. >
  1834. <span>Listen to music</span>
  1835. </button>
  1836. <button
  1837. v-if="!skipVotesLoaded"
  1838. class="button is-primary disabled"
  1839. content="Skip votes have not been loaded yet"
  1840. v-tippy
  1841. >
  1842. <i class="material-icons icon-with-button"
  1843. >skip_next</i
  1844. >
  1845. Vote to skip the current song
  1846. </button>
  1847. <button
  1848. v-else-if="loggedIn"
  1849. :class="[
  1850. 'button',
  1851. 'is-primary',
  1852. { voted: currentSong.voted }
  1853. ]"
  1854. @click="toggleSkipVote()"
  1855. :content="`${
  1856. currentSong.voted ? 'Remove vote' : 'Vote'
  1857. } to Skip Song`"
  1858. v-tippy
  1859. >
  1860. <i class="material-icons icon-with-button"
  1861. >skip_next</i
  1862. >
  1863. Vote to skip the current song -
  1864. {{ currentSong.skipVotes }} votes
  1865. </button>
  1866. <button
  1867. v-else
  1868. class="button is-primary disabled"
  1869. content="Log in to vote to skip songs"
  1870. v-tippy="{ theme: 'info' }"
  1871. >
  1872. <i class="material-icons icon-with-button"
  1873. >skip_next</i
  1874. >
  1875. Vote to skip the current song -
  1876. {{ currentSong.skipVotes }} votes
  1877. </button>
  1878. <div class="row">
  1879. <!-- Ratings -->
  1880. <div
  1881. class="ratings"
  1882. v-if="ratingsLoaded && ownRatingsLoaded"
  1883. :class="{
  1884. liked: currentSong.liked,
  1885. disliked: currentSong.disliked
  1886. }"
  1887. >
  1888. <!-- Like Song Button -->
  1889. <button
  1890. class="button is-success like-song"
  1891. @click="toggleLike()"
  1892. content="Like Song"
  1893. v-tippy
  1894. >
  1895. <i
  1896. class="material-icons icon-with-button"
  1897. :class="{
  1898. liked: currentSong.liked
  1899. }"
  1900. >thumb_up_alt</i
  1901. >{{ currentSong.likes }}
  1902. </button>
  1903. <!-- Dislike Song Button -->
  1904. <button
  1905. class="button is-danger dislike-song"
  1906. @click="toggleDislike()"
  1907. content="Dislike Song"
  1908. v-tippy
  1909. >
  1910. <i
  1911. class="material-icons icon-with-button"
  1912. :class="{
  1913. disliked: currentSong.disliked
  1914. }"
  1915. >thumb_down_alt</i
  1916. >{{ currentSong.dislikes }}
  1917. </button>
  1918. </div>
  1919. <div id="ratings" class="disabled" v-else>
  1920. <!-- Like Song Button -->
  1921. <button
  1922. class="button is-success like-song disabled"
  1923. content="Ratings have not been loaded yet"
  1924. v-tippy
  1925. >
  1926. <i
  1927. class="material-icons icon-with-button"
  1928. >thumb_up_alt</i
  1929. >
  1930. </button>
  1931. <!-- Dislike Song Button -->
  1932. <button
  1933. class="button is-danger dislike-song disabled"
  1934. content="Ratings have not been loaded yet"
  1935. v-tippy
  1936. >
  1937. <i
  1938. class="material-icons icon-with-button"
  1939. >thumb_down_alt</i
  1940. >
  1941. </button>
  1942. </div>
  1943. <add-to-playlist-dropdown
  1944. :song="currentSong"
  1945. placement="top-end"
  1946. >
  1947. <template #button>
  1948. <div
  1949. id="add-song-to-playlist"
  1950. content="Add Song to Playlist"
  1951. v-tippy
  1952. >
  1953. <div class="control has-addons">
  1954. <button
  1955. class="button is-primary"
  1956. >
  1957. <i class="material-icons">
  1958. playlist_add
  1959. </i>
  1960. </button>
  1961. <button
  1962. class="button"
  1963. id="dropdown-toggle"
  1964. >
  1965. <i class="material-icons">
  1966. {{
  1967. showPlaylistDropdown
  1968. ? "expand_more"
  1969. : "expand_less"
  1970. }}
  1971. </i>
  1972. </button>
  1973. </div>
  1974. </div>
  1975. </template>
  1976. </add-to-playlist-dropdown>
  1977. </div>
  1978. </div>
  1979. <div
  1980. class="player-container quadrant"
  1981. v-show="
  1982. !noSong &&
  1983. (!experimentalChangableListenModeEnabled ||
  1984. experimentalChangableListenMode ===
  1985. 'listen_and_participate')
  1986. "
  1987. >
  1988. <div id="video-container">
  1989. <div
  1990. v-show="currentSongMediaType === 'youtube'"
  1991. >
  1992. <div
  1993. id="youtubeStationPlayer"
  1994. style="
  1995. width: 100%;
  1996. height: 100%;
  1997. min-height: 200px;
  1998. "
  1999. />
  2000. </div>
  2001. <iframe
  2002. v-show="
  2003. currentSongMediaType === 'soundcloud'
  2004. "
  2005. id="soundcloudStationPlayer"
  2006. ref="soundcloudIframeElement"
  2007. style="
  2008. width: 100%;
  2009. height: 100%;
  2010. min-height: 200px;
  2011. "
  2012. scrolling="no"
  2013. frameborder="no"
  2014. allow="autoplay"
  2015. ></iframe>
  2016. <div
  2017. class="player-cannot-autoplay"
  2018. v-if="!canAutoplay"
  2019. @click="increaseVolume()"
  2020. >
  2021. <p>
  2022. Please click anywhere on the screen for
  2023. the video to start
  2024. </p>
  2025. </div>
  2026. </div>
  2027. <div id="seeker-bar-container">
  2028. <div
  2029. id="seeker-bar"
  2030. :class="{
  2031. 'christmas-seeker':
  2032. configStore.get('christmas'),
  2033. nyan:
  2034. currentSong &&
  2035. currentSong.mediaSource ===
  2036. 'youtube:QH2-TGUlwu4'
  2037. }"
  2038. />
  2039. <div
  2040. class="seeker-bar-cover"
  2041. :style="{
  2042. width: `calc(100% - ${seekerbarPercentage}%)`
  2043. }"
  2044. ></div>
  2045. <img
  2046. v-if="
  2047. currentSong &&
  2048. currentSong.mediaSource ===
  2049. 'youtube:QH2-TGUlwu4'
  2050. "
  2051. src="https://freepngimg.com/thumb/nyan_cat/1-2-nyan-cat-free-download-png.png"
  2052. :style="{
  2053. position: 'absolute',
  2054. top: `-10px`,
  2055. left: `${seekerbarPercentage}%`,
  2056. width: '50px'
  2057. }"
  2058. />
  2059. <img
  2060. v-if="
  2061. currentSong &&
  2062. (currentSong.mediaSource ===
  2063. 'youtube:DtVBCG6ThDk' ||
  2064. currentSong.mediaSource ===
  2065. 'youtube:sI66hcu9fIs' ||
  2066. currentSong.mediaSource ===
  2067. 'youtube:iYYRH4apXDo' ||
  2068. currentSong.mediaSource ===
  2069. 'youtube:tRcPA7Fzebw')
  2070. "
  2071. src="/assets/rocket.svg"
  2072. :style="{
  2073. position: 'absolute',
  2074. top: `-21px`,
  2075. left: `calc(${seekerbarPercentage}% - 35px)`,
  2076. width: '50px',
  2077. transform: 'rotate(45deg)'
  2078. }"
  2079. />
  2080. <img
  2081. v-if="
  2082. currentSong &&
  2083. currentSong.mediaSource ===
  2084. 'youtube:jofNR_WkoCE'
  2085. "
  2086. src="/assets/fox.svg"
  2087. :style="{
  2088. position: 'absolute',
  2089. top: `-21px`,
  2090. left: `calc(${seekerbarPercentage}% - 35px)`,
  2091. width: '50px',
  2092. transform: 'scaleX(-1)',
  2093. opacity: 1
  2094. }"
  2095. />
  2096. <img
  2097. v-if="
  2098. currentSong &&
  2099. (currentSong.mediaSource ===
  2100. 'youtube:l9PxOanFjxQ' ||
  2101. currentSong.mediaSource ===
  2102. 'youtube:xKVcVSYmesU' ||
  2103. currentSong.mediaSource ===
  2104. 'youtube:60ItHLz5WEA' ||
  2105. currentSong.mediaSource ===
  2106. 'youtube:e6vkFbtSGm0')
  2107. "
  2108. src="/assets/old_logo.png"
  2109. :style="{
  2110. position: 'absolute',
  2111. top: `-9px`,
  2112. left: `calc(${seekerbarPercentage}% - 22px)`,
  2113. 'background-color': 'rgb(96, 199, 169)',
  2114. width: '25px',
  2115. height: '25px',
  2116. 'border-radius': '25px'
  2117. }"
  2118. />
  2119. <img
  2120. v-if="
  2121. configStore.get('christmas') &&
  2122. currentSong &&
  2123. ![
  2124. 'youtube:QH2-TGUlwu4',
  2125. 'youtube:DtVBCG6ThDk',
  2126. 'youtube:sI66hcu9fIs',
  2127. 'youtube:iYYRH4apXDo',
  2128. 'youtube:tRcPA7Fzebw',
  2129. 'youtube:jofNR_WkoCE',
  2130. 'youtube:l9PxOanFjxQ',
  2131. 'youtube:xKVcVSYmesU',
  2132. 'youtube:60ItHLz5WEA',
  2133. 'youtube:e6vkFbtSGm0'
  2134. ].includes(currentSong.mediaSource)
  2135. "
  2136. src="/assets/santa.png"
  2137. :style="{
  2138. position: 'absolute',
  2139. top: `-30px`,
  2140. left: `calc(${seekerbarPercentage}% - 25px)`,
  2141. height: '50px',
  2142. transform: 'scaleX(-1)'
  2143. }"
  2144. />
  2145. </div>
  2146. <div id="control-bar-container">
  2147. <div id="left-buttons">
  2148. <!-- Debug Box -->
  2149. <button
  2150. v-if="frontendDevMode === 'development'"
  2151. class="button is-primary"
  2152. @click="togglePlayerDebugBox()"
  2153. @dblclick="resetPlayerDebugBox()"
  2154. content="Debug"
  2155. v-tippy
  2156. >
  2157. <i
  2158. class="material-icons icon-with-button"
  2159. >
  2160. bug_report
  2161. </i>
  2162. </button>
  2163. <!-- Local Pause/Resume Button -->
  2164. <button
  2165. class="button is-primary"
  2166. @click="resumeLocalStation()"
  2167. id="local-resume"
  2168. v-if="localPaused || autoPaused"
  2169. content="Unpause Playback"
  2170. v-tippy
  2171. >
  2172. <i class="material-icons">play_arrow</i>
  2173. </button>
  2174. <button
  2175. class="button is-primary"
  2176. @click="pauseLocalStation()"
  2177. id="local-pause"
  2178. v-else
  2179. content="Pause Playback"
  2180. v-tippy
  2181. >
  2182. <i class="material-icons">pause</i>
  2183. </button>
  2184. <!-- Vote to Skip Button -->
  2185. <button
  2186. v-if="!skipVotesLoaded"
  2187. class="button is-primary disabled"
  2188. content="Skip votes have not been loaded yet"
  2189. v-tippy
  2190. >
  2191. <i
  2192. class="material-icons icon-with-button"
  2193. >skip_next</i
  2194. >
  2195. </button>
  2196. <button
  2197. v-else-if="loggedIn"
  2198. :class="[
  2199. 'button',
  2200. 'is-primary',
  2201. { voted: currentSong.voted }
  2202. ]"
  2203. @click="toggleSkipVote()"
  2204. :content="`${
  2205. currentSong.voted
  2206. ? 'Remove vote'
  2207. : 'Vote'
  2208. } to Skip Song`"
  2209. v-tippy
  2210. >
  2211. <i
  2212. class="material-icons icon-with-button"
  2213. >skip_next</i
  2214. >
  2215. {{ currentSong.skipVotes }}
  2216. </button>
  2217. <button
  2218. v-else
  2219. class="button is-primary disabled"
  2220. content="Log in to vote to skip songs"
  2221. v-tippy="{ theme: 'info' }"
  2222. >
  2223. <i
  2224. class="material-icons icon-with-button"
  2225. >skip_next</i
  2226. >
  2227. {{ currentSong.skipVotes }}
  2228. </button>
  2229. <!-- Close player window -->
  2230. <button
  2231. v-if="
  2232. experimentalChangableListenModeEnabled
  2233. "
  2234. class="button is-primary"
  2235. content="Close this player window"
  2236. @click="
  2237. experimentalChangableListenModeChange(
  2238. 'participate'
  2239. )
  2240. "
  2241. v-tippy
  2242. >
  2243. <i
  2244. class="material-icons icon-with-button"
  2245. >cancel_presentation</i
  2246. >
  2247. </button>
  2248. </div>
  2249. <div id="duration">
  2250. <p>
  2251. {{ timeElapsed }} /
  2252. {{
  2253. utils.formatTime(
  2254. currentSong.duration
  2255. )
  2256. }}
  2257. </p>
  2258. </div>
  2259. <p id="volume-control" v-if="!isApple">
  2260. <i
  2261. class="material-icons"
  2262. @click="toggleMute()"
  2263. :content="`${
  2264. muted ? 'Unmute' : 'Mute'
  2265. }`"
  2266. v-tippy
  2267. >{{
  2268. muted
  2269. ? "volume_mute"
  2270. : volumeSliderValue >= 50
  2271. ? "volume_up"
  2272. : "volume_down"
  2273. }}</i
  2274. >
  2275. <input
  2276. v-model="volumeSliderValue"
  2277. type="range"
  2278. min="0"
  2279. max="100"
  2280. class="volume-slider active"
  2281. @change="changeVolume()"
  2282. @input="changeVolume()"
  2283. />
  2284. </p>
  2285. <div id="right-buttons" v-if="loggedIn">
  2286. <!-- Ratings (Like/Dislike) Buttons -->
  2287. <div
  2288. id="ratings"
  2289. v-if="ratingsLoaded && ownRatingsLoaded"
  2290. :class="{
  2291. liked: currentSong.liked,
  2292. disliked: currentSong.disliked
  2293. }"
  2294. >
  2295. <!-- Like Song Button -->
  2296. <button
  2297. class="button is-success like-song"
  2298. id="like-song"
  2299. @click="toggleLike()"
  2300. content="Like Song"
  2301. v-tippy
  2302. >
  2303. <i
  2304. class="material-icons icon-with-button"
  2305. :class="{
  2306. liked: currentSong.liked
  2307. }"
  2308. >thumb_up_alt</i
  2309. >{{ currentSong.likes }}
  2310. </button>
  2311. <!-- Dislike Song Button -->
  2312. <button
  2313. class="button is-danger dislike-song"
  2314. id="dislike-song"
  2315. @click="toggleDislike()"
  2316. content="Dislike Song"
  2317. v-tippy
  2318. >
  2319. <i
  2320. class="material-icons icon-with-button"
  2321. :class="{
  2322. disliked:
  2323. currentSong.disliked
  2324. }"
  2325. >thumb_down_alt</i
  2326. >{{ currentSong.dislikes }}
  2327. </button>
  2328. </div>
  2329. <div id="ratings" class="disabled" v-else>
  2330. <!-- Like Song Button -->
  2331. <button
  2332. class="button is-success like-song disabled"
  2333. id="like-song"
  2334. content="Ratings have not been loaded yet"
  2335. v-tippy
  2336. >
  2337. <i
  2338. class="material-icons icon-with-button"
  2339. >thumb_up_alt</i
  2340. >
  2341. </button>
  2342. <!-- Dislike Song Button -->
  2343. <button
  2344. class="button is-danger dislike-song disabled"
  2345. id="dislike-song"
  2346. content="Ratings have not been loaded yet"
  2347. v-tippy
  2348. >
  2349. <i
  2350. class="material-icons icon-with-button"
  2351. >thumb_down_alt</i
  2352. >
  2353. </button>
  2354. </div>
  2355. <!-- Add Song To Playlist Button & Dropdown -->
  2356. <add-to-playlist-dropdown
  2357. :song="currentSong"
  2358. placement="top-end"
  2359. >
  2360. <template #button>
  2361. <div
  2362. id="add-song-to-playlist"
  2363. content="Add Song to Playlist"
  2364. v-tippy
  2365. >
  2366. <div class="control has-addons">
  2367. <button
  2368. class="button is-primary"
  2369. >
  2370. <i
  2371. class="material-icons"
  2372. >
  2373. playlist_add
  2374. </i>
  2375. </button>
  2376. <button
  2377. class="button"
  2378. id="dropdown-toggle"
  2379. >
  2380. <i
  2381. class="material-icons"
  2382. >
  2383. {{
  2384. showPlaylistDropdown
  2385. ? "expand_more"
  2386. : "expand_less"
  2387. }}
  2388. </i>
  2389. </button>
  2390. </div>
  2391. </div>
  2392. </template>
  2393. </add-to-playlist-dropdown>
  2394. </div>
  2395. <div id="right-buttons" v-else>
  2396. <!-- Disabled Ratings (Like/Dislike) Buttons -->
  2397. <div id="ratings" v-if="ratingsLoaded">
  2398. <!-- Disabled Like Song Button -->
  2399. <button
  2400. class="button is-success disabled"
  2401. id="like-song"
  2402. content="Log in to like songs"
  2403. v-tippy="{ theme: 'info' }"
  2404. >
  2405. <i
  2406. class="material-icons icon-with-button"
  2407. >thumb_up_alt</i
  2408. >{{ currentSong.likes }}
  2409. </button>
  2410. <!-- Disabled Dislike Song Button -->
  2411. <button
  2412. class="button is-danger disabled"
  2413. id="dislike-song"
  2414. content="Log in to dislike songs"
  2415. v-tippy="{ theme: 'info' }"
  2416. >
  2417. <i
  2418. class="material-icons icon-with-button"
  2419. >thumb_down_alt</i
  2420. >{{ currentSong.dislikes }}
  2421. </button>
  2422. </div>
  2423. <div id="ratings" v-else>
  2424. <!-- Disabled Like Song Button -->
  2425. <button
  2426. class="button is-success disabled"
  2427. id="like-song"
  2428. content="Ratings have not been loaded yet"
  2429. v-tippy="{ theme: 'info' }"
  2430. >
  2431. <i
  2432. class="material-icons icon-with-button"
  2433. >thumb_up_alt</i
  2434. >
  2435. </button>
  2436. <!-- Disabled Dislike Song Button -->
  2437. <button
  2438. class="button is-danger disabled"
  2439. id="dislike-song"
  2440. content="Ratings have not been loaded yet"
  2441. v-tippy="{ theme: 'info' }"
  2442. >
  2443. <i
  2444. class="material-icons icon-with-button"
  2445. >thumb_down_alt</i
  2446. >
  2447. </button>
  2448. </div>
  2449. <!-- Disabled Add Song To Playlist Button & Dropdown -->
  2450. <div id="add-song-to-playlist">
  2451. <div class="control has-addons">
  2452. <button
  2453. class="button is-primary disabled"
  2454. content="Log in to add songs to playlist"
  2455. v-tippy="{ theme: 'info' }"
  2456. >
  2457. <i class="material-icons"
  2458. >queue</i
  2459. >
  2460. </button>
  2461. </div>
  2462. </div>
  2463. </div>
  2464. </div>
  2465. </div>
  2466. <p
  2467. class="player-container nothing-here-text"
  2468. v-if="noSong"
  2469. >
  2470. No song is currently playing
  2471. </p>
  2472. <div v-if="!noSong" id="current-next-row">
  2473. <div
  2474. id="currently-playing-container"
  2475. class="quadrant"
  2476. :class="{ 'no-currently-playing': noSong }"
  2477. >
  2478. <song-item
  2479. :key="`songItem-currentSong-${currentSong.mediaSource}`"
  2480. :song="currentSong"
  2481. :duration="false"
  2482. :requested-by="true"
  2483. :requested-type="true"
  2484. header="Currently Playing.."
  2485. />
  2486. </div>
  2487. <div
  2488. v-if="nextSong"
  2489. id="next-up-container"
  2490. class="quadrant"
  2491. >
  2492. <song-item
  2493. :key="`songItem-nextSong-${nextSong.mediaSource}`"
  2494. :song="nextSong"
  2495. :duration="false"
  2496. :requested-by="true"
  2497. :requested-type="true"
  2498. header="Next Up.."
  2499. />
  2500. </div>
  2501. </div>
  2502. </div>
  2503. </div>
  2504. </div>
  2505. <main-footer />
  2506. </div>
  2507. <floating-box
  2508. id="player-debug-box"
  2509. ref="playerDebugBox"
  2510. title="Station Debug"
  2511. >
  2512. <template #body>
  2513. <span><b>No song</b>: {{ noSong }}</span>
  2514. <span><b>Song id</b>: {{ currentSong._id }}</span>
  2515. <span><b>Media source</b>: {{ currentSong.mediaSource }}</span>
  2516. <span
  2517. ><b>Media source type</b>: {{ currentSongMediaType }}</span
  2518. >
  2519. <span
  2520. ><b>Media source value</b>:
  2521. {{ currentSongMediaValue }}</span
  2522. >
  2523. <span><b>Duration</b>: {{ currentSong.duration }}</span>
  2524. <span
  2525. ><b>Skip duration</b>: {{ currentSong.skipDuration }}</span
  2526. >
  2527. <span><b>Loading</b>: {{ loading }}</span>
  2528. <span><b>Can autoplay</b>: {{ canAutoplay }}</span>
  2529. <span
  2530. ><b>Youtube player ready</b>: {{ youtubePlayerReady }}</span
  2531. >
  2532. <span
  2533. ><b>Attempts to play video</b>:
  2534. {{ attemptsToPlayVideo }}</span
  2535. >
  2536. <span
  2537. ><b>Last time requested if can autoplay</b>:
  2538. {{ lastTimeRequestedIfCanAutoplay }}</span
  2539. >
  2540. <span><b>Seeking</b>: {{ seeking }}</span>
  2541. <span><b>Playback rate</b>: {{ playbackRate }}</span>
  2542. <span><b>System difference</b>: {{ systemDifference }}</span>
  2543. <span><b>Time before paused</b>: {{ timeBeforePause }}</span>
  2544. <span><b>Time paused</b>: {{ timePaused }}</span>
  2545. <span><b>Time elapsed</b>: {{ timeElapsed }}</span>
  2546. <span><b>Volume slider value</b>: {{ volumeSliderValue }}</span>
  2547. <span><b>Local paused</b>: {{ localPaused }}</span>
  2548. <span><b>Auto paused</b>: {{ autoPaused }}</span>
  2549. <span><b>Station paused</b>: {{ stationPaused }}</span>
  2550. <span :title="new Date(pausedAt).toString()"
  2551. ><b>Paused at</b>: {{ pausedAt }}</span
  2552. >
  2553. <span :title="new Date(startedAt).toString()"
  2554. ><b>Started at</b>: {{ startedAt }}</span
  2555. >
  2556. <span
  2557. ><b>Requests enabled</b>:
  2558. {{ station.requests.enabled }}</span
  2559. >
  2560. <span
  2561. ><b>Requests access</b>: {{ station.requests.access }}</span
  2562. >
  2563. <span><b>Requests limit</b>: {{ station.requests.limit }}</span>
  2564. <span
  2565. ><b>Auto requesting playlists</b>:
  2566. {{
  2567. autoRequest.map(playlist => playlist._id).join(", ")
  2568. }}</span
  2569. >
  2570. <span
  2571. ><b>Autofill enabled</b>:
  2572. {{ station.autofill.enabled }}</span
  2573. >
  2574. <span><b>Autofill limit</b>: {{ station.autofill.limit }}</span>
  2575. <span><b>Autofill mode</b>: {{ station.autofill.mode }}</span>
  2576. <span><b>Skip votes loaded</b>: {{ skipVotesLoaded }}</span>
  2577. <span
  2578. ><b>Skip votes current</b>:
  2579. {{
  2580. currentSong.skipVotesCurrent
  2581. ? currentSong.skipVotesCurrent
  2582. : "N/A"
  2583. }}</span
  2584. >
  2585. <span
  2586. ><b>Skip votes</b>:
  2587. {{ skipVotesLoaded ? currentSong.skipVotes : "N/A" }}</span
  2588. >
  2589. <span><b>Ratings loaded</b>: {{ ratingsLoaded }}</span>
  2590. <span
  2591. ><b>Ratings</b>:
  2592. {{
  2593. ratingsLoaded
  2594. ? `${currentSong.likes} / ${currentSong.dislikes}`
  2595. : "N/A"
  2596. }}</span
  2597. >
  2598. <span><b>Own ratings loaded</b>: {{ ownRatingsLoaded }}</span>
  2599. <span
  2600. ><b>Own ratings</b>:
  2601. {{
  2602. ownRatingsLoaded
  2603. ? `${currentSong.liked} / ${currentSong.disliked}`
  2604. : "N/A"
  2605. }}</span
  2606. >
  2607. </template>
  2608. </floating-box>
  2609. <floating-box
  2610. id="keyboardShortcutsHelper"
  2611. ref="keyboardShortcutsHelper"
  2612. title="Station Keyboard Shortcuts"
  2613. >
  2614. <template #body>
  2615. <div>
  2616. <div
  2617. v-if="
  2618. hasPermission('stations.playback.toggle') ||
  2619. hasPermission('stations.skip')
  2620. "
  2621. >
  2622. <span class="biggest"><b>Admin/owner</b></span>
  2623. <span><b>Ctrl + Space</b> - Pause/resume station</span>
  2624. <span><b>Ctrl + Numpad right</b> - Skip station</span>
  2625. </div>
  2626. <hr
  2627. v-if="
  2628. hasPermission('stations.playback.toggle') ||
  2629. hasPermission('stations.skip')
  2630. "
  2631. />
  2632. <div>
  2633. <span class="biggest"><b>Volume</b></span>
  2634. <span
  2635. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  2636. 10%</span
  2637. >
  2638. <span
  2639. ><b>Ctrl + Shift + Numpad up/down</b> - Volume
  2640. up/down 10%</span
  2641. >
  2642. </div>
  2643. <hr />
  2644. <div>
  2645. <span class="biggest"><b>Misc</b></span>
  2646. <span><b>Ctrl + D</b> - Toggles debug box</span>
  2647. <span><b>Ctrl + Shift + D</b> - Resets debug box</span>
  2648. <span
  2649. ><b>Ctrl + /</b> - Toggles keyboard shortcuts
  2650. box</span
  2651. >
  2652. <span
  2653. ><b>Ctrl + Shift + /</b> - Resets keyboard shortcuts
  2654. box</span
  2655. >
  2656. </div>
  2657. </div>
  2658. </template>
  2659. </floating-box>
  2660. <Z404 v-if="!exists"></Z404>
  2661. </div>
  2662. </template>
  2663. <style lang="less">
  2664. #youtubeStationPlayer,
  2665. #soundcloudStationPlayer {
  2666. position: absolute;
  2667. top: 0;
  2668. left: 0;
  2669. width: 100%;
  2670. height: 100%;
  2671. }
  2672. #currently-playing-container,
  2673. #next-up-container {
  2674. .song-item {
  2675. min-height: 130px;
  2676. .thumbnail {
  2677. min-width: 130px;
  2678. width: 130px;
  2679. height: 130px;
  2680. }
  2681. .song-info {
  2682. margin-left: 130px;
  2683. }
  2684. }
  2685. }
  2686. #control-bar-container
  2687. #right-buttons
  2688. .tippy-box[data-theme~="dropdown"]
  2689. .nav-dropdown-items {
  2690. padding-bottom: 0 !important;
  2691. }
  2692. </style>
  2693. <style lang="less" scoped>
  2694. #page-loader-container {
  2695. height: inherit;
  2696. #page-loader-content {
  2697. height: inherit;
  2698. position: absolute;
  2699. max-width: 100%;
  2700. width: 1800px;
  2701. transform: translateX(-50%);
  2702. left: 50%;
  2703. }
  2704. #page-loader-layout {
  2705. height: inherit;
  2706. width: 100%;
  2707. }
  2708. }
  2709. #mobile-progress-animation {
  2710. width: 50px;
  2711. animation: rotate 0.8s infinite linear;
  2712. border: 8px solid var(--primary-color);
  2713. border-right-color: transparent;
  2714. border-radius: 50%;
  2715. height: 50px;
  2716. position: absolute;
  2717. top: 50%;
  2718. left: 50%;
  2719. display: none;
  2720. }
  2721. @keyframes rotate {
  2722. 0% {
  2723. transform: rotate(0deg);
  2724. }
  2725. 100% {
  2726. transform: rotate(360deg);
  2727. }
  2728. }
  2729. .nav,
  2730. .button.is-primary {
  2731. background-color: var(--primary-color) !important;
  2732. }
  2733. .button.is-primary:hover,
  2734. .button.is-primary:focus {
  2735. filter: brightness(90%);
  2736. }
  2737. .night-mode {
  2738. #currently-playing-container,
  2739. #next-up-container,
  2740. #control-bar-container,
  2741. .quadrant:not(#sidebar-container),
  2742. .player-container {
  2743. background-color: var(--dark-grey-3) !important;
  2744. }
  2745. #video-container,
  2746. #control-bar-container,
  2747. .quadrant:not(#sidebar-container),
  2748. .player-container {
  2749. border: 0 !important;
  2750. }
  2751. #seeker-bar-container {
  2752. background-color: var(--dark-grey-3) !important;
  2753. }
  2754. #dropdown-toggle {
  2755. background-color: var(--dark-grey-2) !important;
  2756. border: 0;
  2757. i {
  2758. color: var(--white);
  2759. }
  2760. }
  2761. }
  2762. #station-outer-container {
  2763. margin: 0 auto;
  2764. padding: 20px 40px;
  2765. min-height: calc(100vh - 64px);
  2766. width: 100%;
  2767. max-width: 1800px;
  2768. display: flex;
  2769. #station-inner-container {
  2770. width: 100%;
  2771. min-height: calc(100vh - 428px);
  2772. display: flex;
  2773. flex-direction: row;
  2774. flex-wrap: wrap;
  2775. .row {
  2776. display: flex;
  2777. flex-direction: row;
  2778. max-width: 100%;
  2779. }
  2780. .column {
  2781. display: flex;
  2782. flex-direction: column;
  2783. }
  2784. .quadrant {
  2785. border-radius: @border-radius;
  2786. margin: 10px;
  2787. overflow: hidden;
  2788. }
  2789. .quadrant:not(#sidebar-container) {
  2790. background-color: var(--white);
  2791. border: 1px solid var(--light-grey-3);
  2792. }
  2793. #station-left-column,
  2794. #station-right-column {
  2795. padding: 0;
  2796. }
  2797. #current-next-row {
  2798. display: flex;
  2799. flex-direction: row;
  2800. #currently-playing-container,
  2801. #next-up-container {
  2802. overflow: hidden;
  2803. flex-basis: 50%;
  2804. .song-item {
  2805. border: unset;
  2806. }
  2807. .nothing-here-text {
  2808. height: 100%;
  2809. }
  2810. }
  2811. > div:only-child {
  2812. flex: 1 !important;
  2813. flex-basis: 100% !important;
  2814. }
  2815. }
  2816. .player-container {
  2817. height: inherit;
  2818. background-color: var(--white);
  2819. display: flex;
  2820. flex-direction: column;
  2821. border: 1px solid var(--light-grey-3);
  2822. border-radius: @border-radius;
  2823. overflow: hidden;
  2824. &.nothing-here-text {
  2825. margin: 10px;
  2826. flex: 1;
  2827. min-height: 487px;
  2828. }
  2829. #video-container {
  2830. position: relative;
  2831. padding-bottom: 56.25%; /* proportion value to aspect ratio 16:9 (9 / 16 = 0.5625 or 56.25%) */
  2832. height: 0;
  2833. overflow: hidden;
  2834. .player-cannot-autoplay {
  2835. position: relative;
  2836. width: 100%;
  2837. height: 100%;
  2838. bottom: calc(100% + 5px);
  2839. background: var(--primary-color);
  2840. display: flex;
  2841. align-items: center;
  2842. justify-content: center;
  2843. p {
  2844. color: var(--white);
  2845. font-size: 26px;
  2846. text-align: center;
  2847. }
  2848. }
  2849. }
  2850. #seeker-bar-container {
  2851. background-color: var(--white);
  2852. position: relative;
  2853. height: 7px;
  2854. display: block;
  2855. width: 100%;
  2856. #seeker-bar {
  2857. background-color: var(--primary-color);
  2858. top: 0;
  2859. left: 0;
  2860. bottom: 0;
  2861. position: absolute;
  2862. width: 100%;
  2863. }
  2864. .seeker-bar-cover {
  2865. position: absolute;
  2866. top: 0;
  2867. right: 0;
  2868. bottom: 0;
  2869. background-color: inherit;
  2870. }
  2871. }
  2872. #control-bar-container {
  2873. display: flex;
  2874. justify-content: space-around;
  2875. padding: 10px 0;
  2876. width: 100%;
  2877. background: var(--white);
  2878. flex-direction: column;
  2879. flex-flow: wrap;
  2880. .button:not(#dropdown-toggle) {
  2881. width: 75px;
  2882. }
  2883. #left-buttons,
  2884. #right-buttons {
  2885. margin: 3px;
  2886. }
  2887. #left-buttons {
  2888. display: flex;
  2889. .button:not(:first-of-type) {
  2890. margin-left: 5px;
  2891. }
  2892. .disabled {
  2893. filter: grayscale(0.4);
  2894. }
  2895. }
  2896. #duration {
  2897. margin: 3px;
  2898. display: flex;
  2899. align-items: center;
  2900. p {
  2901. font-size: 22px;
  2902. /** prevents duration width slightly varying and shifting other controls slightly */
  2903. width: 150px;
  2904. text-align: center;
  2905. }
  2906. }
  2907. #volume-control {
  2908. margin: 3px;
  2909. margin-top: 0;
  2910. display: flex;
  2911. align-items: center;
  2912. cursor: pointer;
  2913. .volume-slider {
  2914. width: 100%;
  2915. padding: 0 15px;
  2916. background: transparent;
  2917. min-width: 100px;
  2918. }
  2919. input[type="range"] {
  2920. -webkit-appearance: none;
  2921. margin: 7.3px 0;
  2922. }
  2923. input[type="range"]:focus {
  2924. outline: none;
  2925. }
  2926. input[type="range"]::-webkit-slider-runnable-track {
  2927. width: 100%;
  2928. height: 5.2px;
  2929. cursor: pointer;
  2930. box-shadow: 0;
  2931. background: var(--light-grey-3);
  2932. border-radius: @border-radius;
  2933. border: 0;
  2934. }
  2935. input[type="range"]::-webkit-slider-thumb {
  2936. box-shadow: 0;
  2937. border: 0;
  2938. height: 19px;
  2939. width: 19px;
  2940. border-radius: 100%;
  2941. background: var(--primary-color);
  2942. cursor: pointer;
  2943. -webkit-appearance: none;
  2944. margin-top: -6.5px;
  2945. }
  2946. input[type="range"]::-moz-range-track {
  2947. width: 100%;
  2948. height: 5.2px;
  2949. cursor: pointer;
  2950. box-shadow: 0;
  2951. background: var(--light-grey-3);
  2952. border-radius: @border-radius;
  2953. border: 0;
  2954. }
  2955. input[type="range"]::-moz-range-thumb {
  2956. box-shadow: 0;
  2957. border: 0;
  2958. height: 19px;
  2959. width: 19px;
  2960. border-radius: 100%;
  2961. background: var(--primary-color);
  2962. cursor: pointer;
  2963. -webkit-appearance: none;
  2964. margin-top: -6.5px;
  2965. }
  2966. input[type="range"]::-ms-track {
  2967. width: 100%;
  2968. height: 5.2px;
  2969. cursor: pointer;
  2970. box-shadow: 0;
  2971. background: var(--light-grey-3);
  2972. border-radius: @border-radius;
  2973. }
  2974. input[type="range"]::-ms-fill-lower {
  2975. background: var(--light-grey-3);
  2976. border: 0;
  2977. border-radius: 0;
  2978. box-shadow: 0;
  2979. }
  2980. input[type="range"]::-ms-fill-upper {
  2981. background: var(--light-grey-3);
  2982. border: 0;
  2983. border-radius: 0;
  2984. box-shadow: 0;
  2985. }
  2986. input[type="range"]::-ms-thumb {
  2987. box-shadow: 0;
  2988. border: 0;
  2989. height: 15px;
  2990. width: 15px;
  2991. border-radius: 100%;
  2992. background: var(--primary-color);
  2993. cursor: pointer;
  2994. -webkit-appearance: none;
  2995. margin-top: 1.5px;
  2996. }
  2997. }
  2998. #right-buttons {
  2999. display: flex;
  3000. #dropdown-toggle {
  3001. width: 35px;
  3002. }
  3003. #dislike-song,
  3004. #add-song-to-playlist .button:not(#dropdown-toggle) {
  3005. margin-left: 5px;
  3006. }
  3007. #ratings {
  3008. display: flex;
  3009. &.liked #dislike-song,
  3010. &.disliked #like-song {
  3011. background-color: var(--grey) !important;
  3012. }
  3013. #like-song.disabled,
  3014. #dislike-song.disabled {
  3015. filter: grayscale(0.4);
  3016. }
  3017. }
  3018. #add-song-to-playlist {
  3019. display: flex;
  3020. flex-direction: column-reverse;
  3021. #nav-dropdown {
  3022. position: absolute;
  3023. margin-left: 4px;
  3024. margin-bottom: 36px;
  3025. .nav-dropdown-items {
  3026. position: relative;
  3027. right: calc(100% - 110px);
  3028. }
  3029. }
  3030. .control {
  3031. width: fit-content;
  3032. margin-bottom: 0 !important;
  3033. button.disabled {
  3034. filter: grayscale(0.4);
  3035. border-radius: @border-radius;
  3036. &::after {
  3037. margin-right: 100%;
  3038. }
  3039. }
  3040. }
  3041. }
  3042. }
  3043. }
  3044. }
  3045. #sidebar-container {
  3046. border-top: 0;
  3047. position: relative;
  3048. height: inherit;
  3049. flex-grow: 1;
  3050. min-height: 350px;
  3051. }
  3052. }
  3053. }
  3054. .footer {
  3055. margin-top: 30px;
  3056. }
  3057. .nyan {
  3058. background: linear-gradient(
  3059. 90deg,
  3060. magenta 0%,
  3061. red 15%,
  3062. orange 30%,
  3063. yellow 45%,
  3064. lime 60%,
  3065. cyan 75%,
  3066. blue 90%,
  3067. magenta 100%
  3068. );
  3069. background-size: 200%;
  3070. animation: nyanMoving 4s linear infinite;
  3071. }
  3072. @keyframes nyanMoving {
  3073. 0% {
  3074. background-position: 0% 0%;
  3075. }
  3076. 100% {
  3077. background-position: -200% 0%;
  3078. }
  3079. }
  3080. .christmas-seeker {
  3081. background: repeating-linear-gradient(
  3082. -45deg,
  3083. var(--white) 0 1rem,
  3084. var(--dark-red) 1rem 2rem
  3085. );
  3086. background-size: 200% 100%;
  3087. animation: christmas 20s linear infinite;
  3088. }
  3089. @keyframes christmas {
  3090. 100% {
  3091. background-position: 80% 100%;
  3092. }
  3093. }
  3094. .bg-bubbles {
  3095. top: 0;
  3096. left: 0;
  3097. width: 100%;
  3098. height: 100%;
  3099. position: absolute;
  3100. z-index: -1;
  3101. margin: 0px;
  3102. pointer-events: none;
  3103. }
  3104. .bg-bubbles li {
  3105. position: absolute;
  3106. list-style: none;
  3107. display: block;
  3108. width: 40px;
  3109. height: 40px;
  3110. border-radius: 100px;
  3111. background-color: var(--primary-color);
  3112. opacity: 0.15;
  3113. bottom: 0px;
  3114. -webkit-animation: square 25s infinite;
  3115. animation: square 25s infinite;
  3116. -webkit-transition-timing-function: linear;
  3117. transition-timing-function: linear;
  3118. }
  3119. .bg-bubbles li:nth-child(1) {
  3120. left: 10%;
  3121. }
  3122. .bg-bubbles li:nth-child(2) {
  3123. left: 20%;
  3124. width: 80px;
  3125. height: 80px;
  3126. -webkit-animation-delay: 2s;
  3127. animation-delay: 2s;
  3128. -webkit-animation-duration: 17s;
  3129. animation-duration: 17s;
  3130. }
  3131. .bg-bubbles li:nth-child(3) {
  3132. left: 25%;
  3133. -webkit-animation-delay: 4s;
  3134. animation-delay: 4s;
  3135. }
  3136. .bg-bubbles li:nth-child(4) {
  3137. left: 40%;
  3138. width: 60px;
  3139. height: 60px;
  3140. -webkit-animation-duration: 22s;
  3141. animation-duration: 22s;
  3142. background-color: var(--primary-color);
  3143. opacity: 0.25;
  3144. }
  3145. .bg-bubbles li:nth-child(5) {
  3146. left: 70%;
  3147. }
  3148. .bg-bubbles li:nth-child(6) {
  3149. left: 80%;
  3150. width: 120px;
  3151. height: 120px;
  3152. -webkit-animation-delay: 3s;
  3153. animation-delay: 3s;
  3154. background-color: var(--primary-color);
  3155. opacity: 0.2;
  3156. }
  3157. .bg-bubbles li:nth-child(7) {
  3158. left: 32%;
  3159. width: 160px;
  3160. height: 160px;
  3161. -webkit-animation-delay: 7s;
  3162. animation-delay: 7s;
  3163. }
  3164. .bg-bubbles li:nth-child(8) {
  3165. left: 55%;
  3166. width: 20px;
  3167. height: 20px;
  3168. -webkit-animation-delay: 15s;
  3169. animation-delay: 15s;
  3170. -webkit-animation-duration: 40s;
  3171. animation-duration: 40s;
  3172. }
  3173. .bg-bubbles li:nth-child(9) {
  3174. left: 25%;
  3175. width: 10px;
  3176. height: 10px;
  3177. -webkit-animation-delay: 2s;
  3178. animation-delay: 2s;
  3179. -webkit-animation-duration: 40s;
  3180. animation-duration: 40s;
  3181. background-color: var(--primary-color);
  3182. opacity: 0.3;
  3183. }
  3184. .bg-bubbles li:nth-child(10) {
  3185. left: 80%;
  3186. width: 160px;
  3187. height: 160px;
  3188. -webkit-animation-delay: 11s;
  3189. animation-delay: 11s;
  3190. }
  3191. .experimental-listen-mode-container {
  3192. display: flex;
  3193. flex-direction: column;
  3194. justify-content: center;
  3195. row-gap: 16px;
  3196. padding: 16px 16px;
  3197. .row {
  3198. display: flex;
  3199. flex-direction: row;
  3200. column-gap: 16px;
  3201. .ratings {
  3202. flex: 2;
  3203. display: flex;
  3204. flex-direction: row;
  3205. column-gap: 16px;
  3206. button {
  3207. flex: 1;
  3208. }
  3209. }
  3210. .addToPlaylistDropdown {
  3211. flex: 1;
  3212. .button.is-primary {
  3213. flex: 1;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. /* Tablet view fix */
  3219. @media (max-width: 768px) {
  3220. .bg-bubbles li:nth-child(10) {
  3221. display: none;
  3222. }
  3223. .experimental-listen-mode-container {
  3224. row-gap: 8px;
  3225. .row {
  3226. column-gap: 8px;
  3227. .ratings {
  3228. column-gap: 8px;
  3229. }
  3230. }
  3231. }
  3232. }
  3233. @-webkit-keyframes square {
  3234. 0% {
  3235. -webkit-transform: translateY(0);
  3236. transform: translateY(0);
  3237. }
  3238. 100% {
  3239. -webkit-transform: translateY(-700px) rotate(600deg);
  3240. transform: translateY(-700px) rotate(600deg);
  3241. }
  3242. }
  3243. @keyframes square {
  3244. 0% {
  3245. -webkit-transform: translateY(0);
  3246. transform: translateY(0);
  3247. }
  3248. 100% {
  3249. -webkit-transform: translateY(-700px) rotate(600deg);
  3250. transform: translateY(-700px) rotate(600deg);
  3251. }
  3252. }
  3253. :deep(.nothing-here-text) {
  3254. display: flex;
  3255. align-items: center;
  3256. justify-content: center;
  3257. }
  3258. @media (min-width: 1500px) {
  3259. #station-left-column {
  3260. max-width: 650px;
  3261. }
  3262. #station-right-column {
  3263. max-width: calc(100% - 650px);
  3264. }
  3265. }
  3266. @media (max-width: 1700px) {
  3267. #current-next-row {
  3268. flex-direction: column !important;
  3269. > div {
  3270. flex: 1 !important;
  3271. }
  3272. }
  3273. }
  3274. @media (max-width: 1500px) {
  3275. #mobile-progress-animation {
  3276. display: block;
  3277. }
  3278. #page-loader-container {
  3279. display: none;
  3280. }
  3281. #station-outer-container {
  3282. max-width: 1500px;
  3283. #station-inner-container {
  3284. flex-direction: row;
  3285. #station-left-column {
  3286. #about-station-container #admin-buttons {
  3287. flex-wrap: wrap;
  3288. }
  3289. #sidebar-container {
  3290. min-height: 350px;
  3291. }
  3292. }
  3293. #station-right-column {
  3294. overflow: hidden;
  3295. #current-next-row {
  3296. flex-direction: column;
  3297. }
  3298. #control-bar-container {
  3299. #duration,
  3300. #volume-control,
  3301. #right-buttons,
  3302. #left-buttons {
  3303. margin-bottom: 5px;
  3304. justify-content: center;
  3305. }
  3306. #duration {
  3307. order: 1;
  3308. }
  3309. #volume-control {
  3310. order: 2;
  3311. max-width: 400px;
  3312. }
  3313. #right-buttons {
  3314. order: 3;
  3315. flex-wrap: wrap;
  3316. #ratings {
  3317. flex-wrap: wrap;
  3318. }
  3319. }
  3320. #left-buttons {
  3321. order: 4;
  3322. flex-wrap: wrap;
  3323. }
  3324. }
  3325. }
  3326. }
  3327. }
  3328. }
  3329. @media (max-width: 1200px) {
  3330. #station-outer-container {
  3331. max-width: 900px;
  3332. padding: 0;
  3333. #station-inner-container {
  3334. flex-direction: column-reverse;
  3335. flex-wrap: nowrap;
  3336. }
  3337. }
  3338. }
  3339. @media (max-width: 990px) {
  3340. #station-outer-container {
  3341. min-height: calc(
  3342. 100vh - 256px
  3343. ); // Height of nav (64px) + height of footer (190px)
  3344. }
  3345. }
  3346. </style>