Station.vue 18 KB

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