index.vue 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844
  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 { useWebsocketsStore } from "@/stores/websockets";
  16. import { useStationStore } from "@/stores/station";
  17. import { useUserAuthStore } from "@/stores/userAuth";
  18. import { useUserPreferencesStore } from "@/stores/userPreferences";
  19. import { useModalsStore } from "@/stores/modals";
  20. import aw from "@/aw";
  21. import ms from "@/ms";
  22. import ws from "@/ws";
  23. import keyboardShortcuts from "@/keyboardShortcuts";
  24. import utils from "@/utils";
  25. const FloatingBox = defineAsyncComponent(
  26. () => import("@/components/FloatingBox.vue")
  27. );
  28. const StationInfoBox = defineAsyncComponent(
  29. () => import("@/components/StationInfoBox.vue")
  30. );
  31. const AddToPlaylistDropdown = defineAsyncComponent(
  32. () => import("@/components/AddToPlaylistDropdown.vue")
  33. );
  34. const SongItem = defineAsyncComponent(
  35. () => import("@/components/SongItem.vue")
  36. );
  37. const Z404 = defineAsyncComponent(() => import("@/pages/404.vue"));
  38. const StationSidebar = defineAsyncComponent(
  39. () => import("./Sidebar/index.vue")
  40. );
  41. const route = useRoute();
  42. const router = useRouter();
  43. const { socket } = useWebsocketsStore();
  44. const stationStore = useStationStore();
  45. const userAuthStore = useUserAuthStore();
  46. const userPreferencesStore = useUserPreferencesStore();
  47. // TODO this might need a different place, like onMounted
  48. const isApple = ref(
  49. navigator.platform.match(/iPhone|iPod|iPad/) ||
  50. navigator.vendor === "Apple Computer, Inc."
  51. );
  52. const loading = ref(true);
  53. const exists = ref(true);
  54. const playerReady = ref(false);
  55. const player = ref(undefined);
  56. const timePaused = ref(0);
  57. const muted = ref(false);
  58. const timeElapsed = ref("0:00");
  59. const timeBeforePause = ref(0);
  60. const systemDifference = ref(0);
  61. const attemptsToPlayVideo = ref(0);
  62. const canAutoplay = ref(true);
  63. const lastTimeRequestedIfCanAutoplay = ref(0);
  64. const seeking = ref(false);
  65. const playbackRate = ref(1);
  66. const volumeSliderValue = ref(0);
  67. const showPlaylistDropdown = ref(false);
  68. const seekerbarPercentage = ref(0);
  69. const frontendDevMode = ref("production");
  70. const activityWatchVideoDataInterval = ref(null);
  71. const activityWatchVideoLastStatus = ref("");
  72. const activityWatchVideoLastYouTubeId = ref("");
  73. // const activityWatchVideoLastStartDuration = ref("");
  74. const nextCurrentSong = ref(null);
  75. // const editSongModalWatcher = ref(null);
  76. // const beforeEditSongModalLocalPaused = ref(null);
  77. const socketConnected = ref(null);
  78. const persistentToastCheckerInterval = ref(null);
  79. const persistentToasts = ref([]);
  80. const mediasession = ref(false);
  81. const christmas = ref(false);
  82. const sitename = ref("Musare");
  83. // NEW
  84. const videoLoading = ref();
  85. const startedAt = ref();
  86. const pausedAt = ref();
  87. const stationIdentifier = ref();
  88. // ENDNEW
  89. const playerDebugBox = ref();
  90. const keyboardShortcutsHelper = ref();
  91. const modalsStore = useModalsStore();
  92. const { activeModals } = storeToRefs(modalsStore);
  93. // TODO fix this if it still has some use, as this is no longer accurate
  94. // const video = computed(() => store.state.modals.editSong);
  95. const { loggedIn, userId, role } = storeToRefs(userAuthStore);
  96. const { nightmode, autoSkipDisliked } = storeToRefs(userPreferencesStore);
  97. const {
  98. station,
  99. currentSong,
  100. nextSong,
  101. songsList,
  102. stationPaused,
  103. localPaused,
  104. noSong,
  105. autoRequest,
  106. autoRequestLock
  107. } = storeToRefs(stationStore);
  108. const skipVotesLoaded = computed(
  109. () =>
  110. !noSong.value &&
  111. Number.isInteger(currentSong.value.skipVotes) &&
  112. currentSong.value.skipVotes >= 0
  113. );
  114. const ratingsLoaded = computed(
  115. () =>
  116. !noSong.value &&
  117. Number.isInteger(currentSong.value.likes) &&
  118. Number.isInteger(currentSong.value.dislikes) &&
  119. currentSong.value.likes >= 0 &&
  120. currentSong.value.dislikes >= 0
  121. );
  122. const ownRatingsLoaded = computed(
  123. () =>
  124. !noSong.value &&
  125. typeof currentSong.value.liked === "boolean" &&
  126. typeof currentSong.value.disliked === "boolean"
  127. );
  128. const aModalIsOpen = computed(() => Object.keys(activeModals.value).length > 0);
  129. const currentUserQueueSongs = computed(
  130. () =>
  131. songsList.value.filter(
  132. queueSong => queueSong.requestedBy === userId.value
  133. ).length
  134. );
  135. const {
  136. joinStation,
  137. leaveStation,
  138. updateStation,
  139. updateUserCount,
  140. updateUsers,
  141. updateCurrentSong,
  142. updateNextSong,
  143. updateSongsList,
  144. repositionSongInList,
  145. updateStationPaused,
  146. updateLocalPaused,
  147. updateNoSong,
  148. updateIfStationIsFavorited,
  149. setAutofillPlaylists,
  150. setBlacklist,
  151. updateCurrentSongRatings,
  152. updateOwnCurrentSongRatings,
  153. updateCurrentSongSkipVotes,
  154. updateAutoRequestLock,
  155. hasPermission
  156. } = stationStore;
  157. // TODO fix this if it still has some use
  158. // const stopVideo = payload =>
  159. // store.dispatch("modals/editSong/stopVideo", payload);
  160. const updateMediaSessionData = song => {
  161. if (song) {
  162. ms.setMediaSessionData(
  163. 0,
  164. !localPaused.value && !stationPaused.value, // This should be improved later
  165. song.title,
  166. song.artists ? song.artists.join(", ") : null,
  167. null,
  168. song.thumbnail
  169. );
  170. } else ms.removeMediaSessionData(0);
  171. };
  172. const autoRequestSong = () => {
  173. if (
  174. !autoRequestLock.value &&
  175. songsList.value.length < 50 &&
  176. currentUserQueueSongs.value < station.value.requests.limit * 0.5 &&
  177. autoRequest.value.length > 0
  178. ) {
  179. const selectedPlaylist =
  180. autoRequest.value[
  181. Math.floor(Math.random() * autoRequest.value.length)
  182. ];
  183. if (selectedPlaylist._id && selectedPlaylist.songs.length > 0) {
  184. const selectedSong =
  185. selectedPlaylist.songs[
  186. Math.floor(Math.random() * selectedPlaylist.songs.length)
  187. ];
  188. if (selectedSong.youtubeId) {
  189. updateAutoRequestLock(true);
  190. socket.dispatch(
  191. "stations.addToQueue",
  192. station.value._id,
  193. selectedSong.youtubeId,
  194. data => {
  195. updateAutoRequestLock(false);
  196. if (data.status !== "success") {
  197. setTimeout(
  198. () => {
  199. autoRequestSong();
  200. },
  201. data.message ===
  202. "That song is already in the queue."
  203. ? 5000
  204. : 1000
  205. );
  206. }
  207. }
  208. );
  209. }
  210. }
  211. }
  212. };
  213. const getTimeElapsed = () => {
  214. if (currentSong.value) {
  215. if (stationPaused.value)
  216. timePaused.value += Date.currently() - pausedAt.value;
  217. return Date.currently() - startedAt.value - timePaused.value;
  218. }
  219. return 0;
  220. };
  221. const getTimeRemaining = () => {
  222. if (currentSong.value) {
  223. return currentSong.value.duration * 1000 - getTimeElapsed();
  224. }
  225. return 0;
  226. };
  227. const skipSong = () => {
  228. if (nextCurrentSong.value && nextCurrentSong.value.currentSong) {
  229. const _songsList = songsList.value.concat([]);
  230. if (
  231. _songsList.length > 0 &&
  232. _songsList[0].youtubeId ===
  233. nextCurrentSong.value.currentSong.youtubeId
  234. ) {
  235. _songsList.splice(0, 1);
  236. updateSongsList(_songsList);
  237. }
  238. // TODO fix
  239. // eslint-disable-next-line
  240. setCurrentSong(nextCurrentSong.value);
  241. } else {
  242. // TODO fix
  243. // eslint-disable-next-line
  244. setCurrentSong({
  245. currentSong: null,
  246. startedAt: 0,
  247. paused: stationPaused.value,
  248. timePaused: 0,
  249. pausedAt: 0
  250. });
  251. }
  252. };
  253. const setNextCurrentSong = (_nextCurrentSong, skipSkipCheck = false) => {
  254. nextCurrentSong.value = _nextCurrentSong;
  255. // If skipSkipCheck is true, it won't try to skip the song
  256. if (getTimeRemaining() <= 0 && !skipSkipCheck) {
  257. skipSong();
  258. }
  259. };
  260. const resizeSeekerbar = () => {
  261. seekerbarPercentage.value = parseFloat(
  262. (getTimeElapsed() / 1000 / currentSong.value.duration) * 100
  263. );
  264. };
  265. const calculateTimeElapsed = () => {
  266. if (
  267. playerReady.value &&
  268. !noSong.value &&
  269. currentSong.value &&
  270. player.value.getPlayerState() === -1
  271. ) {
  272. if (!canAutoplay.value) {
  273. if (Date.now() - lastTimeRequestedIfCanAutoplay.value > 2000) {
  274. lastTimeRequestedIfCanAutoplay.value = Date.now();
  275. canAutoPlay.video().then(({ result }) => {
  276. if (result) {
  277. attemptsToPlayVideo.value = 0;
  278. canAutoplay.value = true;
  279. } else {
  280. canAutoplay.value = false;
  281. }
  282. });
  283. }
  284. } else {
  285. player.value.playVideo();
  286. attemptsToPlayVideo.value += 1;
  287. }
  288. }
  289. if (
  290. !stationPaused.value &&
  291. !localPaused.value &&
  292. playerReady.value &&
  293. !isApple.value
  294. ) {
  295. const timeElapsed = getTimeElapsed();
  296. const currentPlayerTime =
  297. Math.max(
  298. player.value.getCurrentTime() - currentSong.value.skipDuration,
  299. 0
  300. ) * 1000;
  301. const difference = timeElapsed - currentPlayerTime;
  302. let _playbackRate = 1;
  303. if (difference < -2000) {
  304. if (!seeking.value) {
  305. seeking.value = true;
  306. player.value.seekTo(
  307. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  308. );
  309. }
  310. } else if (difference < -200) {
  311. _playbackRate = 0.8;
  312. } else if (difference < -50) {
  313. _playbackRate = 0.9;
  314. } else if (difference < -25) {
  315. _playbackRate = 0.95;
  316. } else if (difference > 2000) {
  317. if (!seeking.value) {
  318. seeking.value = true;
  319. player.value.seekTo(
  320. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  321. );
  322. }
  323. } else if (difference > 200) {
  324. _playbackRate = 1.2;
  325. } else if (difference > 50) {
  326. _playbackRate = 1.1;
  327. } else if (difference > 25) {
  328. _playbackRate = 1.05;
  329. } else if (player.value.getPlaybackRate !== 1.0) {
  330. player.value.setPlaybackRate(1.0);
  331. }
  332. if (playbackRate.value !== _playbackRate) {
  333. player.value.setPlaybackRate(_playbackRate);
  334. playbackRate.value = _playbackRate;
  335. }
  336. }
  337. if (stationPaused.value)
  338. timePaused.value += Date.currently() - pausedAt.value;
  339. const duration =
  340. (Date.currently() - startedAt.value - timePaused.value) / 1000;
  341. const songDuration = currentSong.value.duration;
  342. if (playerReady.value && songDuration <= duration)
  343. player.value.pauseVideo();
  344. if (duration <= songDuration)
  345. timeElapsed.value = utils.formatTime(duration);
  346. };
  347. const playVideo = () => {
  348. if (playerReady.value) {
  349. videoLoading.value = true;
  350. player.value.loadVideoById(
  351. currentSong.value.youtubeId,
  352. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  353. );
  354. if (window.stationInterval !== 0) clearInterval(window.stationInterval);
  355. window.stationInterval = setInterval(() => {
  356. if (!stationPaused.value) {
  357. resizeSeekerbar();
  358. calculateTimeElapsed();
  359. }
  360. }, 150);
  361. }
  362. };
  363. const voteSkipStation = message => {
  364. socket.dispatch("stations.voteSkip", station.value._id, data => {
  365. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  366. else
  367. new Toast(
  368. message || "Successfully voted to skip the current song."
  369. );
  370. });
  371. };
  372. const youtubeReady = () => {
  373. if (!player.value) {
  374. ms.setYTReady(false);
  375. player.value = new window.YT.Player("stationPlayer", {
  376. height: 270,
  377. width: 480,
  378. videoId: currentSong.value.youtubeId,
  379. host: "https://www.youtube-nocookie.com",
  380. startSeconds:
  381. getTimeElapsed() / 1000 + currentSong.value.skipDuration,
  382. playerVars: {
  383. controls: 0,
  384. iv_load_policy: 3,
  385. rel: 0,
  386. showinfo: 0,
  387. disablekb: 1,
  388. playsinline: 1
  389. },
  390. events: {
  391. onReady: () => {
  392. playerReady.value = true;
  393. ms.setYTReady(true);
  394. let volume = parseFloat(localStorage.getItem("volume"));
  395. volume = typeof volume === "number" ? volume : 20;
  396. player.value.setVolume(volume);
  397. if (volume > 0) player.value.unMute();
  398. if (muted.value) player.value.mute();
  399. playVideo();
  400. const duration =
  401. (Date.currently() -
  402. startedAt.value -
  403. timePaused.value) /
  404. 1000;
  405. const songDuration = currentSong.value.duration;
  406. if (songDuration <= duration) player.value.pauseVideo();
  407. // on ios, playback will be forcibly paused locally
  408. if (isApple.value) {
  409. updateLocalPaused(true);
  410. new Toast(
  411. `Please click play manually to use ${sitename.value} on iOS.`
  412. );
  413. }
  414. },
  415. onError: err => {
  416. console.log("error with youtube video", err);
  417. if (err.data === 150 && loggedIn.value) {
  418. if (!(localPaused.value || stationPaused.value)) {
  419. // automatically vote to skip
  420. voteSkipStation(
  421. "Automatically voted to skip as this song isn't available for you."
  422. );
  423. }
  424. // persistent message while song is playing
  425. const persistentToast = new Toast({
  426. content:
  427. "This song is unavailable for you, but is playing for everyone else.",
  428. persistent: true
  429. });
  430. // save current song id
  431. const erroredYoutubeId = currentSong.value.youtubeId;
  432. persistentToasts.value.push({
  433. toast: persistentToast,
  434. checkIfCanRemove: () => {
  435. if (
  436. currentSong.value.youtubeId !==
  437. erroredYoutubeId
  438. ) {
  439. persistentToast.destroy();
  440. return true;
  441. }
  442. return false;
  443. }
  444. });
  445. } else {
  446. new Toast(
  447. "There has been an error with the YouTube Embed"
  448. );
  449. }
  450. },
  451. onStateChange: event => {
  452. if (
  453. event.data === window.YT.PlayerState.PLAYING &&
  454. videoLoading.value === true
  455. ) {
  456. videoLoading.value = false;
  457. player.value.seekTo(
  458. getTimeElapsed() / 1000 +
  459. currentSong.value.skipDuration,
  460. true
  461. );
  462. canAutoplay.value = true;
  463. if (localPaused.value || stationPaused.value)
  464. player.value.pauseVideo();
  465. } else if (
  466. event.data === window.YT.PlayerState.PLAYING &&
  467. (localPaused.value || stationPaused.value)
  468. ) {
  469. player.value.seekTo(timeBeforePause.value / 1000, true);
  470. player.value.pauseVideo();
  471. } else if (
  472. event.data === window.YT.PlayerState.PLAYING &&
  473. seeking.value === true
  474. )
  475. seeking.value = false;
  476. if (
  477. event.data === window.YT.PlayerState.PAUSED &&
  478. !localPaused.value &&
  479. !stationPaused.value &&
  480. !noSong.value &&
  481. player.value.getDuration() / 1000 <
  482. currentSong.value.duration
  483. ) {
  484. player.value.seekTo(
  485. getTimeElapsed() / 1000 +
  486. currentSong.value.skipDuration,
  487. true
  488. );
  489. player.value.playVideo();
  490. }
  491. }
  492. }
  493. });
  494. }
  495. };
  496. const setCurrentSong = data => {
  497. const {
  498. currentSong: _currentSong,
  499. startedAt: _startedAt,
  500. paused: _paused,
  501. timePaused: _timePaused,
  502. pausedAt: _pausedAt
  503. } = data;
  504. if (_currentSong) {
  505. if (!_currentSong.skipDuration || _currentSong.skipDuration < 0)
  506. _currentSong.skipDuration = 0;
  507. if (!_currentSong.duration || _currentSong.duration < 0)
  508. _currentSong.duration = 0;
  509. }
  510. updateCurrentSong(_currentSong || {});
  511. let nextSong = null;
  512. if (songsList.value[0])
  513. nextSong = songsList.value[0].youtubeId ? songsList.value[0] : null;
  514. updateNextSong(nextSong);
  515. setNextCurrentSong(
  516. {
  517. currentSong: null,
  518. startedAt: 0,
  519. _paused,
  520. timePaused: 0,
  521. pausedAt: 0
  522. },
  523. true
  524. );
  525. clearTimeout(window.stationNextSongTimeout);
  526. if (mediasession.value) updateMediaSessionData(_currentSong);
  527. startedAt.value = _startedAt;
  528. updateStationPaused(_paused);
  529. timePaused.value = _timePaused;
  530. pausedAt.value = _pausedAt;
  531. if (_currentSong) {
  532. updateNoSong(false);
  533. if (!playerReady.value) youtubeReady();
  534. else playVideo();
  535. // 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
  536. if (!stationPaused.value && !socketConnected.value) {
  537. if (nextSong)
  538. setNextCurrentSong(
  539. {
  540. currentSong: nextSong,
  541. startedAt: Date.now() + getTimeRemaining(),
  542. paused: false,
  543. timePaused: 0
  544. },
  545. true
  546. );
  547. else
  548. setNextCurrentSong(
  549. {
  550. currentSong: null,
  551. startedAt: 0,
  552. paused: false,
  553. timePaused: 0,
  554. pausedAt: 0
  555. },
  556. true
  557. );
  558. window.stationNextSongTimeout = setTimeout(() => {
  559. if (
  560. !noSong.value &&
  561. _currentSong.value._id === _currentSong._id
  562. )
  563. skipSong("window.stationNextSongTimeout 1");
  564. }, getTimeRemaining());
  565. }
  566. const currentSongId = currentSong.value._id;
  567. socket.dispatch(
  568. "stations.getSkipVotes",
  569. station.value._id,
  570. currentSongId,
  571. res => {
  572. if (res.status === "success") {
  573. const { skipVotes, skipVotesCurrent } = res.data;
  574. if (
  575. !noSong.value &&
  576. currentSong.value._id === currentSongId
  577. ) {
  578. updateCurrentSongSkipVotes({
  579. skipVotes,
  580. skipVotesCurrent
  581. });
  582. }
  583. }
  584. }
  585. );
  586. socket.dispatch("media.getRatings", _currentSong.youtubeId, res => {
  587. if (_currentSong.youtubeId === currentSong.value.youtubeId) {
  588. const { likes, dislikes } = res.data;
  589. updateCurrentSongRatings({ likes, dislikes });
  590. }
  591. });
  592. if (loggedIn.value) {
  593. socket.dispatch(
  594. "media.getOwnRatings",
  595. _currentSong.youtubeId,
  596. res => {
  597. console.log("getOwnSongRatings", res);
  598. if (
  599. res.status === "success" &&
  600. currentSong.value.youtubeId === res.data.youtubeId
  601. ) {
  602. updateOwnCurrentSongRatings(res.data);
  603. if (
  604. autoSkipDisliked.value &&
  605. res.data.disliked === true &&
  606. !(localPaused.value || stationPaused.value)
  607. ) {
  608. voteSkipStation(
  609. "Automatically voted to skip disliked song."
  610. );
  611. }
  612. }
  613. }
  614. );
  615. }
  616. } else {
  617. if (playerReady.value) player.value.stopVideo();
  618. updateNoSong(true);
  619. }
  620. calculateTimeElapsed();
  621. resizeSeekerbar();
  622. };
  623. const changeVolume = () => {
  624. const volume = volumeSliderValue.value;
  625. localStorage.setItem("volume", volume);
  626. if (playerReady.value) {
  627. player.value.setVolume(volume);
  628. if (volume > 0) {
  629. player.value.unMute();
  630. localStorage.setItem("muted", false);
  631. muted.value = false;
  632. }
  633. }
  634. };
  635. const resumeLocalPlayer = () => {
  636. if (mediasession.value) updateMediaSessionData(currentSong.value);
  637. if (!noSong.value) {
  638. if (playerReady.value) {
  639. player.value.seekTo(
  640. getTimeElapsed() / 1000 + currentSong.value.skipDuration
  641. );
  642. player.value.playVideo();
  643. }
  644. }
  645. };
  646. const pauseLocalPlayer = () => {
  647. if (mediasession.value) updateMediaSessionData(currentSong.value);
  648. if (!noSong.value) {
  649. timeBeforePause.value = getTimeElapsed();
  650. if (playerReady.value) player.value.pauseVideo();
  651. }
  652. };
  653. const resumeLocalStation = () => {
  654. updateLocalPaused(false);
  655. if (!stationPaused.value) resumeLocalPlayer();
  656. };
  657. const pauseLocalStation = () => {
  658. updateLocalPaused(true);
  659. pauseLocalPlayer();
  660. };
  661. const skipStation = () => {
  662. socket.dispatch("stations.forceSkip", station.value._id, data => {
  663. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  664. else new Toast("Successfully skipped the station's current song.");
  665. });
  666. };
  667. const resumeStation = () => {
  668. socket.dispatch("stations.resume", station.value._id, data => {
  669. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  670. else new Toast("Successfully resumed the station.");
  671. });
  672. };
  673. const pauseStation = () => {
  674. socket.dispatch("stations.pause", station.value._id, data => {
  675. if (data.status !== "success") new Toast(`Error: ${data.message}`);
  676. else new Toast("Successfully paused the station.");
  677. });
  678. };
  679. const toggleMute = () => {
  680. if (playerReady.value) {
  681. const previousVolume = parseFloat(localStorage.getItem("volume"));
  682. const volume = player.value.getVolume() <= 0 ? previousVolume : 0;
  683. muted.value = !muted.value;
  684. localStorage.setItem("muted", muted.value);
  685. volumeSliderValue.value = volume;
  686. player.value.setVolume(volume);
  687. if (!muted.value) localStorage.setItem("volume", volume);
  688. }
  689. };
  690. const increaseVolume = () => {
  691. if (playerReady.value) {
  692. const previousVolume = parseFloat(localStorage.getItem("volume"));
  693. let volume = previousVolume + 5;
  694. if (previousVolume === 0) {
  695. muted.value = false;
  696. localStorage.setItem("muted", false);
  697. }
  698. if (volume > 100) volume = 100;
  699. volumeSliderValue.value = volume;
  700. player.value.setVolume(volume);
  701. localStorage.setItem("volume", volume);
  702. }
  703. };
  704. const toggleLike = () => {
  705. if (currentSong.value.liked)
  706. socket.dispatch("media.unlike", currentSong.value.youtubeId, res => {
  707. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  708. });
  709. else
  710. socket.dispatch("media.like", currentSong.value.youtubeId, res => {
  711. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  712. });
  713. };
  714. const toggleDislike = () => {
  715. if (currentSong.value.disliked)
  716. return socket.dispatch(
  717. "media.undislike",
  718. currentSong.value.youtubeId,
  719. res => {
  720. if (res.status !== "success")
  721. new Toast(`Error: ${res.message}`);
  722. }
  723. );
  724. return socket.dispatch(
  725. "media.dislike",
  726. currentSong.value.youtubeId,
  727. res => {
  728. if (res.status !== "success") new Toast(`Error: ${res.message}`);
  729. }
  730. );
  731. };
  732. const togglePlayerDebugBox = () => {
  733. playerDebugBox.value.toggleBox();
  734. };
  735. const resetPlayerDebugBox = () => {
  736. playerDebugBox.value.resetBox();
  737. };
  738. const toggleKeyboardShortcutsHelper = () => {
  739. keyboardShortcutsHelper.value.toggleBox();
  740. };
  741. const resetKeyboardShortcutsHelper = () => {
  742. keyboardShortcutsHelper.value.resetBox();
  743. };
  744. const join = () => {
  745. socket.dispatch("stations.join", stationIdentifier.value, res => {
  746. if (res.status === "success") {
  747. setTimeout(() => {
  748. loading.value = false;
  749. }, 1000); // prevents popping in of youtube embed etc.
  750. const {
  751. _id,
  752. displayName,
  753. name,
  754. description,
  755. privacy,
  756. owner,
  757. autofill,
  758. blacklist,
  759. type,
  760. isFavorited,
  761. theme,
  762. requests,
  763. permissions
  764. } = res.data;
  765. // change url to use station name instead of station id
  766. if (name !== stationIdentifier.value) {
  767. // eslint-disable-next-line no-restricted-globals
  768. router.replace(name);
  769. }
  770. joinStation({
  771. _id,
  772. name,
  773. displayName,
  774. description,
  775. privacy,
  776. owner,
  777. autofill,
  778. blacklist,
  779. type,
  780. isFavorited,
  781. theme,
  782. requests,
  783. permissions
  784. });
  785. document.getElementsByTagName(
  786. "html"
  787. )[0].style.cssText = `--primary-color: var(--${res.data.theme})`;
  788. setCurrentSong({
  789. currentSong: res.data.currentSong,
  790. startedAt: res.data.startedAt,
  791. paused: res.data.paused,
  792. timePaused: res.data.timePaused,
  793. pausedAt: res.data.pausedAt
  794. });
  795. updateUserCount(res.data.userCount);
  796. updateUsers(res.data.users);
  797. socket.dispatch(
  798. "stations.getStationAutofillPlaylistsById",
  799. station.value._id,
  800. res => {
  801. if (res.status === "success") {
  802. setAutofillPlaylists(res.data.playlists);
  803. }
  804. }
  805. );
  806. socket.dispatch(
  807. "stations.getStationBlacklistById",
  808. station.value._id,
  809. res => {
  810. if (res.status === "success") {
  811. setBlacklist(res.data.playlists);
  812. }
  813. }
  814. );
  815. socket.dispatch("stations.getQueue", _id, res => {
  816. if (res.status === "success") {
  817. const { queue } = res.data;
  818. updateSongsList(queue);
  819. const [nextSong] = queue;
  820. updateNextSong(nextSong);
  821. }
  822. });
  823. if (
  824. hasPermission("stations.pause") &&
  825. hasPermission("stations.resume")
  826. )
  827. keyboardShortcuts.registerShortcut("station.pauseResume", {
  828. keyCode: 32, // Spacebar
  829. shift: false,
  830. ctrl: true,
  831. preventDefault: true,
  832. handler: () => {
  833. if (aModalIsOpen.value) return;
  834. if (stationPaused.value) resumeStation();
  835. else pauseStation();
  836. }
  837. });
  838. if (hasPermission("stations.skip"))
  839. keyboardShortcuts.registerShortcut("station.skipStation", {
  840. keyCode: 39, // Right arrow key
  841. shift: false,
  842. ctrl: true,
  843. preventDefault: true,
  844. handler: () => {
  845. if (aModalIsOpen.value) return;
  846. skipStation();
  847. }
  848. });
  849. keyboardShortcuts.registerShortcut("station.lowerVolumeLarge", {
  850. keyCode: 40, // Down arrow key
  851. shift: false,
  852. ctrl: true,
  853. preventDefault: true,
  854. handler: () => {
  855. if (aModalIsOpen.value) return;
  856. volumeSliderValue.value -= 10;
  857. changeVolume();
  858. }
  859. });
  860. keyboardShortcuts.registerShortcut("station.lowerVolumeSmall", {
  861. keyCode: 40, // Down arrow key
  862. shift: true,
  863. ctrl: true,
  864. preventDefault: true,
  865. handler: () => {
  866. if (aModalIsOpen.value) return;
  867. volumeSliderValue.value -= 1;
  868. changeVolume();
  869. }
  870. });
  871. keyboardShortcuts.registerShortcut("station.increaseVolumeLarge", {
  872. keyCode: 38, // Up arrow key
  873. shift: false,
  874. ctrl: true,
  875. preventDefault: true,
  876. handler: () => {
  877. if (aModalIsOpen.value) return;
  878. volumeSliderValue.value += 10;
  879. changeVolume();
  880. }
  881. });
  882. keyboardShortcuts.registerShortcut("station.increaseVolumeSmall", {
  883. keyCode: 38, // Up arrow key
  884. shift: true,
  885. ctrl: true,
  886. preventDefault: true,
  887. handler: () => {
  888. if (aModalIsOpen.value) return;
  889. volumeSliderValue.value += 1;
  890. changeVolume();
  891. }
  892. });
  893. keyboardShortcuts.registerShortcut("station.toggleDebug", {
  894. keyCode: 68, // D key
  895. shift: false,
  896. ctrl: true,
  897. preventDefault: true,
  898. handler: () => {
  899. if (aModalIsOpen.value) return;
  900. togglePlayerDebugBox();
  901. }
  902. });
  903. keyboardShortcuts.registerShortcut(
  904. "station.toggleKeyboardShortcutsHelper",
  905. {
  906. keyCode: 191, // '/' key
  907. ctrl: true,
  908. preventDefault: true,
  909. handler: () => {
  910. if (aModalIsOpen.value) return;
  911. toggleKeyboardShortcutsHelper();
  912. }
  913. }
  914. );
  915. keyboardShortcuts.registerShortcut(
  916. "station.resetKeyboardShortcutsHelper",
  917. {
  918. keyCode: 191, // '/' key
  919. ctrl: true,
  920. shift: true,
  921. preventDefault: true,
  922. handler: () => {
  923. if (aModalIsOpen.value) return;
  924. resetKeyboardShortcutsHelper();
  925. }
  926. }
  927. );
  928. // UNIX client time before ping
  929. const beforePing = Date.now();
  930. socket.dispatch("apis.ping", res => {
  931. if (res.status === "success") {
  932. // UNIX client time after ping
  933. const afterPing = Date.now();
  934. // Average time in MS it took between the server responding and the client receiving
  935. const connectionLatency = (afterPing - beforePing) / 2;
  936. console.log(connectionLatency, beforePing - afterPing);
  937. // UNIX server time
  938. const serverDate = res.data.date;
  939. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  940. const difference =
  941. serverDate + connectionLatency - afterPing;
  942. console.log("Difference: ", difference);
  943. if (difference > 3000 || difference < -3000) {
  944. console.log(
  945. "System time difference is bigger than 3 seconds."
  946. );
  947. }
  948. systemDifference.value = difference;
  949. }
  950. });
  951. } else {
  952. loading.value = false;
  953. exists.value = false;
  954. }
  955. });
  956. };
  957. const sendActivityWatchVideoData = () => {
  958. if (!stationPaused.value && !localPaused.value && !noSong.value) {
  959. if (activityWatchVideoLastStatus.value !== "playing") {
  960. activityWatchVideoLastStatus.value = "playing";
  961. activityWatchVideoLastStatus.value =
  962. currentSong.value.skipDuration + getTimeElapsed();
  963. }
  964. if (
  965. activityWatchVideoLastYouTubeId.value !==
  966. currentSong.value.youtubeId
  967. ) {
  968. activityWatchVideoLastYouTubeId.value = currentSong.value.youtubeId;
  969. activityWatchVideoLastStatus.value =
  970. currentSong.value.skipDuration + getTimeElapsed();
  971. }
  972. const videoData = {
  973. title: currentSong.value ? currentSong.value.title : null,
  974. artists:
  975. currentSong.value && currentSong.value.artists
  976. ? currentSong.value.artists.join(", ")
  977. : null,
  978. youtubeId: currentSong.value.youtubeId,
  979. muted: muted.value,
  980. volume: volumeSliderValue.value,
  981. startedDuration:
  982. activityWatchVideoLastStatus.value <= 0
  983. ? 0
  984. : Math.floor(activityWatchVideoLastStatus.value / 1000),
  985. source: `station#${station.value.name}`,
  986. hostname: window.location.hostname
  987. };
  988. aw.sendVideoData(videoData);
  989. } else {
  990. activityWatchVideoLastStatus.value = "not_playing";
  991. }
  992. };
  993. watch(
  994. () => autoRequest.value.length,
  995. () => {
  996. autoRequestSong();
  997. }
  998. );
  999. onMounted(async () => {
  1000. // TODO
  1001. // editSongModalWatcher.value = store.watch(
  1002. // state =>
  1003. // state.modalVisibility.activeModals.length > 0 &&
  1004. // state.modalVisibility.modals[
  1005. // state.modalVisibility.activeModals[
  1006. // state.modalVisibility.activeModals.length - 1
  1007. // ]
  1008. // ] === "editSong"
  1009. // ? state.modals.editSong[
  1010. // state.modalVisibility.activeModals[
  1011. // state.modalVisibility.activeModals.length - 1
  1012. // ]
  1013. // ].video.paused
  1014. // : null,
  1015. // paused => {
  1016. // if (paused && !beforeEditSongModalLocalPaused.value) {
  1017. // resumeLocalStation();
  1018. // } else if (!paused) {
  1019. // beforeEditSongModalLocalPaused.value = localPaused.value;
  1020. // pauseLocalStation();
  1021. // }
  1022. // }
  1023. // );
  1024. window.scrollTo(0, 0);
  1025. Date.currently = () => new Date().getTime() + systemDifference.value;
  1026. stationIdentifier.value = route.params.id;
  1027. window.stationInterval = 0;
  1028. activityWatchVideoDataInterval.value = setInterval(() => {
  1029. sendActivityWatchVideoData();
  1030. }, 1000);
  1031. persistentToastCheckerInterval.value = setInterval(() => {
  1032. persistentToasts.value.filter(
  1033. persistentToast => !persistentToast.checkIfCanRemove()
  1034. );
  1035. }, 1000);
  1036. if (socket.readyState === 1) join();
  1037. ws.onConnect(() => {
  1038. socketConnected.value = true;
  1039. clearTimeout(window.stationNextSongTimeout);
  1040. join();
  1041. });
  1042. ws.onDisconnect(true, () => {
  1043. socketConnected.value = false;
  1044. const _currentSong = currentSong.value.currentSong;
  1045. if (nextSong.value)
  1046. setNextCurrentSong(
  1047. {
  1048. currentSong: nextSong.value,
  1049. startedAt: Date.now() + getTimeRemaining(),
  1050. paused: false,
  1051. timePaused: 0
  1052. },
  1053. true
  1054. );
  1055. else
  1056. setNextCurrentSong(
  1057. {
  1058. currentSong: null,
  1059. startedAt: 0,
  1060. paused: false,
  1061. timePaused: 0,
  1062. pausedAt: 0
  1063. },
  1064. true
  1065. );
  1066. window.stationNextSongTimeout = setTimeout(() => {
  1067. if (!noSong.value && currentSong.value._id === _currentSong._id)
  1068. skipSong("window.stationNextSongTimeout 2");
  1069. }, getTimeRemaining());
  1070. });
  1071. frontendDevMode.value = await lofig.get("mode");
  1072. mediasession.value = await lofig.get("siteSettings.mediasession");
  1073. christmas.value = await lofig.get("siteSettings.christmas");
  1074. sitename.value = await lofig.get("siteSettings.sitename");
  1075. socket.dispatch("stations.existsByName", stationIdentifier.value, res => {
  1076. if (res.status === "error" || !res.data.exists) {
  1077. // station identifier may be using stationid instead
  1078. socket.dispatch(
  1079. "stations.existsById",
  1080. stationIdentifier.value,
  1081. res => {
  1082. if (res.status === "error" || !res.data.exists) {
  1083. loading.value = false;
  1084. exists.value = false;
  1085. }
  1086. }
  1087. );
  1088. }
  1089. });
  1090. ms.setListeners(0, {
  1091. play: () => {
  1092. if (hasPermission("stations.resume")) resumeStation();
  1093. else resumeLocalStation();
  1094. },
  1095. pause: () => {
  1096. if (hasPermission("stations.pause")) pauseStation();
  1097. else pauseLocalStation();
  1098. },
  1099. nexttrack: () => {
  1100. if (hasPermission("stations.skip")) skipStation();
  1101. else voteSkipStation();
  1102. }
  1103. });
  1104. socket.on("event:station.nextSong", res => {
  1105. const { currentSong, startedAt, paused, timePaused } = res.data;
  1106. setCurrentSong({
  1107. currentSong,
  1108. startedAt,
  1109. paused,
  1110. timePaused,
  1111. pausedAt: 0
  1112. });
  1113. });
  1114. socket.on("event:station.pause", res => {
  1115. pausedAt.value = res.data.pausedAt;
  1116. updateStationPaused(true);
  1117. pauseLocalPlayer();
  1118. clearTimeout(window.stationNextSongTimeout);
  1119. });
  1120. socket.on("event:station.resume", res => {
  1121. timePaused.value = res.data.timePaused;
  1122. updateStationPaused(false);
  1123. if (!localPaused.value) resumeLocalPlayer();
  1124. autoRequestSong();
  1125. });
  1126. socket.on("event:station.deleted", () => {
  1127. window.location.href = "/?msg=The station you were in was deleted.";
  1128. return true;
  1129. });
  1130. socket.on("event:ratings.liked", res => {
  1131. if (!noSong.value) {
  1132. if (res.data.youtubeId === currentSong.value.youtubeId) {
  1133. updateCurrentSongRatings(res.data);
  1134. }
  1135. }
  1136. });
  1137. socket.on("event:ratings.disliked", res => {
  1138. if (!noSong.value) {
  1139. if (res.data.youtubeId === currentSong.value.youtubeId) {
  1140. updateCurrentSongRatings(res.data);
  1141. }
  1142. }
  1143. });
  1144. socket.on("event:ratings.unliked", res => {
  1145. if (!noSong.value) {
  1146. if (res.data.youtubeId === currentSong.value.youtubeId) {
  1147. updateCurrentSongRatings(res.data);
  1148. }
  1149. }
  1150. });
  1151. socket.on("event:ratings.undisliked", res => {
  1152. if (!noSong.value) {
  1153. if (res.data.youtubeId === currentSong.value.youtubeId) {
  1154. updateCurrentSongRatings(res.data);
  1155. }
  1156. }
  1157. });
  1158. socket.on("event:ratings.updated", res => {
  1159. if (!noSong.value) {
  1160. if (res.data.youtubeId === currentSong.value.youtubeId) {
  1161. updateOwnCurrentSongRatings(res.data);
  1162. }
  1163. }
  1164. });
  1165. socket.on("event:station.queue.updated", res => {
  1166. updateSongsList(res.data.queue);
  1167. let nextSong = null;
  1168. if (songsList.value[0])
  1169. nextSong = songsList.value[0].youtubeId ? songsList.value[0] : null;
  1170. updateNextSong(nextSong);
  1171. autoRequestSong();
  1172. });
  1173. socket.on("event:station.queue.song.repositioned", res => {
  1174. repositionSongInList(res.data.song);
  1175. let nextSong = null;
  1176. if (songsList.value[0])
  1177. nextSong = songsList.value[0].youtubeId ? songsList.value[0] : null;
  1178. updateNextSong(nextSong);
  1179. });
  1180. socket.on("event:station.voteSkipSong", () => {
  1181. if (currentSong.value)
  1182. updateCurrentSongSkipVotes({
  1183. skipVotes: currentSong.value.skipVotes + 1,
  1184. skipVotesCurrent: null
  1185. });
  1186. });
  1187. socket.on("event:station.updated", async res => {
  1188. const { name, theme, privacy } = res.data.station;
  1189. if (!hasPermission("stations.view") && privacy === "private") {
  1190. window.location.href =
  1191. "/?msg=The station you were in was made private.";
  1192. } else {
  1193. if (station.value.name !== name) {
  1194. await router.push(
  1195. `${name}?${Object.keys(route.query)
  1196. .map(
  1197. key =>
  1198. `${encodeURIComponent(
  1199. key
  1200. )}=${encodeURIComponent(route.query[key])}`
  1201. )
  1202. .join("&")}`
  1203. );
  1204. // eslint-disable-next-line no-restricted-globals
  1205. history.replaceState({ ...history.state, ...{} }, null);
  1206. }
  1207. if (station.value.theme !== theme)
  1208. document.getElementsByTagName(
  1209. "html"
  1210. )[0].style.cssText = `--primary-color: var(--${theme})`;
  1211. updateStation(res.data.station);
  1212. }
  1213. });
  1214. socket.on("event:station.users.updated", res =>
  1215. updateUsers(res.data.users)
  1216. );
  1217. socket.on("event:station.userCount.updated", res =>
  1218. updateUserCount(res.data.userCount)
  1219. );
  1220. socket.on("event:user.station.favorited", res => {
  1221. if (res.data.stationId === station.value._id)
  1222. updateIfStationIsFavorited({ isFavorited: true });
  1223. });
  1224. socket.on("event:user.station.unfavorited", res => {
  1225. if (res.data.stationId === station.value._id)
  1226. updateIfStationIsFavorited({ isFavorited: false });
  1227. });
  1228. if (JSON.parse(localStorage.getItem("muted"))) {
  1229. muted.value = true;
  1230. player.value.setVolume(0);
  1231. volumeSliderValue.value = 0;
  1232. } else {
  1233. let volume = parseFloat(localStorage.getItem("volume"));
  1234. volume =
  1235. typeof volume === "number" && !Number.isNaN(volume) ? volume : 20;
  1236. localStorage.setItem("volume", volume);
  1237. volumeSliderValue.value = volume;
  1238. }
  1239. });
  1240. onBeforeUnmount(() => {
  1241. document.getElementsByTagName("html")[0].style.cssText = "";
  1242. if (mediasession.value) {
  1243. ms.removeListeners(0);
  1244. ms.removeMediaSessionData(0);
  1245. }
  1246. /** Reset Songslist */
  1247. updateSongsList([]);
  1248. const shortcutNames = [
  1249. "station.pauseResume",
  1250. "station.skipStation",
  1251. "station.lowerVolumeLarge",
  1252. "station.lowerVolumeSmall",
  1253. "station.increaseVolumeLarge",
  1254. "station.increaseVolumeSmall",
  1255. "station.toggleDebug"
  1256. ];
  1257. shortcutNames.forEach(shortcutName => {
  1258. keyboardShortcuts.unregisterShortcut(shortcutName);
  1259. });
  1260. // editSongModalWatcher.value(); // removes the watcher
  1261. clearInterval(activityWatchVideoDataInterval.value);
  1262. clearTimeout(window.stationNextSongTimeout);
  1263. clearTimeout(persistentToastCheckerInterval.value);
  1264. persistentToasts.value.forEach(persistentToast => {
  1265. persistentToast.toast.destroy();
  1266. });
  1267. socket.dispatch("stations.leave", station.value._id, () => {});
  1268. leaveStation();
  1269. });
  1270. </script>
  1271. <template>
  1272. <div>
  1273. <page-metadata
  1274. v-if="exists && !loading"
  1275. :title="`${station.displayName}`"
  1276. />
  1277. <page-metadata v-else-if="!exists && !loading" :title="`Not found`" />
  1278. <div id="page-loader-container" v-if="loading">
  1279. <content-loader
  1280. width="1920"
  1281. height="1080"
  1282. :primary-color="nightmode ? '#222' : '#fff'"
  1283. :secondary-color="nightmode ? '#444' : '#ddd'"
  1284. preserve-aspect-ratio="none"
  1285. id="page-loader-content"
  1286. >
  1287. <rect x="55" y="105" rx="5" ry="5" width="670" height="149" />
  1288. <rect x="55" y="283" rx="5" ry="5" width="670" height="640" />
  1289. <rect x="745" y="108" rx="5" ry="5" width="1120" height="672" />
  1290. <rect x="745" y="810" rx="5" ry="5" width="1120" height="110" />
  1291. </content-loader>
  1292. <content-loader
  1293. width="1920"
  1294. height="1080"
  1295. :primary-color="nightmode ? '#222' : '#fff'"
  1296. :secondary-color="nightmode ? '#444' : '#ddd'"
  1297. preserve-aspect-ratio="none"
  1298. id="page-loader-layout"
  1299. >
  1300. <rect x="0" y="0" rx="0" ry="0" width="1920" height="64" />
  1301. <rect x="0" y="980" rx="0" ry="0" width="1920" height="100" />
  1302. </content-loader>
  1303. </div>
  1304. <!-- More simplistic loading animation for mobile users -->
  1305. <div v-show="loading" id="mobile-progress-animation" />
  1306. <ul
  1307. v-if="
  1308. currentSong &&
  1309. (currentSong.youtubeId === 'l9PxOanFjxQ' ||
  1310. currentSong.youtubeId === 'xKVcVSYmesU' ||
  1311. currentSong.youtubeId === '60ItHLz5WEA' ||
  1312. currentSong.youtubeId === 'e6vkFbtSGm0')
  1313. "
  1314. class="bg-bubbles"
  1315. >
  1316. <li></li>
  1317. <li></li>
  1318. <li></li>
  1319. <li></li>
  1320. <li></li>
  1321. <li></li>
  1322. <li></li>
  1323. <li></li>
  1324. <li></li>
  1325. <li></li>
  1326. </ul>
  1327. <div v-show="!loading && exists">
  1328. <main-header />
  1329. <div id="station-outer-container">
  1330. <div
  1331. id="station-inner-container"
  1332. :class="{ 'nothing-here': noSong }"
  1333. >
  1334. <div id="station-left-column" class="column">
  1335. <!-- div with quadrant class -->
  1336. <div class="quadrant">
  1337. <station-info-box
  1338. :station="station"
  1339. :station-paused="stationPaused"
  1340. :show-manage-station="true"
  1341. />
  1342. </div>
  1343. <div id="sidebar-container" class="quadrant">
  1344. <station-sidebar />
  1345. </div>
  1346. </div>
  1347. <div id="station-right-column" class="column">
  1348. <div class="player-container quadrant" v-show="!noSong">
  1349. <div id="video-container">
  1350. <div
  1351. id="stationPlayer"
  1352. style="
  1353. width: 100%;
  1354. height: 100%;
  1355. min-height: 200px;
  1356. "
  1357. />
  1358. <div
  1359. class="player-cannot-autoplay"
  1360. v-if="!canAutoplay"
  1361. @click="increaseVolume()"
  1362. >
  1363. <p>
  1364. Please click anywhere on the screen for
  1365. the video to start
  1366. </p>
  1367. </div>
  1368. </div>
  1369. <div id="seeker-bar-container">
  1370. <div
  1371. id="seeker-bar"
  1372. :class="{
  1373. 'christmas-seeker': christmas,
  1374. nyan:
  1375. currentSong &&
  1376. currentSong.youtubeId ===
  1377. 'QH2-TGUlwu4'
  1378. }"
  1379. />
  1380. <div
  1381. class="seeker-bar-cover"
  1382. :style="{
  1383. width: `calc(100% - ${seekerbarPercentage}%)`
  1384. }"
  1385. ></div>
  1386. <img
  1387. v-if="
  1388. currentSong &&
  1389. currentSong.youtubeId === 'QH2-TGUlwu4'
  1390. "
  1391. src="https://freepngimg.com/thumb/nyan_cat/1-2-nyan-cat-free-download-png.png"
  1392. :style="{
  1393. position: 'absolute',
  1394. top: `-10px`,
  1395. left: `${seekerbarPercentage}%`,
  1396. width: '50px'
  1397. }"
  1398. />
  1399. <img
  1400. v-if="
  1401. currentSong &&
  1402. (currentSong.youtubeId ===
  1403. 'DtVBCG6ThDk' ||
  1404. currentSong.youtubeId ===
  1405. 'sI66hcu9fIs' ||
  1406. currentSong.youtubeId ===
  1407. 'iYYRH4apXDo' ||
  1408. currentSong.youtubeId ===
  1409. 'tRcPA7Fzebw')
  1410. "
  1411. src="/assets/rocket.svg"
  1412. :style="{
  1413. position: 'absolute',
  1414. top: `-21px`,
  1415. left: `calc(${seekerbarPercentage}% - 35px)`,
  1416. width: '50px',
  1417. transform: 'rotate(45deg)'
  1418. }"
  1419. />
  1420. <img
  1421. v-if="
  1422. currentSong &&
  1423. currentSong.youtubeId === 'jofNR_WkoCE'
  1424. "
  1425. src="/assets/fox.svg"
  1426. :style="{
  1427. position: 'absolute',
  1428. top: `-21px`,
  1429. left: `calc(${seekerbarPercentage}% - 35px)`,
  1430. width: '50px',
  1431. transform: 'scaleX(-1)',
  1432. opacity: 1
  1433. }"
  1434. />
  1435. <img
  1436. v-if="
  1437. currentSong &&
  1438. (currentSong.youtubeId ===
  1439. 'l9PxOanFjxQ' ||
  1440. currentSong.youtubeId ===
  1441. 'xKVcVSYmesU' ||
  1442. currentSong.youtubeId ===
  1443. '60ItHLz5WEA' ||
  1444. currentSong.youtubeId ===
  1445. 'e6vkFbtSGm0')
  1446. "
  1447. src="/assets/old_logo.png"
  1448. :style="{
  1449. position: 'absolute',
  1450. top: `-9px`,
  1451. left: `calc(${seekerbarPercentage}% - 22px)`,
  1452. 'background-color': 'rgb(96, 199, 169)',
  1453. width: '25px',
  1454. height: '25px',
  1455. 'border-radius': '25px'
  1456. }"
  1457. />
  1458. <img
  1459. v-if="
  1460. christmas &&
  1461. currentSong &&
  1462. ![
  1463. 'QH2-TGUlwu4',
  1464. 'DtVBCG6ThDk',
  1465. 'sI66hcu9fIs',
  1466. 'iYYRH4apXDo',
  1467. 'tRcPA7Fzebw',
  1468. 'jofNR_WkoCE',
  1469. 'l9PxOanFjxQ',
  1470. 'xKVcVSYmesU',
  1471. '60ItHLz5WEA',
  1472. 'e6vkFbtSGm0'
  1473. ].includes(currentSong.youtubeId)
  1474. "
  1475. src="/assets/santa.png"
  1476. :style="{
  1477. position: 'absolute',
  1478. top: `-30px`,
  1479. left: `calc(${seekerbarPercentage}% - 25px)`,
  1480. height: '50px',
  1481. transform: 'scaleX(-1)'
  1482. }"
  1483. />
  1484. </div>
  1485. <div id="control-bar-container">
  1486. <div id="left-buttons">
  1487. <!-- Debug Box -->
  1488. <button
  1489. v-if="frontendDevMode === 'development'"
  1490. class="button is-primary"
  1491. @click="togglePlayerDebugBox()"
  1492. @dblclick="resetPlayerDebugBox()"
  1493. content="Debug"
  1494. v-tippy
  1495. >
  1496. <i
  1497. class="material-icons icon-with-button"
  1498. >
  1499. bug_report
  1500. </i>
  1501. </button>
  1502. <!-- Local Pause/Resume Button -->
  1503. <button
  1504. class="button is-primary"
  1505. @click="resumeLocalStation()"
  1506. id="local-resume"
  1507. v-if="localPaused"
  1508. content="Unpause Playback"
  1509. v-tippy
  1510. >
  1511. <i class="material-icons">play_arrow</i>
  1512. </button>
  1513. <button
  1514. class="button is-primary"
  1515. @click="pauseLocalStation()"
  1516. id="local-pause"
  1517. v-else
  1518. content="Pause Playback"
  1519. v-tippy
  1520. >
  1521. <i class="material-icons">pause</i>
  1522. </button>
  1523. <!-- Vote to Skip Button -->
  1524. <button
  1525. v-if="!skipVotesLoaded"
  1526. class="button is-primary disabled"
  1527. content="Skip votes have not been loaded yet"
  1528. v-tippy
  1529. >
  1530. <i
  1531. class="material-icons icon-with-button"
  1532. >skip_next</i
  1533. >
  1534. </button>
  1535. <button
  1536. v-else-if="loggedIn"
  1537. class="button is-primary"
  1538. @click="voteSkipStation()"
  1539. content="Vote to Skip Song"
  1540. v-tippy
  1541. >
  1542. <i
  1543. class="material-icons icon-with-button"
  1544. >skip_next</i
  1545. >
  1546. {{ currentSong.skipVotes }}
  1547. </button>
  1548. <button
  1549. v-else
  1550. class="button is-primary disabled"
  1551. content="Log in to vote to skip songs"
  1552. v-tippy="{ theme: 'info' }"
  1553. >
  1554. <i
  1555. class="material-icons icon-with-button"
  1556. >skip_next</i
  1557. >
  1558. {{ currentSong.skipVotes }}
  1559. </button>
  1560. </div>
  1561. <div id="duration">
  1562. <p>
  1563. {{ timeElapsed }} /
  1564. {{
  1565. utils.formatTime(
  1566. currentSong.duration
  1567. )
  1568. }}
  1569. </p>
  1570. </div>
  1571. <p id="volume-control" v-if="!isApple">
  1572. <i
  1573. class="material-icons"
  1574. @click="toggleMute()"
  1575. :content="`${
  1576. muted ? 'Unmute' : 'Mute'
  1577. }`"
  1578. v-tippy
  1579. >{{
  1580. muted
  1581. ? "volume_mute"
  1582. : volumeSliderValue >= 50
  1583. ? "volume_up"
  1584. : "volume_down"
  1585. }}</i
  1586. >
  1587. <input
  1588. v-model="volumeSliderValue"
  1589. type="range"
  1590. min="0"
  1591. max="100"
  1592. class="volume-slider active"
  1593. @change="changeVolume()"
  1594. @input="changeVolume()"
  1595. />
  1596. </p>
  1597. <div id="right-buttons" v-if="loggedIn">
  1598. <!-- Ratings (Like/Dislike) Buttons -->
  1599. <div
  1600. id="ratings"
  1601. v-if="ratingsLoaded && ownRatingsLoaded"
  1602. :class="{
  1603. liked: currentSong.liked,
  1604. disliked: currentSong.disliked
  1605. }"
  1606. >
  1607. <!-- Like Song Button -->
  1608. <button
  1609. class="button is-success like-song"
  1610. id="like-song"
  1611. @click="toggleLike()"
  1612. content="Like Song"
  1613. v-tippy
  1614. >
  1615. <i
  1616. class="material-icons icon-with-button"
  1617. :class="{
  1618. liked: currentSong.liked
  1619. }"
  1620. >thumb_up_alt</i
  1621. >{{ currentSong.likes }}
  1622. </button>
  1623. <!-- Dislike Song Button -->
  1624. <button
  1625. class="button is-danger dislike-song"
  1626. id="dislike-song"
  1627. @click="toggleDislike()"
  1628. content="Dislike Song"
  1629. v-tippy
  1630. >
  1631. <i
  1632. class="material-icons icon-with-button"
  1633. :class="{
  1634. disliked:
  1635. currentSong.disliked
  1636. }"
  1637. >thumb_down_alt</i
  1638. >{{ currentSong.dislikes }}
  1639. </button>
  1640. </div>
  1641. <div id="ratings" class="disabled" v-else>
  1642. <!-- Like Song Button -->
  1643. <button
  1644. class="button is-success like-song disabled"
  1645. id="like-song"
  1646. content="Ratings have not been loaded yet"
  1647. v-tippy
  1648. >
  1649. <i
  1650. class="material-icons icon-with-button"
  1651. >thumb_up_alt</i
  1652. >
  1653. </button>
  1654. <!-- Dislike Song Button -->
  1655. <button
  1656. class="button is-danger dislike-song disabled"
  1657. id="dislike-song"
  1658. content="Ratings have not been loaded yet"
  1659. v-tippy
  1660. >
  1661. <i
  1662. class="material-icons icon-with-button"
  1663. >thumb_down_alt</i
  1664. >
  1665. </button>
  1666. </div>
  1667. <!-- Add Song To Playlist Button & Dropdown -->
  1668. <add-to-playlist-dropdown
  1669. :song="currentSong"
  1670. placement="top-end"
  1671. >
  1672. <template #button>
  1673. <div
  1674. id="add-song-to-playlist"
  1675. content="Add Song to Playlist"
  1676. v-tippy
  1677. >
  1678. <div class="control has-addons">
  1679. <button
  1680. class="button is-primary"
  1681. >
  1682. <i
  1683. class="material-icons"
  1684. >
  1685. playlist_add
  1686. </i>
  1687. </button>
  1688. <button
  1689. class="button"
  1690. id="dropdown-toggle"
  1691. >
  1692. <i
  1693. class="material-icons"
  1694. >
  1695. {{
  1696. showPlaylistDropdown
  1697. ? "expand_more"
  1698. : "expand_less"
  1699. }}
  1700. </i>
  1701. </button>
  1702. </div>
  1703. </div>
  1704. </template>
  1705. </add-to-playlist-dropdown>
  1706. </div>
  1707. <div id="right-buttons" v-else>
  1708. <!-- Disabled Ratings (Like/Dislike) Buttons -->
  1709. <div id="ratings" v-if="ratingsLoaded">
  1710. <!-- Disabled Like Song Button -->
  1711. <button
  1712. class="button is-success disabled"
  1713. id="like-song"
  1714. content="Log in to like songs"
  1715. v-tippy="{ theme: 'info' }"
  1716. >
  1717. <i
  1718. class="material-icons icon-with-button"
  1719. >thumb_up_alt</i
  1720. >{{ currentSong.likes }}
  1721. </button>
  1722. <!-- Disabled Dislike Song Button -->
  1723. <button
  1724. class="button is-danger disabled"
  1725. id="dislike-song"
  1726. content="Log in to dislike songs"
  1727. v-tippy="{ theme: 'info' }"
  1728. >
  1729. <i
  1730. class="material-icons icon-with-button"
  1731. >thumb_down_alt</i
  1732. >{{ currentSong.dislikes }}
  1733. </button>
  1734. </div>
  1735. <div id="ratings" v-else>
  1736. <!-- Disabled Like Song Button -->
  1737. <button
  1738. class="button is-success disabled"
  1739. id="like-song"
  1740. content="Ratings have not been loaded yet"
  1741. v-tippy="{ theme: 'info' }"
  1742. >
  1743. <i
  1744. class="material-icons icon-with-button"
  1745. >thumb_up_alt</i
  1746. >
  1747. </button>
  1748. <!-- Disabled Dislike Song Button -->
  1749. <button
  1750. class="button is-danger disabled"
  1751. id="dislike-song"
  1752. content="Ratings have not been loaded yet"
  1753. v-tippy="{ theme: 'info' }"
  1754. >
  1755. <i
  1756. class="material-icons icon-with-button"
  1757. >thumb_down_alt</i
  1758. >
  1759. </button>
  1760. </div>
  1761. <!-- Disabled Add Song To Playlist Button & Dropdown -->
  1762. <div id="add-song-to-playlist">
  1763. <div class="control has-addons">
  1764. <button
  1765. class="button is-primary disabled"
  1766. content="Log in to add songs to playlist"
  1767. v-tippy="{ theme: 'info' }"
  1768. >
  1769. <i class="material-icons"
  1770. >queue</i
  1771. >
  1772. </button>
  1773. </div>
  1774. </div>
  1775. </div>
  1776. </div>
  1777. </div>
  1778. <p
  1779. class="player-container nothing-here-text"
  1780. v-if="noSong"
  1781. >
  1782. No song is currently playing
  1783. </p>
  1784. <div v-if="!noSong" id="current-next-row">
  1785. <div
  1786. id="currently-playing-container"
  1787. class="quadrant"
  1788. :class="{ 'no-currently-playing': noSong }"
  1789. >
  1790. <song-item
  1791. :key="`songItem-currentSong-${currentSong._id}`"
  1792. :song="currentSong"
  1793. :duration="false"
  1794. :requested-by="true"
  1795. header="Currently Playing.."
  1796. />
  1797. </div>
  1798. <div
  1799. v-if="nextSong"
  1800. id="next-up-container"
  1801. class="quadrant"
  1802. >
  1803. <song-item
  1804. :key="`songItem-nextSong-${nextSong._id}`"
  1805. :song="nextSong"
  1806. :duration="false"
  1807. :requested-by="true"
  1808. header="Next Up.."
  1809. />
  1810. </div>
  1811. </div>
  1812. </div>
  1813. </div>
  1814. </div>
  1815. <main-footer />
  1816. </div>
  1817. <floating-box
  1818. id="player-debug-box"
  1819. ref="playerDebugBox"
  1820. title="Station Debug"
  1821. >
  1822. <template #body>
  1823. <span><b>No song</b>: {{ noSong }}</span>
  1824. <span><b>Song id</b>: {{ currentSong._id }}</span>
  1825. <span><b>YouTube id</b>: {{ currentSong.youtubeId }}</span>
  1826. <span><b>Duration</b>: {{ currentSong.duration }}</span>
  1827. <span
  1828. ><b>Skip duration</b>: {{ currentSong.skipDuration }}</span
  1829. >
  1830. <span><b>Loading</b>: {{ loading }}</span>
  1831. <span><b>Can autoplay</b>: {{ canAutoplay }}</span>
  1832. <span><b>Player ready</b>: {{ playerReady }}</span>
  1833. <span
  1834. ><b>Attempts to play video</b>:
  1835. {{ attemptsToPlayVideo }}</span
  1836. >
  1837. <span
  1838. ><b>Last time requested if can autoplay</b>:
  1839. {{ lastTimeRequestedIfCanAutoplay }}</span
  1840. >
  1841. <span><b>Seeking</b>: {{ seeking }}</span>
  1842. <span><b>Playback rate</b>: {{ playbackRate }}</span>
  1843. <span><b>System difference</b>: {{ systemDifference }}</span>
  1844. <span><b>Time before paused</b>: {{ timeBeforePause }}</span>
  1845. <span><b>Time paused</b>: {{ timePaused }}</span>
  1846. <span><b>Time elapsed</b>: {{ timeElapsed }}</span>
  1847. <span><b>Volume slider value</b>: {{ volumeSliderValue }}</span>
  1848. <span><b>Local paused</b>: {{ localPaused }}</span>
  1849. <span><b>Station paused</b>: {{ stationPaused }}</span>
  1850. <span
  1851. ><b>Requests enabled</b>:
  1852. {{ station.requests.enabled }}</span
  1853. >
  1854. <span
  1855. ><b>Requests access</b>: {{ station.requests.access }}</span
  1856. >
  1857. <span><b>Requests limit</b>: {{ station.requests.limit }}</span>
  1858. <span
  1859. ><b>Auto requesting playlists</b>:
  1860. {{
  1861. autoRequest.map(playlist => playlist._id).join(", ")
  1862. }}</span
  1863. >
  1864. <span
  1865. ><b>Autofill enabled</b>:
  1866. {{ station.autofill.enabled }}</span
  1867. >
  1868. <span><b>Autofill limit</b>: {{ station.autofill.limit }}</span>
  1869. <span><b>Autofill mode</b>: {{ station.autofill.mode }}</span>
  1870. <span><b>Skip votes loaded</b>: {{ skipVotesLoaded }}</span>
  1871. <span
  1872. ><b>Skip votes current</b>:
  1873. {{
  1874. currentSong.skipVotesCurrent === true ||
  1875. currentSong.skipVotesCurrent === false
  1876. ? currentSong.skipVotesCurrent
  1877. : "N/A"
  1878. }}</span
  1879. >
  1880. <span
  1881. ><b>Skip votes</b>:
  1882. {{ skipVotesLoaded ? currentSong.skipVotes : "N/A" }}</span
  1883. >
  1884. <span><b>Ratings loaded</b>: {{ ratingsLoaded }}</span>
  1885. <span
  1886. ><b>Ratings</b>:
  1887. {{
  1888. ratingsLoaded
  1889. ? `${currentSong.likes} / ${currentSong.dislikes}`
  1890. : "N/A"
  1891. }}</span
  1892. >
  1893. <span><b>Own ratings loaded</b>: {{ ownRatingsLoaded }}</span>
  1894. <span
  1895. ><b>Own ratings</b>:
  1896. {{
  1897. ownRatingsLoaded
  1898. ? `${currentSong.liked} / ${currentSong.disliked}`
  1899. : "N/A"
  1900. }}</span
  1901. >
  1902. </template>
  1903. </floating-box>
  1904. <floating-box
  1905. id="keyboardShortcutsHelper"
  1906. ref="keyboardShortcutsHelper"
  1907. title="Station Keyboard Shortcuts"
  1908. >
  1909. <template #body>
  1910. <div>
  1911. <div
  1912. v-if="
  1913. hasPermission('stations.resume') ||
  1914. hasPermission('stations.pause') ||
  1915. hasPermission('stations.skip')
  1916. "
  1917. >
  1918. <span class="biggest"><b>Admin/owner</b></span>
  1919. <span><b>Ctrl + Space</b> - Pause/resume station</span>
  1920. <span><b>Ctrl + Numpad right</b> - Skip station</span>
  1921. </div>
  1922. <hr
  1923. v-if="
  1924. hasPermission('stations.resume') ||
  1925. hasPermission('stations.pause') ||
  1926. hasPermission('stations.skip')
  1927. "
  1928. />
  1929. <div>
  1930. <span class="biggest"><b>Volume</b></span>
  1931. <span
  1932. ><b>Ctrl + Numpad up/down</b> - Volume up/down
  1933. 10%</span
  1934. >
  1935. <span
  1936. ><b>Ctrl + Shift + Numpad up/down</b> - Volume
  1937. up/down 10%</span
  1938. >
  1939. </div>
  1940. <hr />
  1941. <div>
  1942. <span class="biggest"><b>Misc</b></span>
  1943. <span><b>Ctrl + D</b> - Toggles debug box</span>
  1944. <span><b>Ctrl + Shift + D</b> - Resets debug box</span>
  1945. <span
  1946. ><b>Ctrl + /</b> - Toggles keyboard shortcuts
  1947. box</span
  1948. >
  1949. <span
  1950. ><b>Ctrl + Shift + /</b> - Resets keyboard shortcuts
  1951. box</span
  1952. >
  1953. </div>
  1954. </div>
  1955. </template>
  1956. </floating-box>
  1957. <Z404 v-if="!exists"></Z404>
  1958. </div>
  1959. </template>
  1960. <style lang="less">
  1961. #stationPlayer {
  1962. position: absolute;
  1963. top: 0;
  1964. left: 0;
  1965. width: 100%;
  1966. height: 100%;
  1967. }
  1968. #currently-playing-container,
  1969. #next-up-container {
  1970. .song-item {
  1971. .thumbnail {
  1972. min-width: 130px;
  1973. width: 130px;
  1974. height: 130px;
  1975. }
  1976. }
  1977. }
  1978. #control-bar-container
  1979. #right-buttons
  1980. .tippy-box[data-theme~="dropdown"]
  1981. .nav-dropdown-items {
  1982. padding-bottom: 0 !important;
  1983. }
  1984. </style>
  1985. <style lang="less" scoped>
  1986. #page-loader-container {
  1987. height: inherit;
  1988. #page-loader-content {
  1989. height: inherit;
  1990. position: absolute;
  1991. max-width: 100%;
  1992. width: 1800px;
  1993. transform: translateX(-50%);
  1994. left: 50%;
  1995. }
  1996. #page-loader-layout {
  1997. height: inherit;
  1998. width: 100%;
  1999. }
  2000. }
  2001. #mobile-progress-animation {
  2002. width: 50px;
  2003. animation: rotate 0.8s infinite linear;
  2004. border: 8px solid var(--primary-color);
  2005. border-right-color: transparent;
  2006. border-radius: 50%;
  2007. height: 50px;
  2008. position: absolute;
  2009. top: 50%;
  2010. left: 50%;
  2011. display: none;
  2012. }
  2013. @keyframes rotate {
  2014. 0% {
  2015. transform: rotate(0deg);
  2016. }
  2017. 100% {
  2018. transform: rotate(360deg);
  2019. }
  2020. }
  2021. .nav,
  2022. .button.is-primary {
  2023. background-color: var(--primary-color) !important;
  2024. }
  2025. .button.is-primary:hover,
  2026. .button.is-primary:focus {
  2027. filter: brightness(90%);
  2028. }
  2029. .night-mode {
  2030. #currently-playing-container,
  2031. #next-up-container,
  2032. #control-bar-container,
  2033. .quadrant:not(#sidebar-container),
  2034. .player-container {
  2035. background-color: var(--dark-grey-3) !important;
  2036. }
  2037. #video-container,
  2038. #control-bar-container,
  2039. .quadrant:not(#sidebar-container),
  2040. .player-container {
  2041. border: 0 !important;
  2042. }
  2043. #seeker-bar-container {
  2044. background-color: var(--dark-grey-3) !important;
  2045. }
  2046. #dropdown-toggle {
  2047. background-color: var(--dark-grey-2) !important;
  2048. border: 0;
  2049. i {
  2050. color: var(--white);
  2051. }
  2052. }
  2053. }
  2054. #station-outer-container {
  2055. margin: 0 auto;
  2056. padding: 20px 40px;
  2057. min-height: calc(100vh - 64px);
  2058. width: 100%;
  2059. max-width: 1800px;
  2060. display: flex;
  2061. #station-inner-container {
  2062. width: 100%;
  2063. min-height: calc(100vh - 428px);
  2064. display: flex;
  2065. flex-direction: row;
  2066. flex-wrap: wrap;
  2067. .row {
  2068. display: flex;
  2069. flex-direction: row;
  2070. max-width: 100%;
  2071. }
  2072. .column {
  2073. display: flex;
  2074. flex-direction: column;
  2075. }
  2076. .quadrant {
  2077. border-radius: @border-radius;
  2078. margin: 10px;
  2079. overflow: hidden;
  2080. }
  2081. .quadrant:not(#sidebar-container) {
  2082. background-color: var(--white);
  2083. border: 1px solid var(--light-grey-3);
  2084. }
  2085. #station-left-column,
  2086. #station-right-column {
  2087. padding: 0;
  2088. }
  2089. #current-next-row {
  2090. display: flex;
  2091. flex-direction: row;
  2092. #currently-playing-container,
  2093. #next-up-container {
  2094. overflow: hidden;
  2095. flex-basis: 50%;
  2096. .song-item {
  2097. border: unset;
  2098. }
  2099. .nothing-here-text {
  2100. height: 100%;
  2101. }
  2102. }
  2103. > div:only-child {
  2104. flex: 1 !important;
  2105. flex-basis: 100% !important;
  2106. }
  2107. }
  2108. .player-container {
  2109. height: inherit;
  2110. background-color: var(--white);
  2111. display: flex;
  2112. flex-direction: column;
  2113. border: 1px solid var(--light-grey-3);
  2114. border-radius: @border-radius;
  2115. overflow: hidden;
  2116. &.nothing-here-text {
  2117. margin: 10px;
  2118. flex: 1;
  2119. min-height: 487px;
  2120. }
  2121. #video-container {
  2122. position: relative;
  2123. padding-bottom: 56.25%; /* proportion value to aspect ratio 16:9 (9 / 16 = 0.5625 or 56.25%) */
  2124. height: 0;
  2125. overflow: hidden;
  2126. .player-cannot-autoplay {
  2127. position: relative;
  2128. width: 100%;
  2129. height: 100%;
  2130. bottom: calc(100% + 5px);
  2131. background: var(--primary-color);
  2132. display: flex;
  2133. align-items: center;
  2134. justify-content: center;
  2135. p {
  2136. color: var(--white);
  2137. font-size: 26px;
  2138. text-align: center;
  2139. }
  2140. }
  2141. }
  2142. #seeker-bar-container {
  2143. background-color: var(--white);
  2144. position: relative;
  2145. height: 7px;
  2146. display: block;
  2147. width: 100%;
  2148. #seeker-bar {
  2149. background-color: var(--primary-color);
  2150. top: 0;
  2151. left: 0;
  2152. bottom: 0;
  2153. position: absolute;
  2154. width: 100%;
  2155. }
  2156. .seeker-bar-cover {
  2157. position: absolute;
  2158. top: 0;
  2159. right: 0;
  2160. bottom: 0;
  2161. background-color: inherit;
  2162. }
  2163. }
  2164. #control-bar-container {
  2165. display: flex;
  2166. justify-content: space-around;
  2167. padding: 10px 0;
  2168. width: 100%;
  2169. background: var(--white);
  2170. flex-direction: column;
  2171. flex-flow: wrap;
  2172. .button:not(#dropdown-toggle) {
  2173. width: 75px;
  2174. }
  2175. #left-buttons,
  2176. #right-buttons {
  2177. margin: 3px;
  2178. }
  2179. #left-buttons {
  2180. display: flex;
  2181. .button:not(:first-of-type) {
  2182. margin-left: 5px;
  2183. }
  2184. .disabled {
  2185. filter: grayscale(0.4);
  2186. }
  2187. }
  2188. #duration {
  2189. margin: 3px;
  2190. display: flex;
  2191. align-items: center;
  2192. p {
  2193. font-size: 22px;
  2194. /** prevents duration width slightly varying and shifting other controls slightly */
  2195. width: 150px;
  2196. text-align: center;
  2197. }
  2198. }
  2199. #volume-control {
  2200. margin: 3px;
  2201. margin-top: 0;
  2202. display: flex;
  2203. align-items: center;
  2204. cursor: pointer;
  2205. .volume-slider {
  2206. width: 100%;
  2207. padding: 0 15px;
  2208. background: transparent;
  2209. min-width: 100px;
  2210. }
  2211. input[type="range"] {
  2212. -webkit-appearance: none;
  2213. margin: 7.3px 0;
  2214. }
  2215. input[type="range"]:focus {
  2216. outline: none;
  2217. }
  2218. input[type="range"]::-webkit-slider-runnable-track {
  2219. width: 100%;
  2220. height: 5.2px;
  2221. cursor: pointer;
  2222. box-shadow: 0;
  2223. background: var(--light-grey-3);
  2224. border-radius: @border-radius;
  2225. border: 0;
  2226. }
  2227. input[type="range"]::-webkit-slider-thumb {
  2228. box-shadow: 0;
  2229. border: 0;
  2230. height: 19px;
  2231. width: 19px;
  2232. border-radius: 100%;
  2233. background: var(--primary-color);
  2234. cursor: pointer;
  2235. -webkit-appearance: none;
  2236. margin-top: -6.5px;
  2237. }
  2238. input[type="range"]::-moz-range-track {
  2239. width: 100%;
  2240. height: 5.2px;
  2241. cursor: pointer;
  2242. box-shadow: 0;
  2243. background: var(--light-grey-3);
  2244. border-radius: @border-radius;
  2245. border: 0;
  2246. }
  2247. input[type="range"]::-moz-range-thumb {
  2248. box-shadow: 0;
  2249. border: 0;
  2250. height: 19px;
  2251. width: 19px;
  2252. border-radius: 100%;
  2253. background: var(--primary-color);
  2254. cursor: pointer;
  2255. -webkit-appearance: none;
  2256. margin-top: -6.5px;
  2257. }
  2258. input[type="range"]::-ms-track {
  2259. width: 100%;
  2260. height: 5.2px;
  2261. cursor: pointer;
  2262. box-shadow: 0;
  2263. background: var(--light-grey-3);
  2264. border-radius: @border-radius;
  2265. }
  2266. input[type="range"]::-ms-fill-lower {
  2267. background: var(--light-grey-3);
  2268. border: 0;
  2269. border-radius: 0;
  2270. box-shadow: 0;
  2271. }
  2272. input[type="range"]::-ms-fill-upper {
  2273. background: var(--light-grey-3);
  2274. border: 0;
  2275. border-radius: 0;
  2276. box-shadow: 0;
  2277. }
  2278. input[type="range"]::-ms-thumb {
  2279. box-shadow: 0;
  2280. border: 0;
  2281. height: 15px;
  2282. width: 15px;
  2283. border-radius: 100%;
  2284. background: var(--primary-color);
  2285. cursor: pointer;
  2286. -webkit-appearance: none;
  2287. margin-top: 1.5px;
  2288. }
  2289. }
  2290. #right-buttons {
  2291. display: flex;
  2292. #dropdown-toggle {
  2293. width: 35px;
  2294. }
  2295. #dislike-song,
  2296. #add-song-to-playlist .button:not(#dropdown-toggle) {
  2297. margin-left: 5px;
  2298. }
  2299. #ratings {
  2300. display: flex;
  2301. &.liked #dislike-song,
  2302. &.disliked #like-song {
  2303. background-color: var(--grey) !important;
  2304. }
  2305. #like-song.disabled,
  2306. #dislike-song.disabled {
  2307. filter: grayscale(0.4);
  2308. }
  2309. }
  2310. #add-song-to-playlist {
  2311. display: flex;
  2312. flex-direction: column-reverse;
  2313. #nav-dropdown {
  2314. position: absolute;
  2315. margin-left: 4px;
  2316. margin-bottom: 36px;
  2317. .nav-dropdown-items {
  2318. position: relative;
  2319. right: calc(100% - 110px);
  2320. }
  2321. }
  2322. .control {
  2323. width: fit-content;
  2324. margin-bottom: 0 !important;
  2325. button.disabled {
  2326. filter: grayscale(0.4);
  2327. border-radius: @border-radius;
  2328. &::after {
  2329. margin-right: 100%;
  2330. }
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. #sidebar-container {
  2338. border-top: 0;
  2339. position: relative;
  2340. height: inherit;
  2341. flex-grow: 1;
  2342. min-height: 350px;
  2343. }
  2344. }
  2345. }
  2346. .footer {
  2347. margin-top: 30px;
  2348. }
  2349. .nyan {
  2350. background: linear-gradient(
  2351. 90deg,
  2352. magenta 0%,
  2353. red 15%,
  2354. orange 30%,
  2355. yellow 45%,
  2356. lime 60%,
  2357. cyan 75%,
  2358. blue 90%,
  2359. magenta 100%
  2360. );
  2361. background-size: 200%;
  2362. animation: nyanMoving 4s linear infinite;
  2363. }
  2364. @keyframes nyanMoving {
  2365. 0% {
  2366. background-position: 0% 0%;
  2367. }
  2368. 100% {
  2369. background-position: -200% 0%;
  2370. }
  2371. }
  2372. .christmas-seeker {
  2373. background: repeating-linear-gradient(
  2374. -45deg,
  2375. var(--white) 0 1rem,
  2376. var(--dark-red) 1rem 2rem
  2377. );
  2378. background-size: 200% 200%;
  2379. animation: christmas 20s linear infinite;
  2380. }
  2381. @keyframes christmas {
  2382. 100% {
  2383. background-position: 80% 100%;
  2384. }
  2385. }
  2386. .bg-bubbles {
  2387. top: 0;
  2388. left: 0;
  2389. width: 100%;
  2390. height: 100%;
  2391. position: absolute;
  2392. z-index: -1;
  2393. margin: 0px;
  2394. pointer-events: none;
  2395. }
  2396. .bg-bubbles li {
  2397. position: absolute;
  2398. list-style: none;
  2399. display: block;
  2400. width: 40px;
  2401. height: 40px;
  2402. border-radius: 100px;
  2403. background-color: var(--primary-color);
  2404. opacity: 0.15;
  2405. bottom: 0px;
  2406. -webkit-animation: square 25s infinite;
  2407. animation: square 25s infinite;
  2408. -webkit-transition-timing-function: linear;
  2409. transition-timing-function: linear;
  2410. }
  2411. .bg-bubbles li:nth-child(1) {
  2412. left: 10%;
  2413. }
  2414. .bg-bubbles li:nth-child(2) {
  2415. left: 20%;
  2416. width: 80px;
  2417. height: 80px;
  2418. -webkit-animation-delay: 2s;
  2419. animation-delay: 2s;
  2420. -webkit-animation-duration: 17s;
  2421. animation-duration: 17s;
  2422. }
  2423. .bg-bubbles li:nth-child(3) {
  2424. left: 25%;
  2425. -webkit-animation-delay: 4s;
  2426. animation-delay: 4s;
  2427. }
  2428. .bg-bubbles li:nth-child(4) {
  2429. left: 40%;
  2430. width: 60px;
  2431. height: 60px;
  2432. -webkit-animation-duration: 22s;
  2433. animation-duration: 22s;
  2434. background-color: var(--primary-color);
  2435. opacity: 0.25;
  2436. }
  2437. .bg-bubbles li:nth-child(5) {
  2438. left: 70%;
  2439. }
  2440. .bg-bubbles li:nth-child(6) {
  2441. left: 80%;
  2442. width: 120px;
  2443. height: 120px;
  2444. -webkit-animation-delay: 3s;
  2445. animation-delay: 3s;
  2446. background-color: var(--primary-color);
  2447. opacity: 0.2;
  2448. }
  2449. .bg-bubbles li:nth-child(7) {
  2450. left: 32%;
  2451. width: 160px;
  2452. height: 160px;
  2453. -webkit-animation-delay: 7s;
  2454. animation-delay: 7s;
  2455. }
  2456. .bg-bubbles li:nth-child(8) {
  2457. left: 55%;
  2458. width: 20px;
  2459. height: 20px;
  2460. -webkit-animation-delay: 15s;
  2461. animation-delay: 15s;
  2462. -webkit-animation-duration: 40s;
  2463. animation-duration: 40s;
  2464. }
  2465. .bg-bubbles li:nth-child(9) {
  2466. left: 25%;
  2467. width: 10px;
  2468. height: 10px;
  2469. -webkit-animation-delay: 2s;
  2470. animation-delay: 2s;
  2471. -webkit-animation-duration: 40s;
  2472. animation-duration: 40s;
  2473. background-color: var(--primary-color);
  2474. opacity: 0.3;
  2475. }
  2476. .bg-bubbles li:nth-child(10) {
  2477. left: 80%;
  2478. width: 160px;
  2479. height: 160px;
  2480. -webkit-animation-delay: 11s;
  2481. animation-delay: 11s;
  2482. }
  2483. /* Tablet view fix */
  2484. @media (max-width: 768px) {
  2485. .bg-bubbles li:nth-child(10) {
  2486. display: none;
  2487. }
  2488. }
  2489. @-webkit-keyframes square {
  2490. 0% {
  2491. -webkit-transform: translateY(0);
  2492. transform: translateY(0);
  2493. }
  2494. 100% {
  2495. -webkit-transform: translateY(-700px) rotate(600deg);
  2496. transform: translateY(-700px) rotate(600deg);
  2497. }
  2498. }
  2499. @keyframes square {
  2500. 0% {
  2501. -webkit-transform: translateY(0);
  2502. transform: translateY(0);
  2503. }
  2504. 100% {
  2505. -webkit-transform: translateY(-700px) rotate(600deg);
  2506. transform: translateY(-700px) rotate(600deg);
  2507. }
  2508. }
  2509. :deep(.nothing-here-text) {
  2510. display: flex;
  2511. align-items: center;
  2512. justify-content: center;
  2513. }
  2514. @media (min-width: 1500px) {
  2515. #station-left-column {
  2516. max-width: 650px;
  2517. }
  2518. #station-right-column {
  2519. max-width: calc(100% - 650px);
  2520. }
  2521. }
  2522. @media (max-width: 1700px) {
  2523. #current-next-row {
  2524. flex-direction: column !important;
  2525. > div {
  2526. flex: 1 !important;
  2527. }
  2528. }
  2529. }
  2530. @media (max-width: 1500px) {
  2531. #mobile-progress-animation {
  2532. display: block;
  2533. }
  2534. #page-loader-container {
  2535. display: none;
  2536. }
  2537. #station-outer-container {
  2538. max-width: 1500px;
  2539. #station-inner-container {
  2540. flex-direction: row;
  2541. #station-left-column {
  2542. #about-station-container #admin-buttons {
  2543. flex-wrap: wrap;
  2544. }
  2545. #sidebar-container {
  2546. min-height: 350px;
  2547. }
  2548. }
  2549. #station-right-column {
  2550. #current-next-row {
  2551. flex-direction: column;
  2552. }
  2553. #control-bar-container {
  2554. #duration,
  2555. #volume-control,
  2556. #right-buttons,
  2557. #left-buttons {
  2558. margin-bottom: 5px;
  2559. justify-content: center;
  2560. }
  2561. #duration {
  2562. order: 1;
  2563. }
  2564. #volume-control {
  2565. order: 2;
  2566. max-width: 400px;
  2567. }
  2568. #right-buttons {
  2569. order: 3;
  2570. flex-wrap: wrap;
  2571. #ratings {
  2572. flex-wrap: wrap;
  2573. }
  2574. }
  2575. #left-buttons {
  2576. order: 4;
  2577. flex-wrap: wrap;
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. @media (max-width: 1200px) {
  2585. #station-outer-container {
  2586. max-width: 900px;
  2587. padding: 0;
  2588. #station-inner-container {
  2589. flex-direction: column-reverse;
  2590. flex-wrap: nowrap;
  2591. }
  2592. }
  2593. }
  2594. @media (max-width: 990px) {
  2595. #station-outer-container {
  2596. min-height: calc(
  2597. 100vh - 256px
  2598. ); // Height of nav (64px) + height of footer (190px)
  2599. }
  2600. }
  2601. </style>