index.vue 70 KB

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