index.vue 68 KB

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