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