Station.vue 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. <template>
  2. <div>
  3. <official-header v-if="type == 'official'" />
  4. <community-header v-if="type == 'community'" />
  5. <song-queue v-if="modals.addSongToQueue" />
  6. <add-to-playlist v-if="modals.addSongToPlaylist" />
  7. <edit-playlist v-if="modals.editPlaylist" />
  8. <create-playlist v-if="modals.createPlaylist" />
  9. <edit-station v-show="modals.editStation" />
  10. <report v-if="modals.report" />
  11. <songs-list-sidebar v-if="sidebars.songslist" />
  12. <playlist-sidebar v-if="sidebars.playlist" />
  13. <users-sidebar v-if="sidebars.users" />
  14. <div v-show="!ready" class="progress" />
  15. <div v-show="ready" class="station">
  16. <div v-show="noSong" class="no-song">
  17. <h1>No song is currently playing</h1>
  18. <h4
  19. v-if="
  20. type === 'community' &&
  21. station.partyMode &&
  22. (!station.locked ||
  23. (station.locked &&
  24. $parent.loggedIn &&
  25. $parent.userId === station.owner))
  26. "
  27. >
  28. <a
  29. href="#"
  30. class="no-song"
  31. @click="
  32. toggleModal({
  33. sector: 'station',
  34. modal: 'addSongToQueue'
  35. })
  36. "
  37. >Add a song to the queue</a
  38. >
  39. </h4>
  40. <h4
  41. v-if="
  42. type === 'community' &&
  43. !station.partyMode &&
  44. $parent.userId === station.owner &&
  45. !station.privatePlaylist
  46. "
  47. >
  48. <a
  49. href="#"
  50. class="no-song"
  51. @click="sidebars.playlist = true"
  52. >Play a private playlist</a
  53. >
  54. </h4>
  55. <h1
  56. v-if="
  57. type === 'community' &&
  58. !station.partyMode &&
  59. $parent.userId === station.owner &&
  60. station.privatePlaylist
  61. "
  62. >
  63. Maybe you can add some songs to your selected private
  64. playlist and then press the skip button
  65. </h1>
  66. </div>
  67. <div v-show="!noSong" class="columns">
  68. <div
  69. class="column is-8-desktop is-offset-2-desktop is-12-mobile"
  70. >
  71. <div class="video-container">
  72. <div id="player" />
  73. </div>
  74. <div
  75. id="preview-progress"
  76. class="seeker-bar-container white"
  77. >
  78. <div class="seeker-bar light-blue" style="width: 0%;" />
  79. </div>
  80. </div>
  81. <div
  82. class="desktop-only column is-3-desktop card playlistCard experimental"
  83. >
  84. <div v-if="type === 'community'" class="title">
  85. Queue
  86. </div>
  87. <div v-else class="title">
  88. Playlist
  89. </div>
  90. <article v-if="!noSong" class="media">
  91. <figure class="media-left">
  92. <p class="image is-64x64">
  93. <img
  94. :src="currentSong.thumbnail"
  95. onerror="this.src='/assets/notes-transparent.png'"
  96. />
  97. </p>
  98. </figure>
  99. <div class="media-content">
  100. <div class="content">
  101. <p>
  102. Current Song:
  103. <br />
  104. <strong>{{ currentSong.title }}</strong>
  105. <br />
  106. <small>{{ currentSong.artists }}</small>
  107. </p>
  108. </div>
  109. </div>
  110. <div class="media-right">
  111. {{ formatTime(currentSong.duration) }}
  112. </div>
  113. </article>
  114. <p v-if="noSong" class="center">
  115. There is currently no song playing.
  116. </p>
  117. <article
  118. v-for="(song, index) in songsList"
  119. :key="index"
  120. class="media"
  121. >
  122. <div class="media-content">
  123. <div class="content">
  124. <strong class="songTitle">{{
  125. song.title
  126. }}</strong>
  127. <br />
  128. <small>{{ song.artists.join(", ") }}</small>
  129. <br />
  130. <div v-if="station.partyMode">
  131. <br />
  132. <small>
  133. Requested by
  134. <b>
  135. <user-id-to-username
  136. :userId="song.requestedBy"
  137. :link="true"
  138. />
  139. </b>
  140. </small>
  141. <button
  142. v-if="isOwnerOnly() || isAdminOnly()"
  143. class="button"
  144. @click="removeFromQueue(song.songId)"
  145. >
  146. REMOVE
  147. </button>
  148. </div>
  149. </div>
  150. </div>
  151. <div class="media-right">
  152. {{ formatTime(song.duration) }}
  153. </div>
  154. </article>
  155. <a
  156. v-if="type === 'community' && $parent.loggedIn"
  157. class="button add-to-queue"
  158. href="#"
  159. @click="
  160. toggleModal({
  161. sector: 'station',
  162. modal: 'addSongToQueue'
  163. })
  164. "
  165. >Add Song to Queue</a
  166. >
  167. </div>
  168. </div>
  169. <div v-show="!noSong" class="desktop-only columns is-mobile">
  170. <div
  171. class="column is-8-desktop is-offset-2-desktop is-12-mobile"
  172. >
  173. <div class="columns is-mobile">
  174. <div class="column is-12-desktop">
  175. <h4 id="time-display">
  176. {{ timeElapsed }} /
  177. {{ formatTime(currentSong.duration) }}
  178. </h4>
  179. <h3>{{ currentSong.title }}</h3>
  180. <h4 class="thin" style="margin-left: 0">
  181. {{ currentSong.artists }}
  182. </h4>
  183. <div class="columns is-mobile">
  184. <form
  185. style="margin-top: 12px; margin-bottom: 0;"
  186. action="#"
  187. class="column is-7-desktop is-4-mobile"
  188. >
  189. <p class="volume-slider-wrapper">
  190. <i
  191. v-if="muted"
  192. class="material-icons"
  193. @click="toggleMute()"
  194. >volume_mute</i
  195. >
  196. <i
  197. v-else
  198. class="material-icons"
  199. @click="toggleMute()"
  200. >volume_down</i
  201. >
  202. <input
  203. id="volumeSlider"
  204. type="range"
  205. min="0"
  206. max="10000"
  207. class="active"
  208. @change="changeVolume()"
  209. @input="changeVolume()"
  210. />
  211. <i
  212. class="material-icons"
  213. @click="increaseVolume()"
  214. >volume_up</i
  215. >
  216. </p>
  217. </form>
  218. <div
  219. class="column is-8-mobile is-5-desktop"
  220. style="float: right;"
  221. >
  222. <ul
  223. v-if="
  224. currentSong.likes !== -1 &&
  225. currentSong.dislikes !== -1
  226. "
  227. id="ratings"
  228. >
  229. <li
  230. id="like"
  231. class="right"
  232. @click="toggleLike()"
  233. >
  234. <span class="flow-text">{{
  235. currentSong.likes
  236. }}</span>
  237. <i
  238. id="thumbs_up"
  239. class="material-icons grey-text"
  240. :class="{ liked: liked }"
  241. >thumb_up</i
  242. >
  243. <a
  244. class="absolute-a behind"
  245. href="#"
  246. @click="toggleLike()"
  247. />
  248. </li>
  249. <li
  250. id="dislike"
  251. style="margin-right: 10px;"
  252. class="right"
  253. @click="toggleDislike()"
  254. >
  255. <span class="flow-text">{{
  256. currentSong.dislikes
  257. }}</span>
  258. <i
  259. id="thumbs_down"
  260. class="material-icons grey-text"
  261. :class="{
  262. disliked: disliked
  263. }"
  264. >thumb_down</i
  265. >
  266. <a
  267. class="absolute-a behind"
  268. href="#"
  269. @click="toggleDislike()"
  270. />
  271. </li>
  272. </ul>
  273. </div>
  274. </div>
  275. </div>
  276. <div
  277. v-if="!simpleSong"
  278. class="column is-3-desktop experimental"
  279. >
  280. <img
  281. class="image"
  282. :src="currentSong.thumbnail"
  283. alt="Song Thumbnail"
  284. onerror="this.src='/assets/notes-transparent.png'"
  285. />
  286. </div>
  287. </div>
  288. </div>
  289. </div>
  290. <div v-show="!noSong" class="mobile-only">
  291. <div>
  292. <div>
  293. <div>
  294. <h3>{{ currentSong.title }}</h3>
  295. <h4 class="thin">
  296. {{ currentSong.artists }}
  297. </h4>
  298. <h5>
  299. {{ timeElapsed }} /
  300. {{ formatTime(currentSong.duration) }}
  301. </h5>
  302. <div>
  303. <form class="columns" action="#">
  304. <p
  305. class="column is-11-mobile volume-slider-wrapper"
  306. >
  307. <i
  308. v-if="muted"
  309. class="material-icons"
  310. @click="toggleMute()"
  311. >volume_mute</i
  312. >
  313. <i
  314. v-else
  315. class="material-icons"
  316. @click="toggleMute()"
  317. >volume_down</i
  318. >
  319. <input
  320. id="volumeSlider"
  321. type="range"
  322. min="0"
  323. max="10000"
  324. class="active"
  325. @change="changeVolume()"
  326. @input="changeVolume()"
  327. />
  328. <i
  329. class="material-icons"
  330. @click="increaseVolume()"
  331. >volume_up</i
  332. >
  333. </p>
  334. </form>
  335. <div>
  336. <ul
  337. v-if="
  338. currentSong.likes !== -1 &&
  339. currentSong.dislikes !== -1
  340. "
  341. id="ratings"
  342. style="display: inline-block;"
  343. >
  344. <li
  345. id="dislike"
  346. style="display: inline-block;margin-right: 10px;"
  347. @click="toggleDislike()"
  348. >
  349. <span class="flow-text">{{
  350. currentSong.dislikes
  351. }}</span>
  352. <i
  353. id="thumbs_down"
  354. class="material-icons grey-text"
  355. :class="{
  356. disliked: disliked
  357. }"
  358. >thumb_down</i
  359. >
  360. <a
  361. class="absolute-a behind"
  362. href="#"
  363. @click="toggleDislike()"
  364. />
  365. </li>
  366. <li
  367. id="like"
  368. style="display: inline-block;"
  369. @click="toggleLike()"
  370. >
  371. <span class="flow-text">{{
  372. currentSong.likes
  373. }}</span>
  374. <i
  375. id="thumbs_up"
  376. class="material-icons grey-text"
  377. :class="{ liked: liked }"
  378. >thumb_up</i
  379. >
  380. <a
  381. class="absolute-a behind"
  382. href="#"
  383. @click="toggleLike()"
  384. />
  385. </li>
  386. </ul>
  387. </div>
  388. </div>
  389. </div>
  390. </div>
  391. </div>
  392. </div>
  393. </div>
  394. </div>
  395. </template>
  396. <script>
  397. import { mapState, mapActions } from "vuex";
  398. import { Toast } from "vue-roaster";
  399. import SongQueue from "../Modals/AddSongToQueue.vue";
  400. import AddToPlaylist from "../Modals/AddSongToPlaylist.vue";
  401. import EditPlaylist from "../Modals/Playlists/Edit.vue";
  402. import CreatePlaylist from "../Modals/Playlists/Create.vue";
  403. import EditStation from "../Modals/EditStation.vue";
  404. import Report from "../Modals/Report.vue";
  405. import SongsListSidebar from "../Sidebars/SongsList.vue";
  406. import PlaylistSidebar from "../Sidebars/Playlist.vue";
  407. import UsersSidebar from "../Sidebars/UsersList.vue";
  408. import OfficialHeader from "./OfficialHeader.vue";
  409. import CommunityHeader from "./CommunityHeader.vue";
  410. import UserIdToUsername from "../UserIdToUsername.vue";
  411. import io from "../../io";
  412. export default {
  413. data() {
  414. return {
  415. ready: false,
  416. type: "",
  417. playerReady: false,
  418. previousSong: null,
  419. currentSong: {},
  420. player: undefined,
  421. timePaused: 0,
  422. paused: false,
  423. muted: false,
  424. timeElapsed: "0:00",
  425. liked: false,
  426. disliked: false,
  427. sidebars: {
  428. songslist: false,
  429. users: false,
  430. playlist: false
  431. },
  432. noSong: false,
  433. simpleSong: false,
  434. songsList: [],
  435. timeBeforePause: 0,
  436. skipVotes: 0,
  437. privatePlaylistQueueSelected: null,
  438. automaticallyRequestedSongId: null,
  439. systemDifference: 0,
  440. users: [],
  441. userCount: 0
  442. };
  443. },
  444. computed: {
  445. ...mapState("modals", {
  446. modals: state => state.modals.station
  447. }),
  448. ...mapState("station", {
  449. station: state => state.station
  450. })
  451. },
  452. methods: {
  453. isOwnerOnly: function() {
  454. return (
  455. this.$parent.loggedIn &&
  456. this.$parent.userId === this.station.owner
  457. );
  458. },
  459. isAdminOnly: function() {
  460. return this.$parent.loggedIn && this.$parent.role === "admin";
  461. },
  462. removeFromQueue: function(songId) {
  463. window.socket.emit(
  464. "stations.removeFromQueue",
  465. this.station._id,
  466. songId,
  467. res => {
  468. if (res.status === "success") {
  469. Toast.methods.addToast(
  470. "Successfully removed song from the queue.",
  471. 4000
  472. );
  473. } else Toast.methods.addToast(res.message, 8000);
  474. }
  475. );
  476. },
  477. toggleSidebar: function(type) {
  478. Object.keys(this.sidebars).forEach(sidebar => {
  479. if (sidebar !== type) this.sidebars[sidebar] = false;
  480. else this.sidebars[type] = !this.sidebars[type];
  481. });
  482. },
  483. youtubeReady: function() {
  484. let local = this;
  485. if (!local.player) {
  486. local.player = new window.YT.Player("player", {
  487. height: 270,
  488. width: 480,
  489. videoId: local.currentSong.songId,
  490. startSeconds:
  491. local.getTimeElapsed() / 1000 +
  492. local.currentSong.skipDuration,
  493. playerVars: {
  494. controls: 0,
  495. iv_load_policy: 3,
  496. rel: 0,
  497. showinfo: 0
  498. },
  499. events: {
  500. onReady: function() {
  501. local.playerReady = true;
  502. let volume = parseInt(
  503. localStorage.getItem("volume")
  504. );
  505. volume = typeof volume === "number" ? volume : 20;
  506. local.player.setVolume(volume);
  507. if (volume > 0) local.player.unMute();
  508. local.playVideo();
  509. },
  510. onError: function(err) {
  511. console.log("iframe error", err);
  512. local.voteSkipStation();
  513. },
  514. onStateChange: function(event) {
  515. if (
  516. event.data === 1 &&
  517. local.videoLoading === true
  518. ) {
  519. local.videoLoading = false;
  520. local.player.seekTo(
  521. local.getTimeElapsed() / 1000 +
  522. local.currentSong.skipDuration,
  523. true
  524. );
  525. if (local.paused) local.player.pauseVideo();
  526. } else if (event.data === 1 && local.paused) {
  527. local.player.seekTo(
  528. local.timeBeforePause / 1000,
  529. true
  530. );
  531. local.player.pauseVideo();
  532. }
  533. if (
  534. event.data === 2 &&
  535. !local.paused &&
  536. !local.noSong &&
  537. local.player.getDuration() / 1000 <
  538. local.currentSong.duration
  539. ) {
  540. local.player.seekTo(
  541. local.getTimeElapsed() / 1000 +
  542. local.currentSong.skipDuration,
  543. true
  544. );
  545. local.player.playVideo();
  546. }
  547. }
  548. }
  549. });
  550. }
  551. },
  552. getTimeElapsed: function() {
  553. let local = this;
  554. if (local.currentSong)
  555. return Date.currently() - local.startedAt - local.timePaused;
  556. else return 0;
  557. },
  558. playVideo: function() {
  559. let local = this;
  560. if (local.playerReady) {
  561. local.videoLoading = true;
  562. local.player.loadVideoById(
  563. local.currentSong.songId,
  564. local.getTimeElapsed() / 1000 +
  565. local.currentSong.skipDuration
  566. );
  567. if (local.currentSong.artists)
  568. local.currentSong.artists = local.currentSong.artists.join(
  569. ", "
  570. );
  571. if (window.stationInterval !== 0)
  572. clearInterval(window.stationInterval);
  573. window.stationInterval = setInterval(function() {
  574. local.resizeSeekerbar();
  575. local.calculateTimeElapsed();
  576. }, 150);
  577. }
  578. },
  579. resizeSeekerbar: function() {
  580. let local = this;
  581. if (!local.paused) {
  582. document.getElementsByClassName("seeker-bar")[0].style.width =
  583. parseFloat(
  584. (local.getTimeElapsed() /
  585. 1000 /
  586. local.currentSong.duration) *
  587. 100
  588. ) + "%";
  589. }
  590. },
  591. formatTime: function(duration) {
  592. let d = moment.duration(duration, "seconds");
  593. if (duration < 0) return "0:00";
  594. return (
  595. (d.hours() > 0
  596. ? d.hours() < 10
  597. ? "0" + d.hours() + ":"
  598. : d.hours() + ":"
  599. : "") +
  600. (d.minutes() + ":") +
  601. (d.seconds() < 10 ? "0" + d.seconds() : d.seconds())
  602. );
  603. },
  604. calculateTimeElapsed: function() {
  605. let local = this;
  606. if (local.currentTime !== undefined && local.paused) {
  607. local.timePaused += Date.currently() - local.currentTime;
  608. local.currentTime = undefined;
  609. }
  610. let duration =
  611. (Date.currently() - local.startedAt - local.timePaused) / 1000;
  612. let songDuration = local.currentSong.duration;
  613. if (songDuration <= duration) local.player.pauseVideo();
  614. if (!local.paused && duration <= songDuration)
  615. local.timeElapsed = local.formatTime(duration);
  616. },
  617. toggleLock: function() {
  618. window.socket.emit("stations.toggleLock", this.station._id, res => {
  619. if (res.status === "success") {
  620. Toast.methods.addToast(
  621. "Successfully toggled the queue lock.",
  622. 4000
  623. );
  624. } else Toast.methods.addToast(res.message, 8000);
  625. });
  626. },
  627. changeVolume: function() {
  628. let local = this;
  629. let volume = document.getElementById("volumeSlider").value;
  630. localStorage.setItem("volume", volume / 100);
  631. if (local.playerReady) {
  632. local.player.setVolume(volume / 100);
  633. if (volume > 0) local.player.unMute();
  634. }
  635. },
  636. resumeLocalStation: function() {
  637. this.paused = false;
  638. if (!this.noSong) {
  639. if (this.playerReady) {
  640. this.player.seekTo(
  641. this.getTimeElapsed() / 1000 +
  642. this.currentSong.skipDuration
  643. );
  644. this.player.playVideo();
  645. }
  646. }
  647. },
  648. pauseLocalStation: function() {
  649. console.log("pause locally");
  650. this.paused = true;
  651. if (!this.noSong) {
  652. this.timeBeforePause = this.getTimeElapsed();
  653. if (this.playerReady) this.player.pauseVideo();
  654. }
  655. },
  656. skipStation: function() {
  657. let _this = this;
  658. _this.socket.emit("stations.forceSkip", _this.station._id, data => {
  659. if (data.status !== "success")
  660. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  661. else
  662. Toast.methods.addToast(
  663. "Successfully skipped the station's current song.",
  664. 4000
  665. );
  666. });
  667. },
  668. voteSkipStation: function() {
  669. let _this = this;
  670. _this.socket.emit("stations.voteSkip", _this.station._id, data => {
  671. if (data.status !== "success")
  672. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  673. else
  674. Toast.methods.addToast(
  675. "Successfully voted to skip the current song.",
  676. 4000
  677. );
  678. });
  679. },
  680. resumeStation: function() {
  681. let _this = this;
  682. _this.socket.emit("stations.resume", _this.station._id, data => {
  683. if (data.status !== "success")
  684. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  685. else
  686. Toast.methods.addToast(
  687. "Successfully resumed the station.",
  688. 4000
  689. );
  690. });
  691. },
  692. pauseStation: function() {
  693. let _this = this;
  694. _this.socket.emit("stations.pause", _this.station._id, data => {
  695. if (data.status !== "success")
  696. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  697. else
  698. Toast.methods.addToast(
  699. "Successfully paused the station.",
  700. 4000
  701. );
  702. });
  703. },
  704. toggleMute: function() {
  705. if (this.playerReady) {
  706. let previousVolume = parseFloat(localStorage.getItem("volume"));
  707. let volume =
  708. this.player.getVolume() * 100 <= 0 ? previousVolume : 0;
  709. this.muted = !this.muted;
  710. document.getElementById("volumeSlider").value = volume * 100;
  711. this.player.setVolume(volume);
  712. if (!this.muted) localStorage.setItem("volume", volume);
  713. }
  714. },
  715. increaseVolume: function() {
  716. if (this.playerReady) {
  717. let previousVolume = parseInt(localStorage.getItem("volume"));
  718. let volume = previousVolume + 5;
  719. if (previousVolume === 0) this.muted = false;
  720. if (volume > 100) volume = 100;
  721. document.getElementById("volumeSlider").value = volume * 100;
  722. this.player.setVolume(volume);
  723. localStorage.setItem("volume", volume);
  724. }
  725. },
  726. toggleLike: function() {
  727. let _this = this;
  728. if (_this.liked)
  729. _this.socket.emit(
  730. "songs.unlike",
  731. _this.currentSong.songId,
  732. data => {
  733. if (data.status !== "success")
  734. Toast.methods.addToast(
  735. `Error: ${data.message}`,
  736. 8000
  737. );
  738. }
  739. );
  740. else
  741. _this.socket.emit(
  742. "songs.like",
  743. _this.currentSong.songId,
  744. data => {
  745. if (data.status !== "success")
  746. Toast.methods.addToast(
  747. `Error: ${data.message}`,
  748. 8000
  749. );
  750. }
  751. );
  752. },
  753. toggleDislike: function() {
  754. let _this = this;
  755. if (_this.disliked)
  756. return _this.socket.emit(
  757. "songs.undislike",
  758. _this.currentSong.songId,
  759. data => {
  760. if (data.status !== "success")
  761. Toast.methods.addToast(
  762. `Error: ${data.message}`,
  763. 8000
  764. );
  765. }
  766. );
  767. _this.socket.emit(
  768. "songs.dislike",
  769. _this.currentSong.songId,
  770. data => {
  771. if (data.status !== "success")
  772. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  773. }
  774. );
  775. },
  776. addFirstPrivatePlaylistSongToQueue: function() {
  777. let _this = this;
  778. let isInQueue = false;
  779. let userId = _this.$parent.userId;
  780. if (_this.type === "community") {
  781. _this.songsList.forEach(queueSong => {
  782. if (queueSong.requestedBy === userId) isInQueue = true;
  783. });
  784. if (!isInQueue && _this.privatePlaylistQueueSelected) {
  785. _this.socket.emit(
  786. "playlists.getFirstSong",
  787. _this.privatePlaylistQueueSelected,
  788. data => {
  789. if (data.status === "success") {
  790. if (data.song.duration < 15 * 60) {
  791. _this.automaticallyRequestedSongId =
  792. data.song.songId;
  793. _this.socket.emit(
  794. "stations.addToQueue",
  795. _this.station._id,
  796. data.song.songId,
  797. data2 => {
  798. if (data2.status === "success") {
  799. _this.socket.emit(
  800. "playlists.moveSongToBottom",
  801. _this.privatePlaylistQueueSelected,
  802. data.song.songId,
  803. data3 => {
  804. if (
  805. data3.status ===
  806. "success"
  807. ) {} // eslint-disable-line
  808. }
  809. );
  810. }
  811. }
  812. );
  813. } else {
  814. Toast.methods.addToast(
  815. `Top song in playlist was too long to be added.`,
  816. 3000
  817. );
  818. _this.socket.emit(
  819. "playlists.moveSongToBottom",
  820. _this.privatePlaylistQueueSelected,
  821. data.song.songId,
  822. data3 => {
  823. if (data3.status === "success") {
  824. setTimeout(() => {
  825. this.addFirstPrivatePlaylistSongToQueue();
  826. }, 3000);
  827. }
  828. }
  829. );
  830. }
  831. }
  832. }
  833. );
  834. }
  835. }
  836. },
  837. join: function() {
  838. let _this = this;
  839. _this.socket.emit("stations.join", _this.stationName, res => {
  840. if (res.status === "success") {
  841. const {
  842. _id,
  843. displayName,
  844. description,
  845. privacy,
  846. locked,
  847. partyMode,
  848. owner,
  849. privatePlaylist
  850. } = res.data;
  851. _this.joinStation({
  852. _id,
  853. name: _this.stationName,
  854. displayName,
  855. description,
  856. privacy,
  857. locked,
  858. partyMode,
  859. owner,
  860. privatePlaylist
  861. });
  862. _this.currentSong = res.data.currentSong
  863. ? res.data.currentSong
  864. : {};
  865. _this.type = res.data.type;
  866. _this.startedAt = res.data.startedAt;
  867. _this.paused = res.data.paused;
  868. _this.timePaused = res.data.timePaused;
  869. _this.userCount = res.data.userCount;
  870. _this.users = res.data.users;
  871. if (res.data.currentSong) {
  872. _this.noSong = false;
  873. _this.simpleSong =
  874. res.data.currentSong.likes === -1 &&
  875. res.data.currentSong.dislikes === -1;
  876. if (_this.simpleSong) {
  877. _this.currentSong.skipDuration = 0;
  878. }
  879. _this.youtubeReady();
  880. _this.playVideo();
  881. _this.socket.emit(
  882. "songs.getOwnSongRatings",
  883. res.data.currentSong.songId,
  884. data => {
  885. if (_this.currentSong.songId === data.songId) {
  886. _this.liked = data.liked;
  887. _this.disliked = data.disliked;
  888. }
  889. }
  890. );
  891. } else {
  892. if (_this.playerReady) _this.player.pauseVideo();
  893. _this.noSong = true;
  894. }
  895. // UNIX client time before ping
  896. let beforePing = Date.now();
  897. _this.socket.emit("apis.ping", res => {
  898. // UNIX client time after ping
  899. let afterPing = Date.now();
  900. // Average time in MS it took between the server responding and the client receiving
  901. let connectionLatency = (afterPing - beforePing) / 2;
  902. console.log(connectionLatency, beforePing - afterPing);
  903. // UNIX server time
  904. let serverDate = res.date;
  905. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  906. let difference =
  907. serverDate + connectionLatency - afterPing;
  908. console.log("Difference: ", difference);
  909. if (difference > 3000 || difference < -3000) {
  910. console.log(
  911. "System time difference is bigger than 3 seconds."
  912. );
  913. }
  914. _this.systemDifference = difference;
  915. });
  916. }
  917. });
  918. },
  919. ...mapActions("modals", ["toggleModal"]),
  920. ...mapActions("station", ["joinStation"])
  921. },
  922. mounted: function() {
  923. let _this = this;
  924. Date.currently = () => {
  925. return new Date().getTime() + _this.systemDifference;
  926. };
  927. _this.stationName = _this.$route.params.id;
  928. window.stationInterval = 0;
  929. io.getSocket(socket => {
  930. _this.socket = socket;
  931. io.removeAllListeners();
  932. if (_this.socket.connected) _this.join();
  933. io.onConnect(_this.join);
  934. _this.socket.emit("stations.findByName", _this.stationName, res => {
  935. if (res.status === "error") {
  936. _this.$router.go("/404");
  937. Toast.methods.addToast(res.message, 3000);
  938. } else {
  939. _this.ready = true;
  940. }
  941. });
  942. _this.socket.on("event:songs.next", data => {
  943. _this.previousSong = _this.currentSong.songId
  944. ? _this.currentSong
  945. : null;
  946. _this.currentSong = data.currentSong ? data.currentSong : {};
  947. _this.startedAt = data.startedAt;
  948. _this.paused = data.paused;
  949. _this.timePaused = data.timePaused;
  950. if (data.currentSong) {
  951. _this.noSong = false;
  952. _this.simpleSong =
  953. data.currentSong.likes === -1 &&
  954. data.currentSong.dislikes === -1;
  955. if (_this.simpleSong) _this.currentSong.skipDuration = 0;
  956. if (!_this.playerReady) _this.youtubeReady();
  957. else _this.playVideo();
  958. _this.socket.emit(
  959. "songs.getOwnSongRatings",
  960. data.currentSong.songId,
  961. data => {
  962. if (_this.currentSong.songId === data.songId) {
  963. _this.liked = data.liked;
  964. _this.disliked = data.disliked;
  965. }
  966. }
  967. );
  968. } else {
  969. if (_this.playerReady) _this.player.pauseVideo();
  970. _this.noSong = true;
  971. }
  972. let isInQueue = false;
  973. let userId = _this.$parent.userId;
  974. _this.songsList.forEach(queueSong => {
  975. if (queueSong.requestedBy === userId) isInQueue = true;
  976. });
  977. if (
  978. !isInQueue &&
  979. _this.privatePlaylistQueueSelected &&
  980. (_this.automaticallyRequestedSongId !==
  981. _this.currentSong.songId ||
  982. !_this.currentSong.songId)
  983. ) {
  984. _this.addFirstPrivatePlaylistSongToQueue();
  985. }
  986. });
  987. _this.socket.on("event:stations.pause", () => {
  988. _this.pauseLocalStation();
  989. console.log("local pause");
  990. });
  991. _this.socket.on("event:stations.resume", data => {
  992. _this.timePaused = data.timePaused;
  993. _this.resumeLocalStation();
  994. });
  995. _this.socket.on(
  996. "event:stations.remove",
  997. () => (location.href = "/")
  998. );
  999. _this.socket.on("event:song.like", data => {
  1000. if (!this.noSong) {
  1001. if (data.songId === _this.currentSong.songId) {
  1002. _this.currentSong.dislikes = data.dislikes;
  1003. _this.currentSong.likes = data.likes;
  1004. }
  1005. }
  1006. });
  1007. _this.socket.on("event:song.dislike", data => {
  1008. if (!this.noSong) {
  1009. if (data.songId === _this.currentSong.songId) {
  1010. _this.currentSong.dislikes = data.dislikes;
  1011. _this.currentSong.likes = data.likes;
  1012. }
  1013. }
  1014. });
  1015. _this.socket.on("event:song.unlike", data => {
  1016. if (!this.noSong) {
  1017. if (data.songId === _this.currentSong.songId) {
  1018. _this.currentSong.dislikes = data.dislikes;
  1019. _this.currentSong.likes = data.likes;
  1020. }
  1021. }
  1022. });
  1023. _this.socket.on("event:song.undislike", data => {
  1024. if (!this.noSong) {
  1025. if (data.songId === _this.currentSong.songId) {
  1026. _this.currentSong.dislikes = data.dislikes;
  1027. _this.currentSong.likes = data.likes;
  1028. }
  1029. }
  1030. });
  1031. _this.socket.on("event:song.newRatings", data => {
  1032. if (!this.noSong) {
  1033. if (data.songId === _this.currentSong.songId) {
  1034. _this.liked = data.liked;
  1035. _this.disliked = data.disliked;
  1036. }
  1037. }
  1038. });
  1039. _this.socket.on("event:queue.update", queue => {
  1040. if (this.type === "community") this.songsList = queue;
  1041. });
  1042. _this.socket.on("event:song.voteSkipSong", () => {
  1043. if (this.currentSong) this.currentSong.skipVotes++;
  1044. });
  1045. _this.socket.on("event:privatePlaylist.selected", playlistId => {
  1046. if (this.type === "community") {
  1047. this.station.privatePlaylist = playlistId;
  1048. }
  1049. });
  1050. _this.socket.on("event:partyMode.updated", partyMode => {
  1051. if (this.type === "community") {
  1052. this.station.partyMode = partyMode;
  1053. }
  1054. });
  1055. _this.socket.on("event:newOfficialPlaylist", playlist => {
  1056. if (this.type === "official") {
  1057. this.songsList = playlist;
  1058. }
  1059. });
  1060. _this.socket.on("event:users.updated", users => {
  1061. _this.users = users;
  1062. });
  1063. _this.socket.on("event:userCount.updated", userCount => {
  1064. _this.userCount = userCount;
  1065. });
  1066. _this.socket.on("event:queueLockToggled", locked => {
  1067. _this.station.locked = locked;
  1068. });
  1069. });
  1070. let volume = parseFloat(localStorage.getItem("volume"));
  1071. volume = typeof volume === "number" && !isNaN(volume) ? volume : 20;
  1072. localStorage.setItem("volume", volume);
  1073. document.getElementById("volumeSlider").value = volume * 100;
  1074. },
  1075. components: {
  1076. OfficialHeader,
  1077. CommunityHeader,
  1078. SongQueue,
  1079. AddToPlaylist,
  1080. EditPlaylist,
  1081. CreatePlaylist,
  1082. EditStation,
  1083. Report,
  1084. SongsListSidebar,
  1085. PlaylistSidebar,
  1086. UsersSidebar,
  1087. UserIdToUsername
  1088. }
  1089. };
  1090. </script>
  1091. <style lang="scss">
  1092. .no-song {
  1093. color: #03a9f4;
  1094. text-align: center;
  1095. }
  1096. #volumeSlider {
  1097. padding: 0 15px;
  1098. background: transparent;
  1099. }
  1100. .volume-slider-wrapper {
  1101. margin-top: 0;
  1102. position: relative;
  1103. display: flex;
  1104. align-items: center;
  1105. .material-icons {
  1106. user-select: none;
  1107. }
  1108. }
  1109. .material-icons {
  1110. cursor: pointer;
  1111. }
  1112. .stationDisplayName {
  1113. color: white !important;
  1114. }
  1115. .add-to-playlist {
  1116. display: flex;
  1117. align-items: center;
  1118. justify-content: center;
  1119. }
  1120. .slideout {
  1121. top: 50px;
  1122. height: 100%;
  1123. position: fixed;
  1124. right: 0;
  1125. width: 350px;
  1126. background-color: white;
  1127. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16),
  1128. 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  1129. .slideout-header {
  1130. text-align: center;
  1131. background-color: rgb(3, 169, 244) !important;
  1132. margin: 0;
  1133. padding-top: 5px;
  1134. padding-bottom: 7px;
  1135. color: white;
  1136. }
  1137. .slideout-content {
  1138. height: 100%;
  1139. }
  1140. }
  1141. .modal-large {
  1142. width: 75%;
  1143. }
  1144. .station {
  1145. flex: 1 0 auto;
  1146. padding-top: 0.5vw;
  1147. transition: all 0.1s;
  1148. margin: 0 auto;
  1149. max-width: 100%;
  1150. width: 90%;
  1151. @media only screen and (min-width: 993px) {
  1152. width: 70%;
  1153. }
  1154. @media only screen and (min-width: 601px) {
  1155. width: 85%;
  1156. }
  1157. @media (min-width: 999px) {
  1158. .mobile-only {
  1159. display: none;
  1160. }
  1161. .desktop-only {
  1162. display: block;
  1163. }
  1164. }
  1165. @media (max-width: 998px) {
  1166. .mobile-only {
  1167. display: block;
  1168. }
  1169. .desktop-only {
  1170. display: none;
  1171. visibility: hidden;
  1172. }
  1173. }
  1174. .mobile-only {
  1175. text-align: center;
  1176. }
  1177. .playlistCard {
  1178. margin: 10px;
  1179. position: relative;
  1180. padding-bottom: calc(31.25% + 7px);
  1181. height: 0;
  1182. overflow-y: scroll;
  1183. .title {
  1184. background-color: rgb(3, 169, 244);
  1185. text-align: center;
  1186. padding: 10px;
  1187. color: white;
  1188. font-weight: 600;
  1189. }
  1190. .media {
  1191. padding: 0 25px;
  1192. }
  1193. .media-content .content {
  1194. min-height: 64px;
  1195. max-height: 64px;
  1196. display: flex;
  1197. align-items: center;
  1198. }
  1199. .content p strong {
  1200. word-break: break-word;
  1201. }
  1202. .content p small {
  1203. word-break: break-word;
  1204. }
  1205. .add-to-queue {
  1206. width: 100%;
  1207. margin-top: 25px;
  1208. height: 40px;
  1209. border-radius: 0;
  1210. background: rgb(3, 169, 244);
  1211. color: #fff !important;
  1212. border: 0;
  1213. &:active,
  1214. &:focus {
  1215. border: 0;
  1216. }
  1217. }
  1218. .add-to-queue:focus {
  1219. background: #029ce3;
  1220. }
  1221. .media-right {
  1222. line-height: 64px;
  1223. }
  1224. .songTitle {
  1225. word-wrap: break-word;
  1226. overflow: hidden;
  1227. text-overflow: ellipsis;
  1228. display: -webkit-box;
  1229. -webkit-box-orient: vertical;
  1230. -webkit-line-clamp: 2;
  1231. line-height: 20px;
  1232. max-height: 40px;
  1233. width: 100%;
  1234. }
  1235. }
  1236. input[type="range"] {
  1237. -webkit-appearance: none;
  1238. width: 100%;
  1239. margin: 7.3px 0;
  1240. }
  1241. input[type="range"]:focus {
  1242. outline: none;
  1243. }
  1244. input[type="range"]::-webkit-slider-runnable-track {
  1245. width: 100%;
  1246. height: 5.2px;
  1247. cursor: pointer;
  1248. box-shadow: 0;
  1249. background: #c2c0c2;
  1250. border-radius: 0;
  1251. border: 0;
  1252. }
  1253. input[type="range"]::-webkit-slider-thumb {
  1254. box-shadow: 0;
  1255. border: 0;
  1256. height: 19px;
  1257. width: 19px;
  1258. border-radius: 15px;
  1259. background: #03a9f4;
  1260. cursor: pointer;
  1261. -webkit-appearance: none;
  1262. margin-top: -6.5px;
  1263. }
  1264. input[type="range"]::-moz-range-track {
  1265. width: 100%;
  1266. height: 5.2px;
  1267. cursor: pointer;
  1268. box-shadow: 0;
  1269. background: #c2c0c2;
  1270. border-radius: 0;
  1271. border: 0;
  1272. }
  1273. input[type="range"]::-moz-range-thumb {
  1274. box-shadow: 0;
  1275. border: 0;
  1276. height: 19px;
  1277. width: 19px;
  1278. border-radius: 15px;
  1279. background: #03a9f4;
  1280. cursor: pointer;
  1281. -webkit-appearance: none;
  1282. margin-top: -6.5px;
  1283. }
  1284. input[type="range"]::-ms-track {
  1285. width: 100%;
  1286. height: 5.2px;
  1287. cursor: pointer;
  1288. box-shadow: 0;
  1289. background: #c2c0c2;
  1290. border-radius: 1.3px;
  1291. }
  1292. input[type="range"]::-ms-fill-lower {
  1293. background: #c2c0c2;
  1294. border: 0;
  1295. border-radius: 0;
  1296. box-shadow: 0;
  1297. }
  1298. input[type="range"]::-ms-fill-upper {
  1299. background: #c2c0c2;
  1300. border: 0;
  1301. border-radius: 0;
  1302. box-shadow: 0;
  1303. }
  1304. input[type="range"]::-ms-thumb {
  1305. box-shadow: 0;
  1306. border: 0;
  1307. height: 15px;
  1308. width: 15px;
  1309. border-radius: 15px;
  1310. background: #03a9f4;
  1311. cursor: pointer;
  1312. -webkit-appearance: none;
  1313. margin-top: 1.5px;
  1314. }
  1315. .video-container {
  1316. position: relative;
  1317. padding-bottom: 56.25%;
  1318. height: 0;
  1319. overflow: hidden;
  1320. iframe {
  1321. position: absolute;
  1322. top: 0;
  1323. left: 0;
  1324. width: 100%;
  1325. height: 100%;
  1326. }
  1327. }
  1328. .video-col {
  1329. padding-right: 0.75rem;
  1330. padding-left: 0.75rem;
  1331. }
  1332. }
  1333. .room-title {
  1334. left: 50%;
  1335. -webkit-transform: translateX(-50%);
  1336. transform: translateX(-50%);
  1337. font-size: 2.1em;
  1338. }
  1339. #ratings {
  1340. span {
  1341. font-size: 1.68rem;
  1342. }
  1343. i {
  1344. color: #9e9e9e !important;
  1345. cursor: pointer;
  1346. transition: 0.1s color;
  1347. }
  1348. }
  1349. #time-display {
  1350. margin-top: 30px;
  1351. float: right;
  1352. }
  1353. #thumbs_up:hover,
  1354. #thumbs_up.liked {
  1355. color: #87d37c !important;
  1356. }
  1357. #thumbs_down:hover,
  1358. #thumbs_down.disliked {
  1359. color: #ec644b !important;
  1360. }
  1361. #song-thumbnail {
  1362. max-width: 100%;
  1363. width: 85%;
  1364. }
  1365. .seeker-bar-container {
  1366. position: relative;
  1367. height: 7px;
  1368. display: block;
  1369. width: 100%;
  1370. overflow: hidden;
  1371. }
  1372. .seeker-bar {
  1373. top: 0;
  1374. left: 0;
  1375. bottom: 0;
  1376. position: absolute;
  1377. }
  1378. ul {
  1379. list-style: none;
  1380. margin: 0;
  1381. display: block;
  1382. }
  1383. h1,
  1384. h2,
  1385. h3,
  1386. h4,
  1387. h5,
  1388. h6 {
  1389. font-weight: 400;
  1390. line-height: 1.1;
  1391. }
  1392. h1 a,
  1393. h2 a,
  1394. h3 a,
  1395. h4 a,
  1396. h5 a,
  1397. h6 a {
  1398. font-weight: inherit;
  1399. }
  1400. h1 {
  1401. font-size: 4.2rem;
  1402. line-height: 110%;
  1403. margin: 2.1rem 0 1.68rem 0;
  1404. }
  1405. h2 {
  1406. font-size: 3.56rem;
  1407. line-height: 110%;
  1408. margin: 1.78rem 0 1.424rem 0;
  1409. }
  1410. h3 {
  1411. font-size: 2.92rem;
  1412. line-height: 110%;
  1413. margin: 1.46rem 0 1.168rem 0;
  1414. }
  1415. h4 {
  1416. font-size: 2.28rem;
  1417. line-height: 110%;
  1418. margin: 1.14rem 0 0.912rem 0;
  1419. }
  1420. h5 {
  1421. font-size: 1.64rem;
  1422. line-height: 110%;
  1423. margin: 0.82rem 0 0.656rem 0;
  1424. }
  1425. h6 {
  1426. font-size: 1rem;
  1427. line-height: 110%;
  1428. margin: 0.5rem 0 0.4rem 0;
  1429. }
  1430. .thin {
  1431. font-weight: 200;
  1432. }
  1433. .left {
  1434. float: left !important;
  1435. }
  1436. .right {
  1437. float: right !important;
  1438. }
  1439. .light-blue {
  1440. background-color: #03a9f4 !important;
  1441. }
  1442. .white {
  1443. background-color: #ffffff !important;
  1444. }
  1445. .btn-search {
  1446. font-size: 14px;
  1447. }
  1448. .menu {
  1449. padding: 0 10px;
  1450. }
  1451. .menu-list li a:hover {
  1452. color: #000 !important;
  1453. }
  1454. .menu-list li {
  1455. display: flex;
  1456. justify-content: space-between;
  1457. }
  1458. .menu-list a {
  1459. /*padding: 0 10px !important;*/
  1460. }
  1461. .menu-list a:hover {
  1462. background-color: transparent;
  1463. }
  1464. .icons-group {
  1465. display: flex;
  1466. }
  1467. #like,
  1468. #dislike {
  1469. position: relative;
  1470. }
  1471. .behind {
  1472. z-index: -1;
  1473. }
  1474. .behind:focus {
  1475. z-index: 0;
  1476. }
  1477. .progress {
  1478. width: 50px;
  1479. animation: rotate 0.8s infinite linear;
  1480. border: 8px solid #03a9f4;
  1481. border-right-color: transparent;
  1482. height: 50px;
  1483. position: absolute;
  1484. top: 50%;
  1485. left: 50%;
  1486. }
  1487. @keyframes rotate {
  1488. 0% {
  1489. transform: rotate(0deg);
  1490. }
  1491. 100% {
  1492. transform: rotate(360deg);
  1493. }
  1494. }
  1495. .experimental {
  1496. display: none !important;
  1497. }
  1498. </style>