index.vue 48 KB

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