index.vue 50 KB

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