index.vue 67 KB

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