Station.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. <template>
  2. <official-header v-if='type == "official"'></official-header>
  3. <community-header v-if='type == "community"'></community-header>
  4. <song-queue v-if='modals.addSongToQueue'></song-queue>
  5. <edit-playlist v-if='modals.editPlaylist'></edit-playlist>
  6. <create-playlist v-if='modals.createPlaylist'></create-playlist>
  7. <queue-sidebar v-if='sidebars.queue'></queue-sidebar>
  8. <playlist-sidebar v-if='sidebars.playlist'></playlist-sidebar>
  9. <users-sidebar v-if='sidebars.users'></users-sidebar>
  10. <div class="station">
  11. <h1 v-show="noSong" class="noSong">No song is currently playing.</h1>
  12. <div class="columns is-mobile" v-show="!noSong">
  13. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  14. <div class="video-container">
  15. <div id="player"></div>
  16. <div class="seeker-bar-container white" id="preview-progress">
  17. <div class="seeker-bar light-blue" style="width: 0%;"></div>
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="columns is-mobile" v-show="!noSong">
  23. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  24. <div class="columns is-mobile">
  25. <div class="column is-12-mobile" v-bind:class="{'is-8-desktop': !simpleSong}">
  26. <h4 id="time-display">{{timeElapsed}} / {{formatTime(currentSong.duration)}}</h4>
  27. <h3>{{currentSong.title}}</h3>
  28. <h4 class="thin" style="margin-left: 0">{{currentSong.artists}}</h4>
  29. <div class="columns is-mobile">
  30. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="column is-7-desktop is-4-mobile">
  31. <p style="margin-top: 0; position: relative;">
  32. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  33. </p>
  34. </form>
  35. <div class="column is-8-mobile is-5-desktop" style="float: right;">
  36. <ul id="ratings" v-if="currentSong.likes !== -1 && currentSong.dislikes !== -1">
  37. <li id="like" class="right" @click="toggleLike()">
  38. <span class="flow-text">{{currentSong.likes}} </span>
  39. <i id="thumbs_up" class="material-icons grey-text" v-bind:class="{liked: liked}">thumb_up</i>
  40. </li>
  41. <li style="margin-right: 10px;" id="dislike" class="right" @click="toggleDislike()">
  42. <span class="flow-text">{{currentSong.dislikes}} </span>
  43. <i id="thumbs_down" class="material-icons grey-text" v-bind:class="{disliked: disliked}">thumb_down</i>
  44. </li>
  45. </ul>
  46. </div>
  47. </div>
  48. </div>
  49. <div class="column is-4-desktop is-12-mobile" v-if="!simpleSong">
  50. <img class="image" id="song-thumbnail" style="margin-top: 10px !important" :src="currentSong.thumbnail" alt="Song Thumbnail" />
  51. </div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. </template>
  57. <script>
  58. import { Toast } from 'vue-roaster';
  59. import SongQueue from '../Modals/AddSongToQueue.vue';
  60. import EditPlaylist from '../Modals/Playlists/Edit.vue';
  61. import CreatePlaylist from '../Modals/Playlists/Create.vue';
  62. import QueueSidebar from '../Sidebars/Queue.vue';
  63. import PlaylistSidebar from '../Sidebars/Playlist.vue';
  64. import UsersSidebar from '../Sidebars/UsersList.vue';
  65. import OfficialHeader from './OfficialHeader.vue';
  66. import CommunityHeader from './CommunityHeader.vue';
  67. export default {
  68. data() {
  69. return {
  70. type: '',
  71. playerReady: false,
  72. currentSong: {},
  73. player: undefined,
  74. timePaused: 0,
  75. paused: false,
  76. timeElapsed: "0:00",
  77. interval: 0,
  78. liked: false,
  79. disliked: false,
  80. modals: {
  81. addSongToQueue: false,
  82. editPlaylist: false,
  83. createPlaylist: false
  84. },
  85. sidebars: {
  86. queue: false,
  87. users: false,
  88. playlist: false
  89. },
  90. noSong: false,
  91. simpleSong: false,
  92. queue: [],
  93. timeBeforePause: 0
  94. }
  95. },
  96. methods: {
  97. editPlaylist: function (id) {
  98. this.playlistBeingEdited = id;
  99. this.toggleModal('editPlaylist');
  100. },
  101. toggleModal: function (type) {
  102. if (type == 'addSongToQueue') this.modals.addSongToQueue = !this.modals.addSongToQueue;
  103. else if (type == 'editPlaylist') this.modals.editPlaylist = !this.modals.editPlaylist;
  104. else if (type == 'createPlaylist') this.modals.createPlaylist = !this.modals.createPlaylist;
  105. },
  106. youtubeReady: function() {
  107. let local = this;
  108. console.log("@@5", local.currentSong._id);
  109. if (!local.player) {
  110. local.player = new YT.Player("player", {
  111. height: 270,
  112. width: 480,
  113. videoId: local.currentSong._id,
  114. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  115. events: {
  116. 'onReady': function (event) {
  117. console.log("@@6");
  118. local.playerReady = true;
  119. let volume = parseInt(localStorage.getItem("volume"));
  120. volume = (typeof volume === "number") ? volume : 20;
  121. local.player.setVolume(volume);
  122. if (volume > 0) local.player.unMute();
  123. console.log("@@7");
  124. local.playVideo();
  125. },
  126. 'onStateChange': function (event) {
  127. if (event.data === 1 && local.videoLoading === true) {
  128. local.videoLoading = false;
  129. local.player.seekTo(local.getTimeElapsed() / 1000, true);
  130. if (local.paused) local.player.pauseVideo();
  131. } else if (event.data === 1 && local.paused) {
  132. local.player.seekTo(local.timeBeforePause / 1000, true);
  133. local.player.pauseVideo();
  134. }
  135. if (event.data === 2 && !local.paused) {
  136. local.player.seekTo(local.getTimeElapsed() / 1000, true);
  137. local.player.playVideo();
  138. }
  139. }
  140. }
  141. });
  142. }
  143. },
  144. getTimeElapsed: function() {
  145. let local = this;
  146. if (local.currentSong) {
  147. return Date.now() - local.startedAt - local.timePaused;
  148. } else {
  149. return 0;
  150. }
  151. },
  152. playVideo: function() {
  153. let local = this;
  154. console.log("@@9");
  155. if (local.playerReady) {
  156. console.log("@@@1");
  157. local.videoLoading = true;
  158. local.player.loadVideoById(local.currentSong._id);
  159. if (local.currentSong.artists) local.currentSong.artists = local.currentSong.artists.join(", ");
  160. if (local.interval !== 0) clearInterval(local.interval);
  161. local.interval = setInterval(function () {
  162. local.resizeSeekerbar();
  163. local.calculateTimeElapsed();
  164. }, 250);
  165. }
  166. },
  167. resizeSeekerbar: function() {
  168. let local = this;
  169. if (!local.paused) {
  170. $(".seeker-bar").width(parseInt(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100)) + "%");
  171. }
  172. },
  173. formatTime: function(duration) {
  174. let d = moment.duration(duration, 'seconds');
  175. return ((d.hours() > 0) ? (d.hours() < 10 ? ("0" + d.hours() + ":") : (d.hours() + ":")) : "") + (d.minutes() + ":") + (d.seconds() < 10 ? ("0" + d.seconds()) : d.seconds());
  176. },
  177. calculateTimeElapsed: function() {
  178. let local = this;
  179. let currentTime = Date.now();
  180. if (local.currentTime !== undefined && local.paused) {
  181. console.log("123");
  182. local.timePaused += (Date.now() - local.currentTime);
  183. local.currentTime = undefined;
  184. }
  185. let duration = (Date.now() - local.startedAt - local.timePaused) / 1000;
  186. let songDuration = local.currentSong.duration;
  187. //console.log(duration, currentTime, local.startedAt, local.timePaused, local.startedAt - local.timePaused, Date.now() - local.startedAt - local.timePaused, Date.now() - local.startedAt);
  188. if (songDuration <= duration) local.player.pauseVideo();
  189. if ((!local.paused) && duration <= songDuration) local.timeElapsed = local.formatTime(duration);
  190. },
  191. changeVolume: function() {
  192. let local = this;
  193. let volume = $("#volumeSlider").val();
  194. localStorage.setItem("volume", volume);
  195. if (local.playerReady) {
  196. local.player.setVolume(volume);
  197. if (volume > 0) local.player.unMute();
  198. }
  199. },
  200. resumeLocalStation: function() {
  201. this.paused = false;
  202. if (!this.noSong) {
  203. if (this.playerReady) {
  204. this.player.seekTo(this.getTimeElapsed() / 1000);
  205. this.player.playVideo();
  206. }
  207. }
  208. },
  209. pauseLocalStation: function() {
  210. this.paused = true;
  211. if (!this.noSong) {
  212. this.timeBeforePause = this.getTimeElapsed();
  213. if (this.playerReady) this.player.pauseVideo();
  214. }
  215. },
  216. skipStation: function () {
  217. let _this = this;
  218. _this.socket.emit('stations.forceSkip', _this.stationId, data => {
  219. if (data.status !== 'success') {
  220. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  221. } else {
  222. Toast.methods.addToast('Successfully skipped the station\'s current song.', 4000);
  223. }
  224. });
  225. },
  226. resumeStation: function () {
  227. let _this = this;
  228. _this.socket.emit('stations.resume', _this.stationId, data => {
  229. console.log(data);
  230. if (data.status !== 'success') {
  231. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  232. } else {
  233. Toast.methods.addToast('Successfully resumed the station.', 4000);
  234. }
  235. });
  236. },
  237. pauseStation: function () {
  238. let _this = this;
  239. _this.socket.emit('stations.pause', _this.stationId, data => {
  240. console.log(data);
  241. if (data.status !== 'success') {
  242. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  243. } else {
  244. Toast.methods.addToast('Successfully paused the station.', 4000);
  245. }
  246. });
  247. },
  248. toggleLike: function() {
  249. let _this = this;
  250. if (_this.liked) _this.socket.emit('songs.unlike', _this.currentSong._id, data => {
  251. if (data.status !== 'success') {
  252. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  253. }
  254. }); else _this.socket.emit('songs.like', _this.currentSong._id, data => {
  255. if (data.status !== 'success') {
  256. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  257. }
  258. });
  259. },
  260. toggleDislike: function() {
  261. let _this = this;
  262. if (_this.disliked) return _this.socket.emit('songs.undislike', _this.currentSong._id, data => {
  263. if (data.status !== 'success') {
  264. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  265. }
  266. });
  267. _this.socket.emit('songs.dislike', _this.currentSong._id, data => {
  268. if (data.status !== 'success') {
  269. Toast.methods.addToast(`Error: ${data.message}`, 8000);
  270. }
  271. });
  272. }
  273. },
  274. ready: function() {
  275. let _this = this;
  276. _this.stationId = _this.$route.params.id;
  277. _this.interval = 0;
  278. let socketInterval = setInterval(() => {
  279. if (!!_this.$parent.socket) {
  280. _this.socket = _this.$parent.socket;
  281. _this.socket.emit('stations.join', _this.stationId, res => {
  282. if (res.status === "success") {
  283. _this.currentSong = (res.data.currentSong) ? res.data.currentSong : {};
  284. _this.type = res.data.type;
  285. _this.startedAt = res.data.startedAt;
  286. _this.paused = res.data.paused;
  287. _this.timePaused = res.data.timePaused;
  288. if (res.data.currentSong) {
  289. _this.noSong = false;
  290. _this.simpleSong = (res.data.currentSong.likes === -1 && res.data.currentSong.dislikes === -1);
  291. _this.youtubeReady();
  292. _this.playVideo();
  293. _this.socket.emit('songs.getOwnSongRatings', res.data.currentSong._id, data => {
  294. if (_this.currentSong._id === data.songId) {
  295. _this.liked = data.liked;
  296. _this.disliked = data.disliked;
  297. }
  298. });
  299. } else {
  300. if (_this.playerReady) _this.player.pauseVideo();
  301. console.log("NO SONG TRUE1", res);
  302. _this.noSong = true;
  303. }
  304. if (_this.type === 'community') {
  305. _this.socket.emit('stations.getQueue', _this.stationId, data => {
  306. console.log(data);
  307. if (data.status === 'success') {
  308. _this.queue = data.queue;
  309. }
  310. });
  311. }
  312. } else {
  313. //TODO Handle error
  314. }
  315. });
  316. _this.socket.on('event:songs.next', data => {
  317. _this.currentSong = (data.currentSong) ? data.currentSong : {};
  318. _this.startedAt = data.startedAt;
  319. _this.paused = data.paused;
  320. _this.timePaused = data.timePaused;
  321. if (data.currentSong) {
  322. _this.noSong = false;
  323. _this.simpleSong = (data.currentSong.likes === -1 && data.currentSong.dislikes === -1);
  324. if (!_this.playerReady) _this.youtubeReady();
  325. else _this.playVideo();
  326. _this.socket.emit('songs.getOwnSongRatings', data.currentSong._id, (data) => {
  327. if (_this.currentSong._id === data.songId) {
  328. _this.liked = data.liked;
  329. _this.disliked = data.disliked;
  330. }
  331. });
  332. } else {
  333. if (_this.playerReady) _this.player.pauseVideo();
  334. console.log("NO SONG TRUE2", data);
  335. _this.noSong = true;
  336. }
  337. });
  338. _this.socket.on('event:stations.pause', data => {
  339. _this.pauseLocalStation();
  340. });
  341. _this.socket.on('event:stations.resume', data => {
  342. _this.timePaused = data.timePaused;
  343. _this.resumeLocalStation();
  344. });
  345. _this.socket.on('event:song.like', data => {
  346. if (!this.noSong) {
  347. if (data.songId === _this.currentSong._id) {
  348. _this.currentSong.likes++;
  349. if (data.undisliked) _this.currentSong.dislikes--;
  350. }
  351. }
  352. });
  353. _this.socket.on('event:song.dislike', data => {
  354. if (!this.noSong) {
  355. if (data.songId === _this.currentSong._id) {
  356. _this.currentSong.dislikes++;
  357. if (data.unliked) _this.currentSong.likes--;
  358. }
  359. }
  360. });
  361. _this.socket.on('event:song.unlike', data => {
  362. if (!this.noSong) {
  363. if (data.songId === _this.currentSong._id) _this.currentSong.likes--;
  364. }
  365. });
  366. _this.socket.on('event:song.undislike', data => {
  367. if (!this.noSong) {
  368. if (data.songId === _this.currentSong._id) _this.currentSong.dislikes--;
  369. }
  370. });
  371. _this.socket.on('event:song.newRatings', data => {
  372. if (!this.noSong) {
  373. if (data.songId === _this.currentSong._id) {
  374. _this.liked = data.liked;
  375. _this.disliked = data.disliked;
  376. }
  377. }
  378. });
  379. _this.socket.on('event:queue.update', queue => {
  380. if (this.type === 'community') {
  381. this.queue = queue;
  382. }
  383. });
  384. clearInterval(socketInterval);
  385. }
  386. }, 100);
  387. let volume = parseInt(localStorage.getItem("volume"));
  388. volume = (typeof volume === "number") ? volume : 20;
  389. $("#volumeSlider").val(volume);
  390. },
  391. components: { OfficialHeader, CommunityHeader, SongQueue, EditPlaylist, CreatePlaylist, QueueSidebar, PlaylistSidebar, UsersSidebar }
  392. }
  393. </script>
  394. <style lang="scss">
  395. .noSong {
  396. color: #03A9F4;
  397. text-align: center;
  398. }
  399. .slideout {
  400. top: 50px;
  401. height: 100%;
  402. position: fixed;
  403. right: 0;
  404. width: 350px;
  405. background-color: white;
  406. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  407. .slideout-header {
  408. text-align: center;
  409. background-color: rgb(3, 169, 244) !important;
  410. margin: 0;
  411. padding-top: 5px;
  412. padding-bottom: 7px;
  413. color: white;
  414. }
  415. .slideout-content {
  416. height: 100%;
  417. }
  418. }
  419. .modal-large {
  420. width: 75%;
  421. }
  422. .station {
  423. flex: 1 0 auto;
  424. padding-top: 0.5vw;
  425. transition: all 0.1s;
  426. margin: 0 auto;
  427. max-width: 1280px;
  428. width: 90%;
  429. @media only screen and (min-width: 993px) {
  430. width: 70%;
  431. }
  432. @media only screen and (min-width: 601px) {
  433. width: 85%;
  434. }
  435. input[type=range] {
  436. -webkit-appearance: none;
  437. width: 100%;
  438. margin: 7.3px 0;
  439. }
  440. input[type=range]:focus {
  441. outline: none;
  442. }
  443. input[type=range]::-webkit-slider-runnable-track {
  444. width: 100%;
  445. height: 5.2px;
  446. cursor: pointer;
  447. box-shadow: 0;
  448. background: #c2c0c2;
  449. border-radius: 0;
  450. border: 0;
  451. }
  452. input[type=range]::-webkit-slider-thumb {
  453. box-shadow: 0;
  454. border: 0;
  455. height: 19px;
  456. width: 19px;
  457. border-radius: 15px;
  458. background: #03a9f4;
  459. cursor: pointer;
  460. -webkit-appearance: none;
  461. margin-top: -6.5px;
  462. }
  463. input[type=range]::-moz-range-track {
  464. width: 100%;
  465. height: 5.2px;
  466. cursor: pointer;
  467. box-shadow: 0;
  468. background: #c2c0c2;
  469. border-radius: 0;
  470. border: 0;
  471. }
  472. input[type=range]::-moz-range-thumb {
  473. box-shadow: 0;
  474. border: 0;
  475. height: 19px;
  476. width: 19px;
  477. border-radius: 15px;
  478. background: #03a9f4;
  479. cursor: pointer;
  480. -webkit-appearance: none;
  481. margin-top: -6.5px;
  482. }
  483. input[type=range]::-ms-track {
  484. width: 100%;
  485. height: 5.2px;
  486. cursor: pointer;
  487. box-shadow: 0;
  488. background: #c2c0c2;
  489. border-radius: 1.3px;
  490. }
  491. input[type=range]::-ms-fill-lower {
  492. background: #c2c0c2;
  493. border: 0;
  494. border-radius: 0;
  495. box-shadow: 0;
  496. }
  497. input[type=range]::-ms-fill-upper {
  498. background: #c2c0c2;
  499. border: 0;
  500. border-radius: 0;
  501. box-shadow: 0;
  502. }
  503. input[type=range]::-ms-thumb {
  504. box-shadow: 0;
  505. border: 0;
  506. height: 15px;
  507. width: 15px;
  508. border-radius: 15px;
  509. background: #03a9f4;
  510. cursor: pointer;
  511. -webkit-appearance: none;
  512. margin-top: 1.5px;
  513. }
  514. .video-container {
  515. position: relative;
  516. padding-bottom: 56.25%;
  517. height: 0;
  518. overflow: hidden;
  519. iframe {
  520. position: absolute;
  521. top: 0;
  522. left: 0;
  523. width: 100%;
  524. height: 100%;
  525. }
  526. }
  527. .video-col {
  528. padding-right: 0.75rem;
  529. padding-left: 0.75rem;
  530. }
  531. }
  532. .room-title {
  533. left: 50%;
  534. -webkit-transform: translateX(-50%);
  535. transform: translateX(-50%);
  536. font-size: 2.1em;
  537. }
  538. #ratings {
  539. span {
  540. font-size: 1.68rem;
  541. }
  542. i {
  543. color: #9e9e9e !important;
  544. cursor: pointer;
  545. transition: 0.1s color;
  546. }
  547. }
  548. #time-display {
  549. margin-top: 30px;
  550. float: right;
  551. }
  552. #thumbs_up:hover, #thumbs_up.liked {
  553. color: #87D37C !important;
  554. }
  555. #thumbs_down:hover, #thumbs_down.disliked {
  556. color: #EC644B !important;
  557. }
  558. #song-thumbnail {
  559. max-width: 100%;
  560. width: 85%;
  561. }
  562. .seeker-bar-container {
  563. position: relative;
  564. height: 5px;
  565. display: block;
  566. width: 100%;
  567. overflow: hidden;
  568. }
  569. .seeker-bar {
  570. top: 0;
  571. left: 0;
  572. bottom: 0;
  573. position: absolute;
  574. }
  575. ul {
  576. list-style: none;
  577. margin: 0;
  578. display: block;
  579. }
  580. h1, h2, h3, h4, h5, h6 {
  581. font-weight: 400;
  582. line-height: 1.1;
  583. }
  584. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  585. font-weight: inherit;
  586. }
  587. h1 {
  588. font-size: 4.2rem;
  589. line-height: 110%;
  590. margin: 2.1rem 0 1.68rem 0;
  591. }
  592. h2 {
  593. font-size: 3.56rem;
  594. line-height: 110%;
  595. margin: 1.78rem 0 1.424rem 0;
  596. }
  597. h3 {
  598. font-size: 2.92rem;
  599. line-height: 110%;
  600. margin: 1.46rem 0 1.168rem 0;
  601. }
  602. h4 {
  603. font-size: 2.28rem;
  604. line-height: 110%;
  605. margin: 1.14rem 0 0.912rem 0;
  606. }
  607. h5 {
  608. font-size: 1.64rem;
  609. line-height: 110%;
  610. margin: 0.82rem 0 0.656rem 0;
  611. }
  612. h6 {
  613. font-size: 1rem;
  614. line-height: 110%;
  615. margin: 0.5rem 0 0.4rem 0;
  616. }
  617. .thin {
  618. font-weight: 200;
  619. }
  620. .left {
  621. float: left !important;
  622. }
  623. .right {
  624. float: right !important;
  625. }
  626. .light-blue {
  627. background-color: #03a9f4 !important;
  628. }
  629. .white {
  630. background-color: #FFFFFF !important;
  631. }
  632. .btn-search {
  633. font-size: 14px;
  634. }
  635. </style>