index.vue 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301
  1. <template>
  2. <div :style="'--primary-color: var(--' + station.theme + ')'">
  3. <metadata v-if="exists && !loading" :title="`${station.displayName}`" />
  4. <metadata v-else-if="!exists && !loading" :title="`Not found`" />
  5. <div id="page-loader-container" v-if="loading">
  6. <content-loader
  7. width="1920"
  8. height="1080"
  9. :primary-color="nightmode ? '#222' : '#fff'"
  10. :secondary-color="nightmode ? '#444' : '#ddd'"
  11. preserve-aspect-ratio="none"
  12. id="page-loader-content"
  13. >
  14. <rect x="100" y="108" rx="5" ry="5" width="1048" height="672" />
  15. <rect x="100" y="810" rx="5" ry="5" width="1048" height="110" />
  16. <rect x="1190" y="110" rx="5" ry="5" width="630" height="149" />
  17. <rect x="1190" y="288" rx="5" ry="5" width="630" height="630" />
  18. </content-loader>
  19. <content-loader
  20. width="1920"
  21. height="1080"
  22. :primary-color="nightmode ? '#222' : '#fff'"
  23. :secondary-color="nightmode ? '#444' : '#ddd'"
  24. preserve-aspect-ratio="none"
  25. id="page-loader-layout"
  26. >
  27. <rect x="0" y="0" rx="0" ry="0" width="1920" height="64" />
  28. <rect x="0" y="980" rx="0" ry="0" width="1920" height="100" />
  29. </content-loader>
  30. </div>
  31. <!-- More simplistic loading animation for mobile users -->
  32. <div v-show="loading" id="mobile-progress-animation" />
  33. <div v-show="!loading">
  34. <main-header v-if="exists" />
  35. <div
  36. id="station-outer-container"
  37. :style="[!exists ? { margin: 0, padding: 0 } : {}]"
  38. >
  39. <div
  40. v-show="exists"
  41. id="station-inner-container"
  42. :class="{ 'nothing-here': noSong }"
  43. >
  44. <div id="station-left-column" class="column">
  45. <div class="player-container quadrant" v-show="!noSong">
  46. <div id="video-container">
  47. <div
  48. id="stationPlayer"
  49. style="
  50. width: 100%;
  51. height: 100%;
  52. min-height: 200px;
  53. "
  54. />
  55. <div
  56. class="player-cannot-autoplay"
  57. v-if="!canAutoplay"
  58. @click="
  59. increaseVolume() && decreaseVolume()
  60. "
  61. >
  62. <p>
  63. Please click anywhere on the screen for
  64. the video to start
  65. </p>
  66. </div>
  67. </div>
  68. <div id="seeker-bar-container">
  69. <div id="seeker-bar" style="width: 0%" />
  70. </div>
  71. <div id="control-bar-container">
  72. <div id="left-buttons">
  73. <!-- Debug Box -->
  74. <button
  75. class="button is-primary"
  76. @click="togglePlayerDebugBox()"
  77. @dblclick="resetPlayerDebugBox()"
  78. >
  79. <i
  80. class="material-icons icon-with-button"
  81. >
  82. bug_report
  83. </i>
  84. </button>
  85. <!-- Local Pause/Resume Button -->
  86. <button
  87. class="button is-primary"
  88. @click="resumeLocalStation()"
  89. id="local-resume"
  90. v-if="localPaused"
  91. >
  92. <i class="material-icons">play_arrow</i>
  93. </button>
  94. <button
  95. class="button is-primary"
  96. @click="pauseLocalStation()"
  97. id="local-pause"
  98. v-else
  99. >
  100. <i class="material-icons">pause</i>
  101. </button>
  102. <!-- Vote to Skip Button -->
  103. <button
  104. v-if="loggedIn"
  105. class="button is-primary"
  106. @click="voteSkipStation()"
  107. >
  108. <i
  109. class="material-icons icon-with-button"
  110. >skip_next</i
  111. >
  112. {{ currentSong.skipVotes }}
  113. </button>
  114. <button
  115. v-else
  116. class="button is-primary tooltip tooltip-top disabled"
  117. data-tooltip="Login to vote to skip songs"
  118. >
  119. <i
  120. class="material-icons icon-with-button"
  121. >skip_next</i
  122. >
  123. {{ currentSong.skipVotes }}
  124. </button>
  125. </div>
  126. <div id="duration">
  127. <p>
  128. {{ timeElapsed }} /
  129. {{
  130. utils.formatTime(
  131. currentSong.duration
  132. )
  133. }}
  134. </p>
  135. </div>
  136. <p id="volume-control">
  137. <i
  138. v-if="muted"
  139. class="material-icons"
  140. @click="toggleMute()"
  141. >volume_mute</i
  142. >
  143. <i
  144. v-else
  145. class="material-icons"
  146. @click="toggleMute()"
  147. >volume_down</i
  148. >
  149. <input
  150. v-model="volumeSliderValue"
  151. type="range"
  152. min="0"
  153. max="10000"
  154. class="volume-slider active"
  155. @change="changeVolume()"
  156. @input="changeVolume()"
  157. />
  158. <i
  159. class="material-icons"
  160. @click="increaseVolume()"
  161. >volume_up</i
  162. >
  163. </p>
  164. <div id="right-buttons" v-if="loggedIn">
  165. <!-- Ratings (Like/Dislike) Buttons -->
  166. <div
  167. id="ratings"
  168. v-if="
  169. currentSong.likes !== -1 &&
  170. currentSong.dislikes !== -1
  171. "
  172. :class="{
  173. liked: liked,
  174. disliked: disliked
  175. }"
  176. >
  177. <!-- Like Song Button -->
  178. <button
  179. class="button is-success like-song"
  180. id="like-song"
  181. @click="toggleLike()"
  182. >
  183. <i
  184. class="material-icons icon-with-button"
  185. :class="{ liked: liked }"
  186. >thumb_up_alt</i
  187. >{{ currentSong.likes }}
  188. </button>
  189. <!-- Dislike Song Button -->
  190. <button
  191. class="button is-danger dislike-song"
  192. id="dislike-song"
  193. @click="toggleDislike()"
  194. >
  195. <i
  196. class="material-icons icon-with-button"
  197. :class="{
  198. disliked: disliked
  199. }"
  200. >thumb_down_alt</i
  201. >{{ currentSong.dislikes }}
  202. </button>
  203. </div>
  204. <!-- Add Song To Playlist Button & Dropdown -->
  205. <div
  206. id="add-song-to-playlist"
  207. v-click-outside="
  208. () =>
  209. (this.showPlaylistDropdown = false)
  210. "
  211. >
  212. <div class="control has-addons">
  213. <button
  214. class="button is-primary"
  215. @click="
  216. showPlaylistDropdown = !showPlaylistDropdown
  217. "
  218. >
  219. <i class="material-icons"
  220. >queue</i
  221. >
  222. </button>
  223. <button
  224. class="button"
  225. id="dropdown-toggle"
  226. @click="
  227. showPlaylistDropdown = !showPlaylistDropdown
  228. "
  229. >
  230. <i class="material-icons">
  231. {{
  232. showPlaylistDropdown
  233. ? "expand_more"
  234. : "expand_less"
  235. }}
  236. </i>
  237. </button>
  238. </div>
  239. <add-to-playlist-dropdown
  240. v-if="showPlaylistDropdown"
  241. :song="currentSong"
  242. />
  243. </div>
  244. </div>
  245. <div id="right-buttons" v-else>
  246. <!-- Disabled Ratings (Like/Dislike) Buttons -->
  247. <div
  248. id="ratings"
  249. v-if="
  250. currentSong.likes !== -1 &&
  251. currentSong.dislikes !== -1
  252. "
  253. >
  254. <!-- Disabled Like Song Button -->
  255. <button
  256. class="button is-success tooltip tooltip-top disabled"
  257. id="like-song"
  258. data-tooltip="Login to like songs"
  259. >
  260. <i
  261. class="material-icons icon-with-button"
  262. >thumb_up_alt</i
  263. >{{ currentSong.likes }}
  264. </button>
  265. <!-- Disabled Dislike Song Button -->
  266. <button
  267. class="button is-danger tooltip tooltip-top disabled"
  268. id="dislike-song"
  269. data-tooltip="Login to dislike songs"
  270. >
  271. <i
  272. class="material-icons icon-with-button"
  273. >thumb_down_alt</i
  274. >{{ currentSong.dislikes }}
  275. </button>
  276. </div>
  277. <!-- Disabled Add Song To Playlist Button & Dropdown -->
  278. <div id="add-song-to-playlist">
  279. <div class="control has-addons">
  280. <button
  281. class="button is-primary tooltip tooltip-top disabled"
  282. data-tooltip="Login to add songs to playlist"
  283. >
  284. <i class="material-icons"
  285. >queue</i
  286. >
  287. </button>
  288. </div>
  289. </div>
  290. </div>
  291. </div>
  292. </div>
  293. <p
  294. class="player-container nothing-here-text"
  295. v-if="noSong"
  296. >
  297. No song is currently playing
  298. </p>
  299. <div v-if="!noSong" id="current-next-row">
  300. <div
  301. id="currently-playing-container"
  302. class="quadrant"
  303. :class="{ 'no-currently-playing': noSong }"
  304. >
  305. <currently-playing :song="currentSong" />
  306. <!-- <p v-else class="nothing-here-text">
  307. No song is currently playing
  308. </p> -->
  309. </div>
  310. <div
  311. v-if="nextSong"
  312. id="next-up-container"
  313. class="quadrant"
  314. >
  315. <currently-playing
  316. type="next"
  317. :song="nextSong"
  318. />
  319. </div>
  320. </div>
  321. </div>
  322. <div id="station-right-column" class="column">
  323. <div id="about-station-container" class="quadrant">
  324. <div id="station-info">
  325. <div class="row" id="station-name">
  326. <h1>{{ station.displayName }}</h1>
  327. <a href="#">
  328. <!-- Favorite Station Button -->
  329. <i
  330. v-if="
  331. loggedIn && station.isFavorited
  332. "
  333. @click.prevent="unfavoriteStation()"
  334. class="material-icons"
  335. >star</i
  336. >
  337. <i
  338. v-if="
  339. loggedIn && !station.isFavorited
  340. "
  341. @click.prevent="favoriteStation()"
  342. class="material-icons"
  343. >star_border</i
  344. >
  345. </a>
  346. <i
  347. class="material-icons stationMode"
  348. :title="
  349. station.partyMode
  350. ? 'Station in Party mode'
  351. : 'Station in Playlist mode'
  352. "
  353. >{{
  354. station.partyMode
  355. ? "emoji_people"
  356. : "playlist_play"
  357. }}</i
  358. >
  359. </div>
  360. <p>{{ station.description }}</p>
  361. </div>
  362. <div id="admin-buttons" v-if="isOwnerOrAdmin()">
  363. <!-- (Admin) Pause/Resume Button -->
  364. <button
  365. class="button is-danger"
  366. v-if="stationPaused"
  367. @click="resumeStation()"
  368. >
  369. <i class="material-icons icon-with-button"
  370. >play_arrow</i
  371. >
  372. <span class="optional-desktop-only-text">
  373. Resume Station
  374. </span>
  375. </button>
  376. <button
  377. class="button is-danger"
  378. @click="pauseStation()"
  379. v-else
  380. >
  381. <i class="material-icons icon-with-button"
  382. >pause</i
  383. >
  384. <span class="optional-desktop-only-text">
  385. Pause Station
  386. </span>
  387. </button>
  388. <!-- (Admin) Skip Button -->
  389. <button
  390. class="button is-danger"
  391. @click="skipStation()"
  392. >
  393. <i class="material-icons icon-with-button"
  394. >skip_next</i
  395. >
  396. <span class="optional-desktop-only-text">
  397. Force Skip
  398. </span>
  399. </button>
  400. <!-- (Admin) Station Settings Button -->
  401. <button
  402. class="button is-primary"
  403. @click="
  404. openModal({
  405. sector: 'station',
  406. modal: 'editStation'
  407. })
  408. "
  409. >
  410. <i class="material-icons icon-with-button"
  411. >settings</i
  412. >
  413. <span class="optional-desktop-only-text">
  414. Station settings
  415. </span>
  416. </button>
  417. </div>
  418. </div>
  419. <div id="sidebar-container" class="quadrant">
  420. <station-sidebar />
  421. </div>
  422. </div>
  423. </div>
  424. <song-queue v-if="modals.station.addSongToQueue" />
  425. <edit-playlist v-if="modals.station.editPlaylist" />
  426. <create-playlist v-if="modals.station.createPlaylist" />
  427. <edit-station
  428. v-if="modals.station.editStation"
  429. :station-id="station._id"
  430. sector="station"
  431. />
  432. <report v-if="modals.station.report" />
  433. </div>
  434. <main-footer v-if="exists" />
  435. </div>
  436. <edit-song
  437. v-if="modals.admin.editSong"
  438. :song-id="editingSongId"
  439. song-type="songs"
  440. sector="station"
  441. />
  442. <floating-box id="player-debug-box" ref="playerDebugBox">
  443. <template #body>
  444. <span><b>YouTube id</b>: {{ currentSong.songId }}</span>
  445. <span><b>Duration</b>: {{ currentSong.duration }}</span>
  446. <span
  447. ><b>Skip duration</b>: {{ currentSong.skipDuration }}</span
  448. >
  449. <span><b>Can autoplay</b>: {{ canAutoplay }}</span>
  450. <span
  451. ><b>Attempts to play video</b>:
  452. {{ attemptsToPlayVideo }}</span
  453. >
  454. <span
  455. ><b>Last time requested if can autoplay</b>:
  456. {{ lastTimeRequestedIfCanAutoplay }}</span
  457. >
  458. <span><b>Loading</b>: {{ loading }}</span>
  459. <span><b>Playback rate</b>: {{ playbackRate }}</span>
  460. <span><b>Player ready</b>: {{ playerReady }}</span>
  461. <span><b>Ready</b>: {{ ready }}</span>
  462. <span><b>Seeking</b>: {{ seeking }}</span>
  463. <span><b>System difference</b>: {{ systemDifference }}</span>
  464. <span><b>Time before paused</b>: {{ timeBeforePause }}</span>
  465. <span><b>Time elapsed</b>: {{ timeElapsed }}</span>
  466. <span><b>Time paused</b>: {{ timePaused }}</span>
  467. <span><b>Volume slider value</b>: {{ volumeSliderValue }}</span>
  468. <span><b>Local paused</b>: {{ localPaused }}</span>
  469. <span><b>No song</b>: {{ noSong }}</span>
  470. <span
  471. ><b>Private playlist queue selected</b>:
  472. {{ privatePlaylistQueueSelected }}</span
  473. >
  474. <span><b>Station paused</b>: {{ stationPaused }}</span>
  475. <span
  476. ><b>Station Genres</b>:
  477. {{ station.genres.join(", ") }}</span
  478. >
  479. <span
  480. ><b>Station Blacklisted Genres</b>:
  481. {{ station.blacklistedGenres.join(", ") }}</span
  482. >
  483. </template>
  484. </floating-box>
  485. <Z404 v-if="!exists"></Z404>
  486. </div>
  487. </template>
  488. <script>
  489. import { mapState, mapActions, mapGetters } from "vuex";
  490. import Toast from "toasters";
  491. import { ContentLoader } from "vue-content-loader";
  492. import MainHeader from "../../components/layout/MainHeader.vue";
  493. import MainFooter from "../../components/layout/MainFooter.vue";
  494. import Z404 from "../404.vue";
  495. import FloatingBox from "../../components/ui/FloatingBox.vue";
  496. import AddToPlaylistDropdown from "../../components/ui/AddToPlaylistDropdown.vue";
  497. import ws from "../../ws";
  498. import keyboardShortcuts from "../../keyboardShortcuts";
  499. import utils from "../../../js/utils";
  500. import CurrentlyPlaying from "./components/CurrentlyPlaying.vue";
  501. import StationSidebar from "./components/Sidebar/index.vue";
  502. export default {
  503. components: {
  504. ContentLoader,
  505. MainHeader,
  506. MainFooter,
  507. SongQueue: () => import("../../components/modals/AddSongToQueue.vue"),
  508. EditPlaylist: () =>
  509. import("../../components/modals/EditPlaylist/index.vue"),
  510. CreatePlaylist: () =>
  511. import("../../components/modals/CreatePlaylist.vue"),
  512. EditStation: () => import("../../components/modals/EditStation.vue"),
  513. Report: () => import("../../components/modals/Report.vue"),
  514. Z404,
  515. FloatingBox,
  516. CurrentlyPlaying,
  517. StationSidebar,
  518. AddToPlaylistDropdown,
  519. EditSong: () => import("../../components/modals/EditSong.vue")
  520. },
  521. data() {
  522. return {
  523. utils,
  524. title: "Station",
  525. loading: true,
  526. ready: false,
  527. exists: true,
  528. playerReady: false,
  529. player: undefined,
  530. timePaused: 0,
  531. muted: false,
  532. timeElapsed: "0:00",
  533. liked: false,
  534. disliked: false,
  535. timeBeforePause: 0,
  536. skipVotes: 0,
  537. automaticallyRequestedSongId: null,
  538. systemDifference: 0,
  539. attemptsToPlayVideo: 0,
  540. canAutoplay: true,
  541. lastTimeRequestedIfCanAutoplay: 0,
  542. seeking: false,
  543. playbackRate: 1,
  544. volumeSliderValue: 0,
  545. showPlaylistDropdown: false,
  546. editingSongId: "",
  547. theme: "var(--primary-color)"
  548. };
  549. },
  550. computed: {
  551. ...mapState("modalVisibility", {
  552. modals: state => state.modals
  553. }),
  554. ...mapState("station", {
  555. station: state => state.station,
  556. currentSong: state => state.currentSong,
  557. nextSong: state => state.nextSong,
  558. songsList: state => state.songsList,
  559. stationPaused: state => state.stationPaused,
  560. localPaused: state => state.localPaused,
  561. noSong: state => state.noSong,
  562. privatePlaylistQueueSelected: state =>
  563. state.privatePlaylistQueueSelected
  564. }),
  565. ...mapState({
  566. loggedIn: state => state.user.auth.loggedIn,
  567. userId: state => state.user.auth.userId,
  568. role: state => state.user.auth.role,
  569. nightmode: state => state.user.preferences.nightmode,
  570. autoSkipDisliked: state => state.user.preferences.autoSkipDisliked
  571. }),
  572. ...mapGetters({
  573. socket: "websockets/getSocket"
  574. })
  575. },
  576. mounted() {
  577. window.scrollTo(0, 0);
  578. Date.currently = () => {
  579. return new Date().getTime() + this.systemDifference;
  580. };
  581. this.stationIdentifier = this.$route.params.id;
  582. window.stationInterval = 0;
  583. if (this.socket.readyState === 1) this.join();
  584. ws.onConnect(() => this.join());
  585. this.socket.dispatch(
  586. "stations.existsByName",
  587. this.stationIdentifier,
  588. res => {
  589. if (res.status === "failure" || !res.exists) {
  590. // station identifier may be using stationid instead
  591. this.socket.dispatch(
  592. "stations.existsById",
  593. this.stationIdentifier,
  594. res => {
  595. if (res.status === "failure" || !res.exists) {
  596. this.loading = false;
  597. this.exists = false;
  598. }
  599. }
  600. );
  601. }
  602. }
  603. );
  604. this.socket.on("event:songs.next", data => {
  605. const previousSong = this.currentSong.songId
  606. ? this.currentSong
  607. : null;
  608. this.updatePreviousSong(previousSong);
  609. const { currentSong } = data;
  610. if (currentSong && !currentSong.thumbnail)
  611. currentSong.ytThumbnail = `https://img.youtube.com/vi/${currentSong.songId}/mqdefault.jpg`;
  612. this.updateCurrentSong(currentSong || {});
  613. let nextSong = null;
  614. if (this.songsList[1]) {
  615. nextSong = this.songsList[1].songId ? this.songsList[1] : null;
  616. }
  617. this.updateNextSong(nextSong);
  618. this.startedAt = data.startedAt;
  619. this.updateStationPaused(data.paused);
  620. this.timePaused = data.timePaused;
  621. if (currentSong) {
  622. this.updateNoSong(false);
  623. if (!this.playerReady) this.youtubeReady();
  624. else this.playVideo();
  625. this.socket.dispatch(
  626. "songs.getOwnSongRatings",
  627. data.currentSong.songId,
  628. song => {
  629. if (this.currentSong.songId === song.songId) {
  630. this.liked = song.liked;
  631. this.disliked = song.disliked;
  632. if (
  633. this.autoSkipDisliked &&
  634. song.disliked === true
  635. ) {
  636. this.voteSkipStation();
  637. new Toast({
  638. content:
  639. "Automatically voted to skip disliked song.",
  640. timeout: 4000
  641. });
  642. }
  643. }
  644. }
  645. );
  646. } else {
  647. if (this.playerReady) this.player.pauseVideo();
  648. this.updateNoSong(true);
  649. }
  650. let isInQueue = false;
  651. this.songsList.forEach(queueSong => {
  652. if (queueSong.requestedBy === this.userId) isInQueue = true;
  653. });
  654. if (
  655. !isInQueue &&
  656. this.privatePlaylistQueueSelected &&
  657. (this.automaticallyRequestedSongId !==
  658. this.currentSong.songId ||
  659. !this.currentSong.songId)
  660. ) {
  661. this.addFirstPrivatePlaylistSongToQueue();
  662. }
  663. // if (this.station.type === "official") {
  664. // this.socket.dispatch(
  665. // "stations.getQueue",
  666. // this.station._id,
  667. // res => {
  668. // if (res.status === "success") {
  669. // this.updateSongsList(res.queue);
  670. // }
  671. // }
  672. // );
  673. // }
  674. // if (
  675. // !isInQueue &&
  676. // this.privatePlaylistQueueSelected &&
  677. // (this.automaticallyRequestedSongId !==
  678. // this.currentSong.songId ||
  679. // !this.currentSong.songId)
  680. // ) {
  681. // this.addFirstPrivatePlaylistSongToQueue();
  682. // }
  683. });
  684. this.socket.on("event:stations.pause", data => {
  685. this.pausedAt = data.pausedAt;
  686. this.updateStationPaused(true);
  687. this.pauseLocalPlayer();
  688. });
  689. this.socket.on("event:stations.resume", data => {
  690. this.timePaused = data.timePaused;
  691. this.updateStationPaused(false);
  692. if (!this.localPaused) this.resumeLocalPlayer();
  693. });
  694. this.socket.on("event:stations.remove", () => {
  695. window.location.href = "/";
  696. return true;
  697. });
  698. this.socket.on("event:song.like", data => {
  699. if (!this.noSong) {
  700. if (data.songId === this.currentSong.songId) {
  701. this.currentSong.dislikes = data.dislikes;
  702. this.currentSong.likes = data.likes;
  703. }
  704. }
  705. });
  706. this.socket.on("event:song.dislike", data => {
  707. if (!this.noSong) {
  708. if (data.songId === this.currentSong.songId) {
  709. this.currentSong.dislikes = data.dislikes;
  710. this.currentSong.likes = data.likes;
  711. }
  712. }
  713. });
  714. this.socket.on("event:song.unlike", data => {
  715. if (!this.noSong) {
  716. if (data.songId === this.currentSong.songId) {
  717. this.currentSong.dislikes = data.dislikes;
  718. this.currentSong.likes = data.likes;
  719. }
  720. }
  721. });
  722. this.socket.on("event:song.undislike", data => {
  723. if (!this.noSong) {
  724. if (data.songId === this.currentSong.songId) {
  725. this.currentSong.dislikes = data.dislikes;
  726. this.currentSong.likes = data.likes;
  727. }
  728. }
  729. });
  730. this.socket.on("event:song.newRatings", data => {
  731. if (!this.noSong) {
  732. if (data.songId === this.currentSong.songId) {
  733. this.liked = data.liked;
  734. this.disliked = data.disliked;
  735. }
  736. }
  737. });
  738. this.socket.on("event:queue.update", queue => {
  739. this.updateSongsList(queue);
  740. let nextSong = null;
  741. if (this.songsList[0]) {
  742. nextSong = this.songsList[0].songId ? this.songsList[0] : null;
  743. }
  744. this.updateNextSong(nextSong);
  745. });
  746. this.socket.on("event:song.voteSkipSong", () => {
  747. if (this.currentSong) this.currentSong.skipVotes += 1;
  748. });
  749. this.socket.on("event:privatePlaylist.selected", playlistId => {
  750. if (this.station.type === "community") {
  751. this.station.privatePlaylist = playlistId;
  752. }
  753. });
  754. this.socket.on("event:privatePlaylist.deselected", () => {
  755. if (this.station.type === "community") {
  756. this.station.privatePlaylist = null;
  757. }
  758. });
  759. this.socket.on("event:partyMode.updated", partyMode => {
  760. if (this.station.type === "community") {
  761. this.station.partyMode = partyMode;
  762. }
  763. });
  764. this.socket.on("event:station.themeUpdated", theme => {
  765. this.station.theme = theme;
  766. });
  767. this.socket.on("event:station.updateName", res => {
  768. this.station.name = res.name;
  769. // eslint-disable-next-line no-restricted-globals
  770. history.pushState(
  771. {},
  772. null,
  773. `${res.name}?${Object.keys(this.$route.query)
  774. .map(key => {
  775. return `${encodeURIComponent(key)}=${encodeURIComponent(
  776. this.$route.query[key]
  777. )}`;
  778. })
  779. .join("&")}`
  780. );
  781. });
  782. this.socket.on("event:station.updateDisplayName", res => {
  783. this.station.displayName = res.displayName;
  784. });
  785. this.socket.on("event:station.updateDescription", res => {
  786. this.station.description = res.description;
  787. });
  788. // this.socket.on("event:newOfficialPlaylist", playlist => {
  789. // if (this.station.type === "official")
  790. // this.updateSongsList(playlist);
  791. // });
  792. this.socket.on("event:users.updated", users => this.updateUsers(users));
  793. this.socket.on("event:userCount.updated", userCount =>
  794. this.updateUserCount(userCount)
  795. );
  796. this.socket.on("event:queueLockToggled", locked => {
  797. this.station.locked = locked;
  798. });
  799. this.socket.on("event:user.favoritedStation", stationId => {
  800. if (stationId === this.station._id)
  801. this.updateIfStationIsFavorited({ isFavorited: true });
  802. });
  803. this.socket.on("event:user.unfavoritedStation", stationId => {
  804. if (stationId === this.station._id)
  805. this.updateIfStationIsFavorited({ isFavorited: false });
  806. });
  807. if (JSON.parse(localStorage.getItem("muted"))) {
  808. this.muted = true;
  809. this.player.setVolume(0);
  810. this.volumeSliderValue = 0 * 100;
  811. } else {
  812. let volume = parseFloat(localStorage.getItem("volume"));
  813. volume =
  814. typeof volume === "number" && !Number.isNaN(volume)
  815. ? volume
  816. : 20;
  817. localStorage.setItem("volume", volume);
  818. this.volumeSliderValue = volume * 100;
  819. }
  820. },
  821. beforeDestroy() {
  822. /** Reset Songslist */
  823. this.updateSongsList([]);
  824. const shortcutNames = [
  825. "station.pauseResume",
  826. "station.skipStation",
  827. "station.lowerVolumeLarge",
  828. "station.lowerVolumeSmall",
  829. "station.increaseVolumeLarge",
  830. "station.increaseVolumeSmall",
  831. "station.toggleDebug"
  832. ];
  833. shortcutNames.forEach(shortcutName => {
  834. keyboardShortcuts.unregisterShortcut(shortcutName);
  835. });
  836. },
  837. methods: {
  838. isOwnerOnly() {
  839. return this.loggedIn && this.userId === this.station.owner;
  840. },
  841. isAdminOnly() {
  842. return this.loggedIn && this.role === "admin";
  843. },
  844. isOwnerOrAdmin() {
  845. return this.isOwnerOnly() || this.isAdminOnly();
  846. },
  847. removeFromQueue(songId) {
  848. window.socket.dispatch(
  849. "stations.removeFromQueue",
  850. this.station._id,
  851. songId,
  852. res => {
  853. if (res.status === "success") {
  854. new Toast({
  855. content:
  856. "Successfully removed song from the queue.",
  857. timeout: 4000
  858. });
  859. } else new Toast({ content: res.message, timeout: 8000 });
  860. }
  861. );
  862. },
  863. youtubeReady() {
  864. if (!this.player) {
  865. this.player = new window.YT.Player("stationPlayer", {
  866. height: 270,
  867. width: 480,
  868. videoId: this.currentSong.songId,
  869. host: "https://www.youtube-nocookie.com",
  870. startSeconds:
  871. this.getTimeElapsed() / 1000 +
  872. this.currentSong.skipDuration,
  873. playerVars: {
  874. controls: 0,
  875. iv_load_policy: 3,
  876. rel: 0,
  877. showinfo: 0,
  878. disablekb: 1
  879. },
  880. events: {
  881. onReady: () => {
  882. this.playerReady = true;
  883. let volume = parseInt(
  884. localStorage.getItem("volume")
  885. );
  886. volume = typeof volume === "number" ? volume : 20;
  887. this.player.setVolume(volume);
  888. if (volume > 0) this.player.unMute();
  889. if (this.muted) this.player.mute();
  890. this.playVideo();
  891. },
  892. onError: err => {
  893. console.log("error with youtube video", err);
  894. if (err.data === 150 && this.loggedIn) {
  895. new Toast({
  896. content:
  897. "Automatically voted to skip as this song isn't available for you.",
  898. timeout: 4000
  899. });
  900. // automatically vote to skip
  901. this.voteSkipStation();
  902. // persistent message while song is playing
  903. const toastMessage =
  904. "This song is unavailable for you, but is playing for everyone else.";
  905. new Toast({
  906. content: toastMessage,
  907. persistant: true
  908. });
  909. // save current song id
  910. const erroredSongId = this.currentSong.songId;
  911. // remove persistent toast if video has finished
  912. window.isSongErroredInterval = setInterval(
  913. () => {
  914. if (
  915. this.currentSong.songId !==
  916. erroredSongId
  917. ) {
  918. document
  919. .getElementById(
  920. "toasts-content"
  921. )
  922. .childNodes.forEach(toast => {
  923. if (
  924. toast.innerHTML ===
  925. toastMessage
  926. )
  927. toast.remove();
  928. });
  929. clearInterval(
  930. window.isSongErroredInterval
  931. );
  932. }
  933. },
  934. 150
  935. );
  936. } else {
  937. new Toast({
  938. content:
  939. "There has been an error with the YouTube Embed",
  940. timeout: 8000
  941. });
  942. }
  943. },
  944. onStateChange: event => {
  945. if (
  946. event.data === window.YT.PlayerState.PLAYING &&
  947. this.videoLoading === true
  948. ) {
  949. this.videoLoading = false;
  950. this.player.seekTo(
  951. this.getTimeElapsed() / 1000 +
  952. this.currentSong.skipDuration,
  953. true
  954. );
  955. if (this.localPaused || this.stationPaused)
  956. this.player.pauseVideo();
  957. } else if (
  958. event.data === window.YT.PlayerState.PLAYING &&
  959. (this.localPaused || this.stationPaused)
  960. ) {
  961. this.player.seekTo(
  962. this.timeBeforePause / 1000,
  963. true
  964. );
  965. this.player.pauseVideo();
  966. } else if (
  967. event.data === window.YT.PlayerState.PLAYING &&
  968. this.seeking === true
  969. ) {
  970. this.seeking = false;
  971. }
  972. if (
  973. event.data === window.YT.PlayerState.PAUSED &&
  974. !this.localPaused &&
  975. !this.stationPaused &&
  976. !this.noSong &&
  977. this.player.getDuration() / 1000 <
  978. this.currentSong.duration
  979. ) {
  980. this.player.seekTo(
  981. this.getTimeElapsed() / 1000 +
  982. this.currentSong.skipDuration,
  983. true
  984. );
  985. this.player.playVideo();
  986. }
  987. }
  988. }
  989. });
  990. }
  991. },
  992. getTimeElapsed() {
  993. if (this.currentSong) {
  994. let { timePaused } = this;
  995. if (this.stationPaused)
  996. timePaused += Date.currently() - this.pausedAt;
  997. return Date.currently() - this.startedAt - timePaused;
  998. }
  999. return 0;
  1000. },
  1001. playVideo() {
  1002. if (this.playerReady) {
  1003. this.videoLoading = true;
  1004. this.player.loadVideoById(
  1005. this.currentSong.songId,
  1006. this.getTimeElapsed() / 1000 + this.currentSong.skipDuration
  1007. );
  1008. if (window.stationInterval !== 0)
  1009. clearInterval(window.stationInterval);
  1010. window.stationInterval = setInterval(() => {
  1011. this.resizeSeekerbar();
  1012. this.calculateTimeElapsed();
  1013. }, 150);
  1014. }
  1015. },
  1016. resizeSeekerbar() {
  1017. if (!this.stationPaused) {
  1018. document.getElementById(
  1019. "seeker-bar"
  1020. ).style.width = `${parseFloat(
  1021. (this.getTimeElapsed() / 1000 / this.currentSong.duration) *
  1022. 100
  1023. )}%`;
  1024. }
  1025. },
  1026. calculateTimeElapsed() {
  1027. if (
  1028. this.playerReady &&
  1029. this.currentSong &&
  1030. this.player.getPlayerState() === -1
  1031. ) {
  1032. if (this.attemptsToPlayVideo >= 5) {
  1033. if (
  1034. Date.now() - this.lastTimeRequestedIfCanAutoplay >
  1035. 2000
  1036. ) {
  1037. this.lastTimeRequestedIfCanAutoplay = Date.now();
  1038. window.canAutoplay.video().then(({ result }) => {
  1039. if (result) {
  1040. this.attemptsToPlayVideo = 0;
  1041. this.canAutoplay = true;
  1042. } else {
  1043. this.canAutoplay = false;
  1044. }
  1045. });
  1046. }
  1047. } else {
  1048. this.player.playVideo();
  1049. this.attemptsToPlayVideo += 1;
  1050. }
  1051. }
  1052. if (!this.stationPaused && !this.localPaused) {
  1053. const timeElapsed = this.getTimeElapsed();
  1054. const currentPlayerTime =
  1055. Math.max(
  1056. this.player.getCurrentTime() -
  1057. this.currentSong.skipDuration,
  1058. 0
  1059. ) * 1000;
  1060. const difference = timeElapsed - currentPlayerTime;
  1061. // console.log(difference);
  1062. let playbackRate = 1;
  1063. if (difference < -2000) {
  1064. if (!this.seeking) {
  1065. this.seeking = true;
  1066. this.player.seekTo(
  1067. this.getTimeElapsed() / 1000 +
  1068. this.currentSong.skipDuration
  1069. );
  1070. }
  1071. } else if (difference < -200) {
  1072. // console.log("Difference0.8");
  1073. playbackRate = 0.8;
  1074. } else if (difference < -50) {
  1075. // console.log("Difference0.9");
  1076. playbackRate = 0.9;
  1077. } else if (difference < -25) {
  1078. // console.log("Difference0.99");
  1079. playbackRate = 0.95;
  1080. } else if (difference > 2000) {
  1081. if (!this.seeking) {
  1082. this.seeking = true;
  1083. this.player.seekTo(
  1084. this.getTimeElapsed() / 1000 +
  1085. this.currentSong.skipDuration
  1086. );
  1087. }
  1088. } else if (difference > 200) {
  1089. // console.log("Difference1.2");
  1090. playbackRate = 1.2;
  1091. } else if (difference > 50) {
  1092. // console.log("Difference1.1");
  1093. playbackRate = 1.1;
  1094. } else if (difference > 25) {
  1095. // console.log("Difference1.01");
  1096. playbackRate = 1.05;
  1097. } else if (this.player.getPlaybackRate !== 1.0) {
  1098. // console.log("NDifference1.0");
  1099. this.player.setPlaybackRate(1.0);
  1100. }
  1101. if (this.playbackRate !== playbackRate) {
  1102. this.player.setPlaybackRate(playbackRate);
  1103. this.playbackRate = playbackRate;
  1104. }
  1105. }
  1106. /* if (this.currentTime !== undefined && this.paused) {
  1107. this.timePaused += Date.currently() - this.currentTime;
  1108. this.currentTime = undefined;
  1109. } */
  1110. let { timePaused } = this;
  1111. if (this.stationPaused)
  1112. timePaused += Date.currently() - this.pausedAt;
  1113. const duration =
  1114. (Date.currently() - this.startedAt - timePaused) / 1000;
  1115. const songDuration = this.currentSong.duration;
  1116. if (songDuration <= duration) this.player.pauseVideo();
  1117. if (!this.stationPaused && duration <= songDuration)
  1118. this.timeElapsed = utils.formatTime(duration);
  1119. },
  1120. toggleLock() {
  1121. window.socket.dispatch(
  1122. "stations.toggleLock",
  1123. this.station._id,
  1124. res => {
  1125. if (res.status === "success") {
  1126. new Toast({
  1127. content: "Successfully toggled the queue lock.",
  1128. timeout: 4000
  1129. });
  1130. } else new Toast({ content: res.message, timeout: 8000 });
  1131. }
  1132. );
  1133. },
  1134. changeVolume() {
  1135. const volume = this.volumeSliderValue;
  1136. localStorage.setItem("volume", volume / 100);
  1137. if (this.playerReady) {
  1138. this.player.setVolume(volume / 100);
  1139. if (volume > 0) {
  1140. this.player.unMute();
  1141. localStorage.setItem("muted", false);
  1142. this.muted = false;
  1143. }
  1144. }
  1145. },
  1146. resumeLocalStation() {
  1147. this.updateLocalPaused(false);
  1148. if (!this.stationPaused) this.resumeLocalPlayer();
  1149. },
  1150. pauseLocalStation() {
  1151. this.updateLocalPaused(true);
  1152. this.pauseLocalPlayer();
  1153. },
  1154. resumeLocalPlayer() {
  1155. if (!this.noSong) {
  1156. if (this.playerReady) {
  1157. this.player.seekTo(
  1158. this.getTimeElapsed() / 1000 +
  1159. this.currentSong.skipDuration
  1160. );
  1161. this.player.playVideo();
  1162. }
  1163. }
  1164. },
  1165. pauseLocalPlayer() {
  1166. if (!this.noSong) {
  1167. this.timeBeforePause = this.getTimeElapsed();
  1168. if (this.playerReady) this.player.pauseVideo();
  1169. }
  1170. },
  1171. skipStation() {
  1172. this.socket.dispatch(
  1173. "stations.forceSkip",
  1174. this.station._id,
  1175. data => {
  1176. if (data.status !== "success")
  1177. new Toast({
  1178. content: `Error: ${data.message}`,
  1179. timeout: 8000
  1180. });
  1181. else
  1182. new Toast({
  1183. content:
  1184. "Successfully skipped the station's current song.",
  1185. timeout: 4000
  1186. });
  1187. }
  1188. );
  1189. },
  1190. voteSkipStation() {
  1191. this.socket.dispatch(
  1192. "stations.voteSkip",
  1193. this.station._id,
  1194. data => {
  1195. if (data.status !== "success")
  1196. new Toast({
  1197. content: `Error: ${data.message}`,
  1198. timeout: 8000
  1199. });
  1200. else
  1201. new Toast({
  1202. content:
  1203. "Successfully voted to skip the current song.",
  1204. timeout: 4000
  1205. });
  1206. }
  1207. );
  1208. },
  1209. resumeStation() {
  1210. this.socket.dispatch("stations.resume", this.station._id, data => {
  1211. if (data.status !== "success")
  1212. new Toast({
  1213. content: `Error: ${data.message}`,
  1214. timeout: 8000
  1215. });
  1216. else
  1217. new Toast({
  1218. content: "Successfully resumed the station.",
  1219. timeout: 4000
  1220. });
  1221. });
  1222. },
  1223. pauseStation() {
  1224. this.socket.dispatch("stations.pause", this.station._id, data => {
  1225. if (data.status !== "success")
  1226. new Toast({
  1227. content: `Error: ${data.message}`,
  1228. timeout: 8000
  1229. });
  1230. else
  1231. new Toast({
  1232. content: "Successfully paused the station.",
  1233. timeout: 4000
  1234. });
  1235. });
  1236. },
  1237. toggleMute() {
  1238. if (this.playerReady) {
  1239. const previousVolume = parseFloat(
  1240. localStorage.getItem("volume")
  1241. );
  1242. const volume =
  1243. this.player.getVolume() * 100 <= 0 ? previousVolume : 0;
  1244. this.muted = !this.muted;
  1245. localStorage.setItem("muted", this.muted);
  1246. this.volumeSliderValue = volume * 100;
  1247. this.player.setVolume(volume);
  1248. if (!this.muted) localStorage.setItem("volume", volume);
  1249. }
  1250. },
  1251. increaseVolume() {
  1252. if (this.playerReady) {
  1253. const previousVolume = parseInt(localStorage.getItem("volume"));
  1254. let volume = previousVolume + 5;
  1255. if (previousVolume === 0) {
  1256. this.muted = false;
  1257. localStorage.setItem("muted", false);
  1258. }
  1259. if (volume > 100) volume = 100;
  1260. this.volumeSliderValue = volume * 100;
  1261. this.player.setVolume(volume);
  1262. localStorage.setItem("volume", volume);
  1263. }
  1264. },
  1265. toggleLike() {
  1266. if (this.liked)
  1267. this.socket.dispatch(
  1268. "songs.unlike",
  1269. this.currentSong.songId,
  1270. data => {
  1271. if (data.status !== "success")
  1272. new Toast({
  1273. content: `Error: ${data.message}`,
  1274. timeout: 8000
  1275. });
  1276. }
  1277. );
  1278. else
  1279. this.socket.dispatch(
  1280. "songs.like",
  1281. this.currentSong.songId,
  1282. data => {
  1283. if (data.status !== "success")
  1284. new Toast({
  1285. content: `Error: ${data.message}`,
  1286. timeout: 8000
  1287. });
  1288. }
  1289. );
  1290. },
  1291. toggleDislike() {
  1292. if (this.disliked)
  1293. return this.socket.dispatch(
  1294. "songs.undislike",
  1295. this.currentSong.songId,
  1296. data => {
  1297. if (data.status !== "success")
  1298. new Toast({
  1299. content: `Error: ${data.message}`,
  1300. timeout: 8000
  1301. });
  1302. }
  1303. );
  1304. return this.socket.dispatch(
  1305. "songs.dislike",
  1306. this.currentSong.songId,
  1307. data => {
  1308. if (data.status !== "success")
  1309. new Toast({
  1310. content: `Error: ${data.message}`,
  1311. timeout: 8000
  1312. });
  1313. }
  1314. );
  1315. },
  1316. addFirstPrivatePlaylistSongToQueue() {
  1317. let isInQueue = false;
  1318. if (
  1319. this.station.type === "community" &&
  1320. this.station.partyMode === true
  1321. ) {
  1322. this.songsList.forEach(queueSong => {
  1323. if (queueSong.requestedBy === this.userId) isInQueue = true;
  1324. });
  1325. if (!isInQueue && this.privatePlaylistQueueSelected) {
  1326. this.socket.dispatch(
  1327. "playlists.getFirstSong",
  1328. this.privatePlaylistQueueSelected,
  1329. data => {
  1330. if (data.status === "success") {
  1331. if (data.song) {
  1332. if (data.song.duration < 15 * 60) {
  1333. this.automaticallyRequestedSongId =
  1334. data.song.songId;
  1335. this.socket.dispatch(
  1336. "stations.addToQueue",
  1337. this.station._id,
  1338. data.song.songId,
  1339. data2 => {
  1340. if (data2.status === "success")
  1341. this.socket.dispatch(
  1342. "playlists.moveSongToBottom",
  1343. this
  1344. .privatePlaylistQueueSelected,
  1345. data.song.songId
  1346. );
  1347. }
  1348. );
  1349. } else {
  1350. new Toast({
  1351. content: `Top song in playlist was too long to be added.`,
  1352. timeout: 3000
  1353. });
  1354. this.socket.dispatch(
  1355. "playlists.moveSongToBottom",
  1356. this.privatePlaylistQueueSelected,
  1357. data.song.songId,
  1358. data3 => {
  1359. if (data3.status === "success")
  1360. setTimeout(
  1361. () =>
  1362. this.addFirstPrivatePlaylistSongToQueue(),
  1363. 3000
  1364. );
  1365. }
  1366. );
  1367. }
  1368. } else
  1369. new Toast({
  1370. content: `Selected playlist has no songs.`,
  1371. timeout: 4000
  1372. });
  1373. }
  1374. }
  1375. );
  1376. }
  1377. }
  1378. },
  1379. togglePlayerDebugBox() {
  1380. this.$refs.playerDebugBox.toggleBox();
  1381. },
  1382. resetPlayerDebugBox() {
  1383. this.$refs.playerDebugBox.resetBox();
  1384. },
  1385. join() {
  1386. this.socket.dispatch(
  1387. "stations.join",
  1388. this.stationIdentifier,
  1389. res => {
  1390. if (res.status === "success") {
  1391. setTimeout(() => {
  1392. this.loading = false;
  1393. }, 1000); // prevents popping in of youtube embed etc.
  1394. const {
  1395. _id,
  1396. displayName,
  1397. name,
  1398. description,
  1399. privacy,
  1400. locked,
  1401. partyMode,
  1402. owner,
  1403. privatePlaylist,
  1404. includedPlaylists,
  1405. excludedPlaylists,
  1406. type,
  1407. genres,
  1408. blacklistedGenres,
  1409. isFavorited,
  1410. theme
  1411. } = res.data;
  1412. // change url to use station name instead of station id
  1413. if (name !== this.stationIdentifier) {
  1414. // eslint-disable-next-line no-restricted-globals
  1415. history.pushState({}, null, name);
  1416. }
  1417. this.joinStation({
  1418. _id,
  1419. name,
  1420. displayName,
  1421. description,
  1422. privacy,
  1423. locked,
  1424. partyMode,
  1425. owner,
  1426. privatePlaylist,
  1427. includedPlaylists,
  1428. excludedPlaylists,
  1429. type,
  1430. genres,
  1431. blacklistedGenres,
  1432. isFavorited,
  1433. theme
  1434. });
  1435. const currentSong = res.data.currentSong
  1436. ? res.data.currentSong
  1437. : {};
  1438. if (currentSong && !currentSong.thumbnail)
  1439. currentSong.ytThumbnail = `https://img.youtube.com/vi/${currentSong.songId}/mqdefault.jpg`;
  1440. this.updateCurrentSong(currentSong);
  1441. this.startedAt = res.data.startedAt;
  1442. this.updateStationPaused(res.data.paused);
  1443. this.timePaused = res.data.timePaused;
  1444. this.updateUserCount(res.data.userCount);
  1445. this.updateUsers(res.data.users);
  1446. this.pausedAt = res.data.pausedAt;
  1447. if (res.data.currentSong) {
  1448. this.updateNoSong(false);
  1449. this.youtubeReady();
  1450. this.playVideo();
  1451. this.socket.dispatch(
  1452. "songs.getOwnSongRatings",
  1453. res.data.currentSong.songId,
  1454. song => {
  1455. if (
  1456. this.currentSong.songId === song.songId
  1457. ) {
  1458. this.liked = song.liked;
  1459. this.disliked = song.disliked;
  1460. }
  1461. }
  1462. );
  1463. } else {
  1464. if (this.playerReady) this.player.pauseVideo();
  1465. this.updateNoSong(true);
  1466. }
  1467. this.socket.dispatch("stations.getQueue", _id, res => {
  1468. if (res.status === "success") {
  1469. this.updateSongsList(res.queue);
  1470. let nextSong = null;
  1471. if (this.songsList[0]) {
  1472. nextSong = this.songsList[0].songId
  1473. ? this.songsList[0]
  1474. : null;
  1475. }
  1476. this.updateNextSong(nextSong);
  1477. }
  1478. });
  1479. if (this.isOwnerOrAdmin()) {
  1480. keyboardShortcuts.registerShortcut(
  1481. "station.pauseResume",
  1482. {
  1483. keyCode: 32,
  1484. shift: false,
  1485. ctrl: true,
  1486. preventDefault: true,
  1487. handler: () => {
  1488. if (this.stationPaused)
  1489. this.resumeStation();
  1490. else this.pauseStation();
  1491. }
  1492. }
  1493. );
  1494. keyboardShortcuts.registerShortcut(
  1495. "station.skipStation",
  1496. {
  1497. keyCode: 39,
  1498. shift: false,
  1499. ctrl: true,
  1500. preventDefault: true,
  1501. handler: () => {
  1502. this.skipStation();
  1503. }
  1504. }
  1505. );
  1506. }
  1507. keyboardShortcuts.registerShortcut(
  1508. "station.lowerVolumeLarge",
  1509. {
  1510. keyCode: 40,
  1511. shift: false,
  1512. ctrl: true,
  1513. preventDefault: true,
  1514. handler: () => {
  1515. this.volumeSliderValue -= 1000;
  1516. this.changeVolume();
  1517. }
  1518. }
  1519. );
  1520. keyboardShortcuts.registerShortcut(
  1521. "station.lowerVolumeSmall",
  1522. {
  1523. keyCode: 40,
  1524. shift: true,
  1525. ctrl: true,
  1526. preventDefault: true,
  1527. handler: () => {
  1528. this.volumeSliderValue -= 100;
  1529. this.changeVolume();
  1530. }
  1531. }
  1532. );
  1533. keyboardShortcuts.registerShortcut(
  1534. "station.increaseVolumeLarge",
  1535. {
  1536. keyCode: 38,
  1537. shift: false,
  1538. ctrl: true,
  1539. preventDefault: true,
  1540. handler: () => {
  1541. this.volumeSliderValue += 1000;
  1542. this.changeVolume();
  1543. }
  1544. }
  1545. );
  1546. keyboardShortcuts.registerShortcut(
  1547. "station.increaseVolumeSmall",
  1548. {
  1549. keyCode: 38,
  1550. shift: true,
  1551. ctrl: true,
  1552. preventDefault: true,
  1553. handler: () => {
  1554. this.volumeSliderValue += 100;
  1555. this.changeVolume();
  1556. }
  1557. }
  1558. );
  1559. keyboardShortcuts.registerShortcut(
  1560. "station.toggleDebug",
  1561. {
  1562. keyCode: 68,
  1563. shift: false,
  1564. ctrl: true,
  1565. preventDefault: true,
  1566. handler: () => {
  1567. this.togglePlayerDebugBox();
  1568. }
  1569. }
  1570. );
  1571. // UNIX client time before ping
  1572. const beforePing = Date.now();
  1573. this.socket.dispatch("apis.ping", pong => {
  1574. // UNIX client time after ping
  1575. const afterPing = Date.now();
  1576. // Average time in MS it took between the server responding and the client receiving
  1577. const connectionLatency =
  1578. (afterPing - beforePing) / 2;
  1579. console.log(
  1580. connectionLatency,
  1581. beforePing - afterPing
  1582. );
  1583. // UNIX server time
  1584. const serverDate = pong.date;
  1585. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  1586. const difference =
  1587. serverDate + connectionLatency - afterPing;
  1588. console.log("Difference: ", difference);
  1589. if (difference > 3000 || difference < -3000) {
  1590. console.log(
  1591. "System time difference is bigger than 3 seconds."
  1592. );
  1593. }
  1594. this.systemDifference = difference;
  1595. });
  1596. } else {
  1597. this.loading = false;
  1598. this.exists = false;
  1599. }
  1600. }
  1601. );
  1602. },
  1603. favoriteStation() {
  1604. this.socket.dispatch(
  1605. "stations.favoriteStation",
  1606. this.station._id,
  1607. res => {
  1608. if (res.status === "success") {
  1609. new Toast({
  1610. content: "Successfully favorited station.",
  1611. timeout: 4000
  1612. });
  1613. } else new Toast({ content: res.message, timeout: 8000 });
  1614. }
  1615. );
  1616. },
  1617. unfavoriteStation() {
  1618. this.socket.dispatch(
  1619. "stations.unfavoriteStation",
  1620. this.station._id,
  1621. res => {
  1622. if (res.status === "success") {
  1623. new Toast({
  1624. content: "Successfully unfavorited station.",
  1625. timeout: 4000
  1626. });
  1627. } else new Toast({ content: res.message, timeout: 8000 });
  1628. }
  1629. );
  1630. },
  1631. editSong(song) {
  1632. this.editingSongId = song._id;
  1633. this.openModal({ sector: "admin", modal: "editSong" });
  1634. },
  1635. ...mapActions("modalVisibility", ["openModal"]),
  1636. ...mapActions("station", [
  1637. "joinStation",
  1638. "updateUserCount",
  1639. "updateUsers",
  1640. "updateCurrentSong",
  1641. "updatePreviousSong",
  1642. "updateNextSong",
  1643. "updateSongsList",
  1644. "updateStationPaused",
  1645. "updateLocalPaused",
  1646. "updateNoSong",
  1647. "updateIfStationIsFavorited"
  1648. ]),
  1649. ...mapActions("modals/editSong", ["stopVideo"])
  1650. }
  1651. };
  1652. </script>
  1653. <style lang="scss" scoped>
  1654. #page-loader-container {
  1655. height: inherit;
  1656. #page-loader-content {
  1657. height: inherit;
  1658. position: absolute;
  1659. max-width: 100%;
  1660. width: 1800px;
  1661. transform: translateX(-50%);
  1662. left: 50%;
  1663. }
  1664. #page-loader-layout {
  1665. height: inherit;
  1666. width: 100%;
  1667. }
  1668. }
  1669. #mobile-progress-animation {
  1670. width: 50px;
  1671. animation: rotate 0.8s infinite linear;
  1672. border: 8px solid var(--primary-color);
  1673. border-right-color: transparent;
  1674. border-radius: 50%;
  1675. height: 50px;
  1676. position: absolute;
  1677. top: 50%;
  1678. left: 50%;
  1679. display: none;
  1680. }
  1681. @keyframes rotate {
  1682. 0% {
  1683. transform: rotate(0deg);
  1684. }
  1685. 100% {
  1686. transform: rotate(360deg);
  1687. }
  1688. }
  1689. .nav,
  1690. .button.is-primary {
  1691. background-color: var(--primary-color) !important;
  1692. }
  1693. .button.is-primary:hover,
  1694. .button.is-primary:focus {
  1695. filter: brightness(90%);
  1696. }
  1697. #player-debug-box {
  1698. .box-body {
  1699. flex-direction: column;
  1700. b {
  1701. color: var(--black);
  1702. }
  1703. }
  1704. }
  1705. .night-mode {
  1706. #currently-playing-container,
  1707. #next-up-container,
  1708. #about-station-container,
  1709. #control-bar-container,
  1710. .player-container {
  1711. background-color: var(--dark-grey-3) !important;
  1712. }
  1713. #video-container,
  1714. #control-bar-container,
  1715. .quadrant:not(#sidebar-container),
  1716. .player-container {
  1717. border: 0 !important;
  1718. }
  1719. #seeker-bar-container {
  1720. background-color: var(--dark-grey-3) !important;
  1721. }
  1722. #dropdown-toggle {
  1723. background-color: var(--dark-grey-2) !important;
  1724. border: 0;
  1725. i {
  1726. color: var(--white);
  1727. }
  1728. }
  1729. }
  1730. #station-outer-container {
  1731. margin: 0 auto;
  1732. padding: 20px 40px;
  1733. height: 100%;
  1734. width: 100%;
  1735. max-width: 1800px;
  1736. display: flex;
  1737. #station-inner-container {
  1738. height: 100%;
  1739. width: 100%;
  1740. min-height: calc(100vh - 428px);
  1741. display: flex;
  1742. flex-direction: row;
  1743. flex-wrap: wrap;
  1744. .row {
  1745. display: flex;
  1746. flex-direction: row;
  1747. max-width: 100%;
  1748. }
  1749. .column {
  1750. display: flex;
  1751. flex-direction: column;
  1752. }
  1753. .quadrant {
  1754. border-radius: 5px;
  1755. margin: 10px;
  1756. flex-grow: 1;
  1757. }
  1758. .quadrant:not(#sidebar-container) {
  1759. background-color: var(--white);
  1760. border: 1px solid var(--light-grey-3);
  1761. }
  1762. #station-left-column {
  1763. padding: 0;
  1764. }
  1765. #station-right-column {
  1766. max-width: 650px;
  1767. padding: 0;
  1768. }
  1769. #about-station-container {
  1770. padding: 20px;
  1771. display: flex;
  1772. flex-direction: column;
  1773. flex-grow: unset;
  1774. #station-info {
  1775. #station-name {
  1776. flex-direction: row !important;
  1777. h1 {
  1778. margin: 0;
  1779. font-size: 36px;
  1780. line-height: 0.8;
  1781. }
  1782. i {
  1783. margin-left: 10px;
  1784. font-size: 30px;
  1785. color: var(--yellow);
  1786. &.stationMode {
  1787. padding-left: 10px;
  1788. margin-left: auto;
  1789. color: var(--primary-color);
  1790. }
  1791. }
  1792. }
  1793. p {
  1794. max-width: 700px;
  1795. margin-bottom: 10px;
  1796. }
  1797. }
  1798. #admin-buttons {
  1799. display: flex;
  1800. .button {
  1801. margin: 3px;
  1802. }
  1803. }
  1804. }
  1805. #current-next-row {
  1806. display: flex;
  1807. flex-direction: row;
  1808. #currently-playing-container,
  1809. #next-up-container {
  1810. overflow: hidden;
  1811. flex-basis: 50%;
  1812. .nothing-here-text {
  1813. height: 100%;
  1814. }
  1815. }
  1816. }
  1817. .player-container {
  1818. height: inherit;
  1819. background-color: var(--white);
  1820. display: flex;
  1821. flex-direction: column;
  1822. border: 1px solid var(--light-grey-3);
  1823. border-radius: 5px;
  1824. overflow: hidden;
  1825. flex-grow: 1;
  1826. &.nothing-here-text {
  1827. margin: 10px;
  1828. }
  1829. #video-container {
  1830. width: 100%;
  1831. height: 100%;
  1832. .player-cannot-autoplay {
  1833. position: relative;
  1834. width: 100%;
  1835. height: 100%;
  1836. bottom: calc(100% + 5px);
  1837. background: var(--primary-color);
  1838. display: flex;
  1839. align-items: center;
  1840. justify-content: center;
  1841. p {
  1842. color: var(--white);
  1843. font-size: 26px;
  1844. text-align: center;
  1845. }
  1846. }
  1847. }
  1848. #seeker-bar-container {
  1849. background-color: var(--white);
  1850. position: relative;
  1851. height: 7px;
  1852. display: block;
  1853. width: 100%;
  1854. overflow: hidden;
  1855. #seeker-bar {
  1856. background-color: var(--primary-color);
  1857. top: 0;
  1858. left: 0;
  1859. bottom: 0;
  1860. position: absolute;
  1861. }
  1862. }
  1863. #control-bar-container {
  1864. display: flex;
  1865. justify-content: space-around;
  1866. padding: 10px 0;
  1867. width: 100%;
  1868. background: var(--white);
  1869. flex-direction: column;
  1870. flex-flow: wrap;
  1871. .button:not(#dropdown-toggle) {
  1872. width: 75px;
  1873. }
  1874. #left-buttons,
  1875. #right-buttons {
  1876. margin: 3px;
  1877. }
  1878. #left-buttons {
  1879. display: flex;
  1880. .button:not(:first-of-type) {
  1881. margin-left: 5px;
  1882. }
  1883. .disabled {
  1884. filter: grayscale(0.4);
  1885. }
  1886. }
  1887. #duration {
  1888. margin: 3px;
  1889. display: flex;
  1890. align-items: center;
  1891. p {
  1892. font-size: 22px;
  1893. /** prevents duration width slightly varying and shifting other controls slightly */
  1894. width: 150px;
  1895. text-align: center;
  1896. }
  1897. }
  1898. #volume-control {
  1899. margin: 3px;
  1900. margin-top: 0;
  1901. display: flex;
  1902. align-items: center;
  1903. cursor: pointer;
  1904. .volume-slider {
  1905. width: 100%;
  1906. padding: 0 15px;
  1907. background: transparent;
  1908. min-width: 100px;
  1909. }
  1910. input[type="range"] {
  1911. -webkit-appearance: none;
  1912. margin: 7.3px 0;
  1913. }
  1914. input[type="range"]:focus {
  1915. outline: none;
  1916. }
  1917. input[type="range"]::-webkit-slider-runnable-track {
  1918. width: 100%;
  1919. height: 5.2px;
  1920. cursor: pointer;
  1921. box-shadow: 0;
  1922. background: var(--light-grey-3);
  1923. border-radius: 0;
  1924. border: 0;
  1925. }
  1926. input[type="range"]::-webkit-slider-thumb {
  1927. box-shadow: 0;
  1928. border: 0;
  1929. height: 19px;
  1930. width: 19px;
  1931. border-radius: 15px;
  1932. background: var(--primary-color);
  1933. cursor: pointer;
  1934. -webkit-appearance: none;
  1935. margin-top: -6.5px;
  1936. }
  1937. input[type="range"]::-moz-range-track {
  1938. width: 100%;
  1939. height: 5.2px;
  1940. cursor: pointer;
  1941. box-shadow: 0;
  1942. background: var(--light-grey-3);
  1943. border-radius: 0;
  1944. border: 0;
  1945. }
  1946. input[type="range"]::-moz-range-thumb {
  1947. box-shadow: 0;
  1948. border: 0;
  1949. height: 19px;
  1950. width: 19px;
  1951. border-radius: 15px;
  1952. background: var(--primary-color);
  1953. cursor: pointer;
  1954. -webkit-appearance: none;
  1955. margin-top: -6.5px;
  1956. }
  1957. input[type="range"]::-ms-track {
  1958. width: 100%;
  1959. height: 5.2px;
  1960. cursor: pointer;
  1961. box-shadow: 0;
  1962. background: var(--light-grey-3);
  1963. border-radius: 1.3px;
  1964. }
  1965. input[type="range"]::-ms-fill-lower {
  1966. background: var(--light-grey-3);
  1967. border: 0;
  1968. border-radius: 0;
  1969. box-shadow: 0;
  1970. }
  1971. input[type="range"]::-ms-fill-upper {
  1972. background: var(--light-grey-3);
  1973. border: 0;
  1974. border-radius: 0;
  1975. box-shadow: 0;
  1976. }
  1977. input[type="range"]::-ms-thumb {
  1978. box-shadow: 0;
  1979. border: 0;
  1980. height: 15px;
  1981. width: 15px;
  1982. border-radius: 15px;
  1983. background: var(--primary-color);
  1984. cursor: pointer;
  1985. -webkit-appearance: none;
  1986. margin-top: 1.5px;
  1987. }
  1988. }
  1989. #right-buttons {
  1990. display: flex;
  1991. #dropdown-toggle {
  1992. width: 35px;
  1993. }
  1994. #dislike-song,
  1995. #add-song-to-playlist .button:not(#dropdown-toggle) {
  1996. margin-left: 5px;
  1997. }
  1998. #ratings {
  1999. display: flex;
  2000. &.liked #dislike-song,
  2001. &.disliked #like-song {
  2002. background-color: var(--grey) !important;
  2003. }
  2004. #like-song.disabled,
  2005. #dislike-song.disabled {
  2006. filter: grayscale(0.4);
  2007. }
  2008. }
  2009. #add-song-to-playlist {
  2010. display: flex;
  2011. flex-direction: column-reverse;
  2012. #nav-dropdown {
  2013. position: absolute;
  2014. margin-left: 4px;
  2015. margin-bottom: 36px;
  2016. .nav-dropdown-items {
  2017. position: relative;
  2018. right: calc(100% - 110px);
  2019. }
  2020. }
  2021. .control {
  2022. width: fit-content;
  2023. margin-bottom: 0 !important;
  2024. button.disabled {
  2025. filter: grayscale(0.4);
  2026. border-radius: 3px;
  2027. &::after {
  2028. margin-right: 100%;
  2029. }
  2030. }
  2031. }
  2032. }
  2033. }
  2034. }
  2035. }
  2036. #sidebar-container {
  2037. border-top: 0;
  2038. position: relative;
  2039. height: inherit;
  2040. }
  2041. }
  2042. }
  2043. .footer {
  2044. margin-top: 30px;
  2045. }
  2046. /deep/ .nothing-here-text {
  2047. display: flex;
  2048. align-items: center;
  2049. justify-content: center;
  2050. }
  2051. @media (max-width: 950px) {
  2052. #mobile-progress-animation {
  2053. display: block;
  2054. }
  2055. #page-loader-container {
  2056. display: none;
  2057. }
  2058. #station-outer-container {
  2059. padding: 10px;
  2060. height: unset;
  2061. max-width: 700px;
  2062. #station-inner-container {
  2063. flex-direction: column;
  2064. #station-left-column {
  2065. #current-next-row {
  2066. flex-direction: column;
  2067. }
  2068. #control-bar-container {
  2069. #duration,
  2070. #volume-control,
  2071. #right-buttons,
  2072. #left-buttons {
  2073. margin-bottom: 5px;
  2074. justify-content: center;
  2075. }
  2076. #duration {
  2077. order: 1;
  2078. }
  2079. #volume-control {
  2080. order: 2;
  2081. max-width: 400px;
  2082. }
  2083. #right-buttons {
  2084. order: 3;
  2085. flex-wrap: wrap;
  2086. #ratings {
  2087. flex-wrap: wrap;
  2088. }
  2089. }
  2090. #left-buttons {
  2091. order: 4;
  2092. flex-wrap: wrap;
  2093. }
  2094. }
  2095. }
  2096. #station-right-column {
  2097. max-width: unset;
  2098. #about-station-container #admin-buttons {
  2099. flex-wrap: wrap;
  2100. }
  2101. #sidebar-container {
  2102. min-height: 350px;
  2103. }
  2104. }
  2105. }
  2106. }
  2107. }
  2108. </style>