index.vue 71 KB

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