Station.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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. $(".seeker-bar").width(
  589. parseFloat(
  590. (local.getTimeElapsed() /
  591. 1000 /
  592. local.currentSong.duration) *
  593. 100
  594. ) + "%"
  595. );
  596. }
  597. },
  598. formatTime: function(duration) {
  599. let d = moment.duration(duration, "seconds");
  600. if (duration < 0) return "0:00";
  601. return (
  602. (d.hours() > 0
  603. ? d.hours() < 10
  604. ? "0" + d.hours() + ":"
  605. : d.hours() + ":"
  606. : "") +
  607. (d.minutes() + ":") +
  608. (d.seconds() < 10 ? "0" + d.seconds() : d.seconds())
  609. );
  610. },
  611. calculateTimeElapsed: function() {
  612. let local = this;
  613. if (local.currentTime !== undefined && local.paused) {
  614. local.timePaused += Date.currently() - local.currentTime;
  615. local.currentTime = undefined;
  616. }
  617. let duration =
  618. (Date.currently() - local.startedAt - local.timePaused) / 1000;
  619. let songDuration = local.currentSong.duration;
  620. if (songDuration <= duration) local.player.pauseVideo();
  621. if (!local.paused && duration <= songDuration)
  622. local.timeElapsed = local.formatTime(duration);
  623. },
  624. toggleLock: function() {
  625. window.socket.emit("stations.toggleLock", this.station._id, res => {
  626. if (res.status === "success") {
  627. Toast.methods.addToast(
  628. "Successfully toggled the queue lock.",
  629. 4000
  630. );
  631. } else Toast.methods.addToast(res.message, 8000);
  632. });
  633. },
  634. changeVolume: function() {
  635. let local = this;
  636. let volume = $("#volumeSlider").val();
  637. localStorage.setItem("volume", volume / 100);
  638. if (local.playerReady) {
  639. local.player.setVolume(volume / 100);
  640. if (volume > 0) local.player.unMute();
  641. }
  642. },
  643. resumeLocalStation: function() {
  644. this.paused = false;
  645. if (!this.noSong) {
  646. if (this.playerReady) {
  647. this.player.seekTo(
  648. this.getTimeElapsed() / 1000 +
  649. this.currentSong.skipDuration
  650. );
  651. this.player.playVideo();
  652. }
  653. }
  654. },
  655. pauseLocalStation: function() {
  656. console.log("pause locally");
  657. this.paused = true;
  658. if (!this.noSong) {
  659. this.timeBeforePause = this.getTimeElapsed();
  660. if (this.playerReady) this.player.pauseVideo();
  661. }
  662. },
  663. skipStation: function() {
  664. let _this = this;
  665. _this.socket.emit("stations.forceSkip", _this.station._id, data => {
  666. if (data.status !== "success")
  667. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  668. else
  669. Toast.methods.addToast(
  670. "Successfully skipped the station's current song.",
  671. 4000
  672. );
  673. });
  674. },
  675. voteSkipStation: function() {
  676. let _this = this;
  677. _this.socket.emit("stations.voteSkip", _this.station._id, data => {
  678. if (data.status !== "success")
  679. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  680. else
  681. Toast.methods.addToast(
  682. "Successfully voted to skip the current song.",
  683. 4000
  684. );
  685. });
  686. },
  687. resumeStation: function() {
  688. let _this = this;
  689. _this.socket.emit("stations.resume", _this.station._id, data => {
  690. if (data.status !== "success")
  691. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  692. else
  693. Toast.methods.addToast(
  694. "Successfully resumed the station.",
  695. 4000
  696. );
  697. });
  698. },
  699. pauseStation: function() {
  700. let _this = this;
  701. _this.socket.emit("stations.pause", _this.station._id, data => {
  702. if (data.status !== "success")
  703. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  704. else
  705. Toast.methods.addToast(
  706. "Successfully paused the station.",
  707. 4000
  708. );
  709. });
  710. },
  711. toggleMute: function() {
  712. if (this.playerReady) {
  713. let previousVolume = parseFloat(localStorage.getItem("volume"));
  714. let volume =
  715. this.player.getVolume() * 100 <= 0 ? previousVolume : 0;
  716. this.muted = !this.muted;
  717. $("#volumeSlider").val(volume * 100);
  718. this.player.setVolume(volume);
  719. if (!this.muted) localStorage.setItem("volume", volume);
  720. }
  721. },
  722. increaseVolume: function() {
  723. if (this.playerReady) {
  724. let previousVolume = parseInt(localStorage.getItem("volume"));
  725. let volume = previousVolume + 5;
  726. if (previousVolume === 0) this.muted = false;
  727. if (volume > 100) volume = 100;
  728. $("#volumeSlider").val(volume * 100);
  729. this.player.setVolume(volume);
  730. localStorage.setItem("volume", volume);
  731. }
  732. },
  733. toggleLike: function() {
  734. let _this = this;
  735. if (_this.liked)
  736. _this.socket.emit(
  737. "songs.unlike",
  738. _this.currentSong.songId,
  739. data => {
  740. if (data.status !== "success")
  741. Toast.methods.addToast(
  742. `Error: ${data.message}`,
  743. 8000
  744. );
  745. }
  746. );
  747. else
  748. _this.socket.emit(
  749. "songs.like",
  750. _this.currentSong.songId,
  751. data => {
  752. if (data.status !== "success")
  753. Toast.methods.addToast(
  754. `Error: ${data.message}`,
  755. 8000
  756. );
  757. }
  758. );
  759. },
  760. toggleDislike: function() {
  761. let _this = this;
  762. if (_this.disliked)
  763. return _this.socket.emit(
  764. "songs.undislike",
  765. _this.currentSong.songId,
  766. data => {
  767. if (data.status !== "success")
  768. Toast.methods.addToast(
  769. `Error: ${data.message}`,
  770. 8000
  771. );
  772. }
  773. );
  774. _this.socket.emit(
  775. "songs.dislike",
  776. _this.currentSong.songId,
  777. data => {
  778. if (data.status !== "success")
  779. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  780. }
  781. );
  782. },
  783. addFirstPrivatePlaylistSongToQueue: function() {
  784. let _this = this;
  785. let isInQueue = false;
  786. let userId = _this.$parent.userId;
  787. if (_this.type === "community") {
  788. _this.songsList.forEach(queueSong => {
  789. if (queueSong.requestedBy === userId) isInQueue = true;
  790. });
  791. if (!isInQueue && _this.privatePlaylistQueueSelected) {
  792. _this.socket.emit(
  793. "playlists.getFirstSong",
  794. _this.privatePlaylistQueueSelected,
  795. data => {
  796. if (data.status === "success") {
  797. if (data.song.duration < 15 * 60) {
  798. _this.automaticallyRequestedSongId =
  799. data.song.songId;
  800. _this.socket.emit(
  801. "stations.addToQueue",
  802. _this.station._id,
  803. data.song.songId,
  804. data2 => {
  805. if (data2.status === "success") {
  806. _this.socket.emit(
  807. "playlists.moveSongToBottom",
  808. _this.privatePlaylistQueueSelected,
  809. data.song.songId,
  810. data3 => {
  811. if (
  812. data3.status ===
  813. "success"
  814. ) {} // eslint-disable-line
  815. }
  816. );
  817. }
  818. }
  819. );
  820. } else {
  821. Toast.methods.addToast(
  822. `Top song in playlist was too long to be added.`,
  823. 3000
  824. );
  825. _this.socket.emit(
  826. "playlists.moveSongToBottom",
  827. _this.privatePlaylistQueueSelected,
  828. data.song.songId,
  829. data3 => {
  830. if (data3.status === "success") {
  831. setTimeout(() => {
  832. this.addFirstPrivatePlaylistSongToQueue();
  833. }, 3000);
  834. }
  835. }
  836. );
  837. }
  838. }
  839. }
  840. );
  841. }
  842. }
  843. },
  844. join: function() {
  845. let _this = this;
  846. _this.socket.emit("stations.join", _this.stationName, res => {
  847. if (res.status === "success") {
  848. const {
  849. _id,
  850. displayName,
  851. description,
  852. privacy,
  853. locked,
  854. partyMode,
  855. owner,
  856. privatePlaylist
  857. } = res.data;
  858. _this.joinStation({
  859. _id,
  860. name: _this.stationName,
  861. displayName,
  862. description,
  863. privacy,
  864. locked,
  865. partyMode,
  866. owner,
  867. privatePlaylist
  868. });
  869. _this.currentSong = res.data.currentSong
  870. ? res.data.currentSong
  871. : {};
  872. _this.type = res.data.type;
  873. _this.startedAt = res.data.startedAt;
  874. _this.paused = res.data.paused;
  875. _this.timePaused = res.data.timePaused;
  876. _this.userCount = res.data.userCount;
  877. _this.users = res.data.users;
  878. if (res.data.currentSong) {
  879. _this.noSong = false;
  880. _this.simpleSong =
  881. res.data.currentSong.likes === -1 &&
  882. res.data.currentSong.dislikes === -1;
  883. if (_this.simpleSong) {
  884. _this.currentSong.skipDuration = 0;
  885. }
  886. _this.youtubeReady();
  887. _this.playVideo();
  888. _this.socket.emit(
  889. "songs.getOwnSongRatings",
  890. res.data.currentSong.songId,
  891. data => {
  892. if (_this.currentSong.songId === data.songId) {
  893. _this.liked = data.liked;
  894. _this.disliked = data.disliked;
  895. }
  896. }
  897. );
  898. } else {
  899. if (_this.playerReady) _this.player.pauseVideo();
  900. _this.noSong = true;
  901. }
  902. // UNIX client time before ping
  903. let beforePing = Date.now();
  904. _this.socket.emit("apis.ping", res => {
  905. // UNIX client time after ping
  906. let afterPing = Date.now();
  907. // Average time in MS it took between the server responding and the client receiving
  908. let connectionLatency = (afterPing - beforePing) / 2;
  909. console.log(connectionLatency, beforePing - afterPing);
  910. // UNIX server time
  911. let serverDate = res.date;
  912. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  913. let difference =
  914. serverDate + connectionLatency - afterPing;
  915. console.log("Difference: ", difference);
  916. if (difference > 3000 || difference < -3000) {
  917. console.log(
  918. "System time difference is bigger than 3 seconds."
  919. );
  920. }
  921. _this.systemDifference = difference;
  922. });
  923. }
  924. });
  925. },
  926. ...mapActions("modals", ["toggleModal"]),
  927. ...mapActions("station", ["joinStation"])
  928. },
  929. mounted: function() {
  930. let _this = this;
  931. Date.currently = () => {
  932. return new Date().getTime() + _this.systemDifference;
  933. };
  934. _this.stationName = _this.$route.params.id;
  935. window.stationInterval = 0;
  936. io.getSocket(socket => {
  937. _this.socket = socket;
  938. io.removeAllListeners();
  939. if (_this.socket.connected) _this.join();
  940. io.onConnect(_this.join);
  941. _this.socket.emit("stations.findByName", _this.stationName, res => {
  942. if (res.status === "error") {
  943. _this.$router.go("/404");
  944. Toast.methods.addToast(res.message, 3000);
  945. } else {
  946. _this.ready = true;
  947. }
  948. });
  949. _this.socket.on("event:songs.next", data => {
  950. _this.previousSong = _this.currentSong.songId
  951. ? _this.currentSong
  952. : null;
  953. _this.currentSong = data.currentSong ? data.currentSong : {};
  954. _this.startedAt = data.startedAt;
  955. _this.paused = data.paused;
  956. _this.timePaused = data.timePaused;
  957. if (data.currentSong) {
  958. _this.noSong = false;
  959. _this.simpleSong =
  960. data.currentSong.likes === -1 &&
  961. data.currentSong.dislikes === -1;
  962. if (_this.simpleSong) _this.currentSong.skipDuration = 0;
  963. if (!_this.playerReady) _this.youtubeReady();
  964. else _this.playVideo();
  965. _this.socket.emit(
  966. "songs.getOwnSongRatings",
  967. data.currentSong.songId,
  968. data => {
  969. if (_this.currentSong.songId === data.songId) {
  970. _this.liked = data.liked;
  971. _this.disliked = data.disliked;
  972. }
  973. }
  974. );
  975. } else {
  976. if (_this.playerReady) _this.player.pauseVideo();
  977. _this.noSong = true;
  978. }
  979. let isInQueue = false;
  980. let userId = _this.$parent.userId;
  981. _this.songsList.forEach(queueSong => {
  982. if (queueSong.requestedBy === userId) isInQueue = true;
  983. });
  984. if (
  985. !isInQueue &&
  986. _this.privatePlaylistQueueSelected &&
  987. (_this.automaticallyRequestedSongId !==
  988. _this.currentSong.songId ||
  989. !_this.currentSong.songId)
  990. ) {
  991. _this.addFirstPrivatePlaylistSongToQueue();
  992. }
  993. });
  994. _this.socket.on("event:stations.pause", () => {
  995. _this.pauseLocalStation();
  996. console.log("local pause");
  997. });
  998. _this.socket.on("event:stations.resume", data => {
  999. _this.timePaused = data.timePaused;
  1000. _this.resumeLocalStation();
  1001. });
  1002. _this.socket.on(
  1003. "event:stations.remove",
  1004. () => (location.href = "/")
  1005. );
  1006. _this.socket.on("event:song.like", data => {
  1007. if (!this.noSong) {
  1008. if (data.songId === _this.currentSong.songId) {
  1009. _this.currentSong.dislikes = data.dislikes;
  1010. _this.currentSong.likes = data.likes;
  1011. }
  1012. }
  1013. });
  1014. _this.socket.on("event:song.dislike", data => {
  1015. if (!this.noSong) {
  1016. if (data.songId === _this.currentSong.songId) {
  1017. _this.currentSong.dislikes = data.dislikes;
  1018. _this.currentSong.likes = data.likes;
  1019. }
  1020. }
  1021. });
  1022. _this.socket.on("event:song.unlike", data => {
  1023. if (!this.noSong) {
  1024. if (data.songId === _this.currentSong.songId) {
  1025. _this.currentSong.dislikes = data.dislikes;
  1026. _this.currentSong.likes = data.likes;
  1027. }
  1028. }
  1029. });
  1030. _this.socket.on("event:song.undislike", data => {
  1031. if (!this.noSong) {
  1032. if (data.songId === _this.currentSong.songId) {
  1033. _this.currentSong.dislikes = data.dislikes;
  1034. _this.currentSong.likes = data.likes;
  1035. }
  1036. }
  1037. });
  1038. _this.socket.on("event:song.newRatings", data => {
  1039. if (!this.noSong) {
  1040. if (data.songId === _this.currentSong.songId) {
  1041. _this.liked = data.liked;
  1042. _this.disliked = data.disliked;
  1043. }
  1044. }
  1045. });
  1046. _this.socket.on("event:queue.update", queue => {
  1047. if (this.type === "community") this.songsList = queue;
  1048. });
  1049. _this.socket.on("event:song.voteSkipSong", () => {
  1050. if (this.currentSong) this.currentSong.skipVotes++;
  1051. });
  1052. _this.socket.on("event:privatePlaylist.selected", playlistId => {
  1053. if (this.type === "community") {
  1054. this.station.privatePlaylist = playlistId;
  1055. }
  1056. });
  1057. _this.socket.on("event:partyMode.updated", partyMode => {
  1058. if (this.type === "community") {
  1059. this.station.partyMode = partyMode;
  1060. }
  1061. });
  1062. _this.socket.on("event:newOfficialPlaylist", playlist => {
  1063. if (this.type === "official") {
  1064. this.songsList = playlist;
  1065. }
  1066. });
  1067. _this.socket.on("event:users.updated", users => {
  1068. _this.users = users;
  1069. });
  1070. _this.socket.on("event:userCount.updated", userCount => {
  1071. _this.userCount = userCount;
  1072. });
  1073. _this.socket.on("event:queueLockToggled", locked => {
  1074. _this.station.locked = locked;
  1075. });
  1076. });
  1077. let volume = parseFloat(localStorage.getItem("volume"));
  1078. volume = typeof volume === "number" && !isNaN(volume) ? volume : 20;
  1079. localStorage.setItem("volume", volume);
  1080. $("#volumeSlider").val(volume * 100);
  1081. },
  1082. components: {
  1083. OfficialHeader,
  1084. CommunityHeader,
  1085. SongQueue,
  1086. AddToPlaylist,
  1087. EditPlaylist,
  1088. CreatePlaylist,
  1089. EditStation,
  1090. Report,
  1091. SongsListSidebar,
  1092. PlaylistSidebar,
  1093. UsersSidebar
  1094. }
  1095. };
  1096. </script>
  1097. <style lang="scss">
  1098. .no-song {
  1099. color: #03a9f4;
  1100. text-align: center;
  1101. }
  1102. #volumeSlider {
  1103. padding: 0 15px;
  1104. background: transparent;
  1105. }
  1106. .volume-slider-wrapper {
  1107. margin-top: 0;
  1108. position: relative;
  1109. display: flex;
  1110. align-items: center;
  1111. .material-icons {
  1112. user-select: none;
  1113. }
  1114. }
  1115. .material-icons {
  1116. cursor: pointer;
  1117. }
  1118. .stationDisplayName {
  1119. color: white !important;
  1120. }
  1121. .add-to-playlist {
  1122. display: flex;
  1123. align-items: center;
  1124. justify-content: center;
  1125. }
  1126. .slideout {
  1127. top: 50px;
  1128. height: 100%;
  1129. position: fixed;
  1130. right: 0;
  1131. width: 350px;
  1132. background-color: white;
  1133. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16),
  1134. 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  1135. .slideout-header {
  1136. text-align: center;
  1137. background-color: rgb(3, 169, 244) !important;
  1138. margin: 0;
  1139. padding-top: 5px;
  1140. padding-bottom: 7px;
  1141. color: white;
  1142. }
  1143. .slideout-content {
  1144. height: 100%;
  1145. }
  1146. }
  1147. .modal-large {
  1148. width: 75%;
  1149. }
  1150. .station {
  1151. flex: 1 0 auto;
  1152. padding-top: 0.5vw;
  1153. transition: all 0.1s;
  1154. margin: 0 auto;
  1155. max-width: 100%;
  1156. width: 90%;
  1157. @media only screen and (min-width: 993px) {
  1158. width: 70%;
  1159. }
  1160. @media only screen and (min-width: 601px) {
  1161. width: 85%;
  1162. }
  1163. @media (min-width: 999px) {
  1164. .mobile-only {
  1165. display: none;
  1166. }
  1167. .desktop-only {
  1168. display: block;
  1169. }
  1170. }
  1171. @media (max-width: 998px) {
  1172. .mobile-only {
  1173. display: block;
  1174. }
  1175. .desktop-only {
  1176. display: none;
  1177. visibility: hidden;
  1178. }
  1179. }
  1180. .mobile-only {
  1181. text-align: center;
  1182. }
  1183. .playlistCard {
  1184. margin: 10px;
  1185. position: relative;
  1186. padding-bottom: calc(31.25% + 7px);
  1187. height: 0;
  1188. overflow-y: scroll;
  1189. .title {
  1190. background-color: rgb(3, 169, 244);
  1191. text-align: center;
  1192. padding: 10px;
  1193. color: white;
  1194. font-weight: 600;
  1195. }
  1196. .media {
  1197. padding: 0 25px;
  1198. }
  1199. .media-content .content {
  1200. min-height: 64px;
  1201. max-height: 64px;
  1202. display: flex;
  1203. align-items: center;
  1204. }
  1205. .content p strong {
  1206. word-break: break-word;
  1207. }
  1208. .content p small {
  1209. word-break: break-word;
  1210. }
  1211. .add-to-queue {
  1212. width: 100%;
  1213. margin-top: 25px;
  1214. height: 40px;
  1215. border-radius: 0;
  1216. background: rgb(3, 169, 244);
  1217. color: #fff !important;
  1218. border: 0;
  1219. &:active,
  1220. &:focus {
  1221. border: 0;
  1222. }
  1223. }
  1224. .add-to-queue:focus {
  1225. background: #029ce3;
  1226. }
  1227. .media-right {
  1228. line-height: 64px;
  1229. }
  1230. .songTitle {
  1231. word-wrap: break-word;
  1232. overflow: hidden;
  1233. text-overflow: ellipsis;
  1234. display: -webkit-box;
  1235. -webkit-box-orient: vertical;
  1236. -webkit-line-clamp: 2;
  1237. line-height: 20px;
  1238. max-height: 40px;
  1239. width: 100%;
  1240. }
  1241. }
  1242. input[type="range"] {
  1243. -webkit-appearance: none;
  1244. width: 100%;
  1245. margin: 7.3px 0;
  1246. }
  1247. input[type="range"]:focus {
  1248. outline: none;
  1249. }
  1250. input[type="range"]::-webkit-slider-runnable-track {
  1251. width: 100%;
  1252. height: 5.2px;
  1253. cursor: pointer;
  1254. box-shadow: 0;
  1255. background: #c2c0c2;
  1256. border-radius: 0;
  1257. border: 0;
  1258. }
  1259. input[type="range"]::-webkit-slider-thumb {
  1260. box-shadow: 0;
  1261. border: 0;
  1262. height: 19px;
  1263. width: 19px;
  1264. border-radius: 15px;
  1265. background: #03a9f4;
  1266. cursor: pointer;
  1267. -webkit-appearance: none;
  1268. margin-top: -6.5px;
  1269. }
  1270. input[type="range"]::-moz-range-track {
  1271. width: 100%;
  1272. height: 5.2px;
  1273. cursor: pointer;
  1274. box-shadow: 0;
  1275. background: #c2c0c2;
  1276. border-radius: 0;
  1277. border: 0;
  1278. }
  1279. input[type="range"]::-moz-range-thumb {
  1280. box-shadow: 0;
  1281. border: 0;
  1282. height: 19px;
  1283. width: 19px;
  1284. border-radius: 15px;
  1285. background: #03a9f4;
  1286. cursor: pointer;
  1287. -webkit-appearance: none;
  1288. margin-top: -6.5px;
  1289. }
  1290. input[type="range"]::-ms-track {
  1291. width: 100%;
  1292. height: 5.2px;
  1293. cursor: pointer;
  1294. box-shadow: 0;
  1295. background: #c2c0c2;
  1296. border-radius: 1.3px;
  1297. }
  1298. input[type="range"]::-ms-fill-lower {
  1299. background: #c2c0c2;
  1300. border: 0;
  1301. border-radius: 0;
  1302. box-shadow: 0;
  1303. }
  1304. input[type="range"]::-ms-fill-upper {
  1305. background: #c2c0c2;
  1306. border: 0;
  1307. border-radius: 0;
  1308. box-shadow: 0;
  1309. }
  1310. input[type="range"]::-ms-thumb {
  1311. box-shadow: 0;
  1312. border: 0;
  1313. height: 15px;
  1314. width: 15px;
  1315. border-radius: 15px;
  1316. background: #03a9f4;
  1317. cursor: pointer;
  1318. -webkit-appearance: none;
  1319. margin-top: 1.5px;
  1320. }
  1321. .video-container {
  1322. position: relative;
  1323. padding-bottom: 56.25%;
  1324. height: 0;
  1325. overflow: hidden;
  1326. iframe {
  1327. position: absolute;
  1328. top: 0;
  1329. left: 0;
  1330. width: 100%;
  1331. height: 100%;
  1332. }
  1333. }
  1334. .video-col {
  1335. padding-right: 0.75rem;
  1336. padding-left: 0.75rem;
  1337. }
  1338. }
  1339. .room-title {
  1340. left: 50%;
  1341. -webkit-transform: translateX(-50%);
  1342. transform: translateX(-50%);
  1343. font-size: 2.1em;
  1344. }
  1345. #ratings {
  1346. span {
  1347. font-size: 1.68rem;
  1348. }
  1349. i {
  1350. color: #9e9e9e !important;
  1351. cursor: pointer;
  1352. transition: 0.1s color;
  1353. }
  1354. }
  1355. #time-display {
  1356. margin-top: 30px;
  1357. float: right;
  1358. }
  1359. #thumbs_up:hover,
  1360. #thumbs_up.liked {
  1361. color: #87d37c !important;
  1362. }
  1363. #thumbs_down:hover,
  1364. #thumbs_down.disliked {
  1365. color: #ec644b !important;
  1366. }
  1367. #song-thumbnail {
  1368. max-width: 100%;
  1369. width: 85%;
  1370. }
  1371. .seeker-bar-container {
  1372. position: relative;
  1373. height: 7px;
  1374. display: block;
  1375. width: 100%;
  1376. overflow: hidden;
  1377. }
  1378. .seeker-bar {
  1379. top: 0;
  1380. left: 0;
  1381. bottom: 0;
  1382. position: absolute;
  1383. }
  1384. ul {
  1385. list-style: none;
  1386. margin: 0;
  1387. display: block;
  1388. }
  1389. h1,
  1390. h2,
  1391. h3,
  1392. h4,
  1393. h5,
  1394. h6 {
  1395. font-weight: 400;
  1396. line-height: 1.1;
  1397. }
  1398. h1 a,
  1399. h2 a,
  1400. h3 a,
  1401. h4 a,
  1402. h5 a,
  1403. h6 a {
  1404. font-weight: inherit;
  1405. }
  1406. h1 {
  1407. font-size: 4.2rem;
  1408. line-height: 110%;
  1409. margin: 2.1rem 0 1.68rem 0;
  1410. }
  1411. h2 {
  1412. font-size: 3.56rem;
  1413. line-height: 110%;
  1414. margin: 1.78rem 0 1.424rem 0;
  1415. }
  1416. h3 {
  1417. font-size: 2.92rem;
  1418. line-height: 110%;
  1419. margin: 1.46rem 0 1.168rem 0;
  1420. }
  1421. h4 {
  1422. font-size: 2.28rem;
  1423. line-height: 110%;
  1424. margin: 1.14rem 0 0.912rem 0;
  1425. }
  1426. h5 {
  1427. font-size: 1.64rem;
  1428. line-height: 110%;
  1429. margin: 0.82rem 0 0.656rem 0;
  1430. }
  1431. h6 {
  1432. font-size: 1rem;
  1433. line-height: 110%;
  1434. margin: 0.5rem 0 0.4rem 0;
  1435. }
  1436. .thin {
  1437. font-weight: 200;
  1438. }
  1439. .left {
  1440. float: left !important;
  1441. }
  1442. .right {
  1443. float: right !important;
  1444. }
  1445. .light-blue {
  1446. background-color: #03a9f4 !important;
  1447. }
  1448. .white {
  1449. background-color: #ffffff !important;
  1450. }
  1451. .btn-search {
  1452. font-size: 14px;
  1453. }
  1454. .menu {
  1455. padding: 0 10px;
  1456. }
  1457. .menu-list li a:hover {
  1458. color: #000 !important;
  1459. }
  1460. .menu-list li {
  1461. display: flex;
  1462. justify-content: space-between;
  1463. }
  1464. .menu-list a {
  1465. /*padding: 0 10px !important;*/
  1466. }
  1467. .menu-list a:hover {
  1468. background-color: transparent;
  1469. }
  1470. .icons-group {
  1471. display: flex;
  1472. }
  1473. #like,
  1474. #dislike {
  1475. position: relative;
  1476. }
  1477. .behind {
  1478. z-index: -1;
  1479. }
  1480. .behind:focus {
  1481. z-index: 0;
  1482. }
  1483. .progress {
  1484. width: 50px;
  1485. animation: rotate 0.8s infinite linear;
  1486. border: 8px solid #03a9f4;
  1487. border-right-color: transparent;
  1488. height: 50px;
  1489. position: absolute;
  1490. top: 50%;
  1491. left: 50%;
  1492. }
  1493. @keyframes rotate {
  1494. 0% {
  1495. transform: rotate(0deg);
  1496. }
  1497. 100% {
  1498. transform: rotate(360deg);
  1499. }
  1500. }
  1501. .experimental {
  1502. display: none !important;
  1503. }
  1504. </style>