Station.vue 18 KB

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