Station.vue 17 KB

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