index.vue 86 KB

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