Station.vue 35 KB

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