index.vue 69 KB

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