Station.vue 17 KB

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