index.vue 86 KB

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