Station.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <station-header></station-header>
  3. <div class="station">
  4. <div class="columns is-mobile">
  5. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  6. <div class="video-container">
  7. <div id="player"></div>
  8. <div class="seeker-bar-container white" id="preview-progress">
  9. <div class="seeker-bar light-blue" style="width: 60.9869%;"></div>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="columns is-mobile">
  15. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  16. <!--<button v-if="paused" @click="unpauseStation()">Unpause</button>-->
  17. <!--<button v-if="!paused" @click="pauseStation()">Pause</button>-->
  18. <div class="columns is-mobile">
  19. <div class="column is-8-desktop is-12-mobile">
  20. <h4 id="time-display">{{timeElapsed}} / {{formatTime(currentSong.duration)}}</h4>
  21. <h3>{{currentSong.title}}</h3>
  22. <h4 class="thin" style="margin-left: 0">{{currentSong.artists}}</h4>
  23. <div class="columns is-mobile">
  24. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="column is-7-desktop is-4-mobile">
  25. <p style="margin-top: 0; position: relative;">
  26. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  27. </p>
  28. </form>
  29. <div class="column is-8-mobile is-5-desktop" style="float: right;">
  30. <ul id="ratings">
  31. <li id="like" class="right"><span class="flow-text">{{currentSong.likes}} </span> <i id="thumbs_up" class="material-icons grey-text">thumb_up</i></li>
  32. <li style="margin-right: 10px;" id="dislike" class="right"><span class="flow-text">{{currentSong.dislikes}} </span><i id="thumbs_down" class="material-icons grey-text">thumb_down</i></li>
  33. </ul>
  34. </div>
  35. </div>
  36. </div>
  37. <button @click="addSongToQueue('aHjpOzsQ9YI')">ADD CRYSTALIZE!</button>
  38. <div class="column is-4-desktop is-12-mobile">
  39. <img class="image" id="song-thumbnail" style="margin-top: 10px !important" :src="currentSong.thumbnail" alt="Song Thumbnail" />
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="modal" :class="{ 'is-active': isActive }">
  46. <div class="modal-background"></div>
  47. <div class="modal-card">
  48. <header class="modal-card-head">
  49. <p class="modal-card-title">Add Songs to Station</p>
  50. <button class="delete" @click="toggleModal()" ></button>
  51. </header>
  52. <section class="modal-card-body">
  53. <div class="control is-grouped">
  54. <p class="control is-expanded">
  55. <input class="input" type="text" placeholder="YouTube Query" v-model="querySearch">
  56. </p>
  57. <p class="control">
  58. <a class="button is-info" @click="submitQuery()">
  59. Search
  60. </a>
  61. </p>
  62. </div>
  63. <table class="table">
  64. <tbody>
  65. <tr v-for="result in queryResults">
  66. <td>
  67. <img :src="result.thumbnail" />
  68. </td>
  69. <td>{{result.title}}</td>
  70. <td>
  71. <a class="button is-success" @click="addSongToQueue(result.id)">
  72. Add
  73. </a>
  74. </td>
  75. </tr>
  76. </tbody>
  77. </table>
  78. </section>
  79. </div>
  80. </div>
  81. </template>
  82. <script>
  83. import { Toast } from 'vue-roaster';
  84. import StationHeader from './StationHeader.vue';
  85. export default {
  86. data() {
  87. return {
  88. isActive: false,
  89. playerReady: false,
  90. currentSong: {},
  91. player: undefined,
  92. timePaused: 0,
  93. paused: false,
  94. timeElapsed: "0:00",
  95. interval: 0,
  96. querySearch: "",
  97. queryResults: [],
  98. queue: []
  99. }
  100. },
  101. methods: {
  102. toggleModal: function() {
  103. this.isActive = !this.isActive;
  104. },
  105. youtubeReady: function() {
  106. let local = this;
  107. local.player = new YT.Player("player", {
  108. height: 270,
  109. width: 480,
  110. videoId: local.currentSong._id,
  111. playerVars: {controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0},
  112. events: {
  113. 'onReady': function(event) {
  114. local.playerReady = true;
  115. let volume = parseInt(localStorage.getItem("volume"));
  116. volume = (typeof volume === "number") ? volume : 20;
  117. local.player.setVolume(volume);
  118. if (volume > 0) {
  119. local.player.unMute();
  120. }
  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) {
  128. local.player.pauseVideo();
  129. }
  130. }
  131. }
  132. }
  133. });
  134. },
  135. getTimeElapsed: function() {
  136. let local = this;
  137. if (local.currentSong) {
  138. return Date.now() - local.startedAt - local.timePaused;
  139. } else {
  140. return 0;
  141. }
  142. },
  143. playVideo: function() {
  144. let local = this;
  145. if (local.playerReady) {
  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) {
  150. clearInterval(local.interval);
  151. }
  152. local.interval = setInterval(function () {
  153. local.resizeSeekerbar();
  154. local.calculateTimeElapsed();
  155. }, 250);
  156. }
  157. },
  158. resizeSeekerbar: function() {
  159. let local = this;
  160. if (!local.paused) {
  161. $(".seeker-bar").width(parseInt(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100)) + "%");
  162. }
  163. },
  164. formatTime: function(duration) {
  165. let d = moment.duration(duration, 'seconds');
  166. return ((d.hours() > 0) ? (d.hours() < 10 ? ("0" + d.hours() + ":") : (d.hours() + ":")) : "") + (d.minutes() + ":") + (d.seconds() < 10 ? ("0" + d.seconds()) : d.seconds());
  167. },
  168. calculateTimeElapsed: function() {
  169. let local = this;
  170. let currentTime = Date.now();
  171. if (local.currentTime !== undefined && local.paused) {
  172. local.timePaused += (Date.now() - local.currentTime);
  173. local.currentTime = undefined;
  174. }
  175. let duration = (Date.now() - local.startedAt - local.timePaused) / 1000;
  176. let songDuration = local.currentSong.duration;
  177. if (songDuration <= duration) {
  178. // console.log("PAUSE!");
  179. // console.log(songDuration, duration);
  180. local.player.pauseVideo();
  181. }
  182. if ((!local.paused) && duration <= songDuration) {
  183. local.timeElapsed = local.formatTime(duration);
  184. }
  185. },
  186. changeVolume: function() {
  187. let local = this;
  188. let volume = $("#volumeSlider").val();
  189. localStorage.setItem("volume", volume);
  190. if (local.playerReady) {
  191. local.player.setVolume(volume);
  192. if (volume > 0) {
  193. local.player.unMute();
  194. }
  195. }
  196. },
  197. unpauseStation: function() {
  198. let local = this;
  199. local.paused = false;
  200. if (local.playerReady) {
  201. local.player.seekTo(local.getTimeElapsed() / 1000);
  202. local.player.playVideo();
  203. }
  204. },
  205. pauseStation: function() {
  206. let local = this;
  207. local.paused = true;
  208. if (local.playerReady) {
  209. local.player.pauseVideo();
  210. }
  211. },
  212. addSongToQueue: function(songId) {
  213. let local = this;
  214. local.socket.emit('queueSongs.add', songId, res => {
  215. if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
  216. });
  217. },
  218. submitQuery: function() {
  219. let local = this;
  220. local.socket.emit('apis.searchYoutube', local.querySearch, function(results) {
  221. results = results.data;
  222. local.queryResults = [];
  223. for (let i = 0; i < results.items.length; i++) {
  224. local.queryResults.push({
  225. id: results.items[i].id.videoId,
  226. url: `https://www.youtube.com/watch?v=${this.id}`,
  227. title: results.items[i].snippet.title,
  228. thumbnail: results.items[i].snippet.thumbnails.default.url
  229. });
  230. }
  231. });
  232. }
  233. },
  234. ready: function() {
  235. let _this = this;
  236. _this.stationId = _this.$route.params.id;
  237. _this.interval = 0;
  238. _this.socket = _this.$parent.socket;
  239. _this.socket.emit('stations.join', _this.stationId, data => {
  240. if (data.status === "success") {
  241. _this.currentSong = data.currentSong;
  242. _this.startedAt = data.startedAt;
  243. _this.paused = data.paused;
  244. _this.timePaused = data.timePaused;
  245. _this.youtubeReady();
  246. _this.playVideo();
  247. } else {
  248. //TODO Handle error
  249. }
  250. });
  251. _this.socket.on('event:songs.next', data => {
  252. _this.currentSong = data.currentSong;
  253. _this.startedAt = data.startedAt;
  254. _this.paused = data.paused;
  255. _this.timePaused = data.timePaused;
  256. _this.playVideo();
  257. });
  258. let volume = parseInt(localStorage.getItem("volume"));
  259. volume = (typeof volume === "number") ? volume : 20;
  260. $("#volumeSlider").val(volume);
  261. },
  262. components: { StationHeader }
  263. }
  264. </script>
  265. <style lang="scss">
  266. .modal-large {
  267. width: 75%;
  268. }
  269. .station {
  270. flex: 1 0 auto;
  271. padding-top: 0.5vw;
  272. transition: all 0.1s;
  273. margin: 0 auto;
  274. max-width: 1280px;
  275. width: 90%;
  276. @media only screen and (min-width: 993px) {
  277. width: 70%;
  278. }
  279. @media only screen and (min-width: 601px) {
  280. width: 85%;
  281. }
  282. input[type=range] {
  283. -webkit-appearance: none;
  284. width: 100%;
  285. margin: 7.3px 0;
  286. }
  287. input[type=range]:focus {
  288. outline: none;
  289. }
  290. input[type=range]::-webkit-slider-runnable-track {
  291. width: 100%;
  292. height: 5.2px;
  293. cursor: pointer;
  294. box-shadow: 0;
  295. background: #c2c0c2;
  296. border-radius: 0;
  297. border: 0;
  298. }
  299. input[type=range]::-webkit-slider-thumb {
  300. box-shadow: 0;
  301. border: 0;
  302. height: 19px;
  303. width: 19px;
  304. border-radius: 15px;
  305. background: #03a9f4;
  306. cursor: pointer;
  307. -webkit-appearance: none;
  308. margin-top: -6.5px;
  309. }
  310. input[type=range]::-moz-range-track {
  311. width: 100%;
  312. height: 5.2px;
  313. cursor: pointer;
  314. box-shadow: 0;
  315. background: #c2c0c2;
  316. border-radius: 0;
  317. border: 0;
  318. }
  319. input[type=range]::-moz-range-thumb {
  320. box-shadow: 0;
  321. border: 0;
  322. height: 19px;
  323. width: 19px;
  324. border-radius: 15px;
  325. background: #03a9f4;
  326. cursor: pointer;
  327. -webkit-appearance: none;
  328. margin-top: -6.5px;
  329. }
  330. input[type=range]::-ms-track {
  331. width: 100%;
  332. height: 5.2px;
  333. cursor: pointer;
  334. box-shadow: 0;
  335. background: #c2c0c2;
  336. border-radius: 1.3px;
  337. }
  338. input[type=range]::-ms-fill-lower {
  339. background: #c2c0c2;
  340. border: 0;
  341. border-radius: 0;
  342. box-shadow: 0;
  343. }
  344. input[type=range]::-ms-fill-upper {
  345. background: #c2c0c2;
  346. border: 0;
  347. border-radius: 0;
  348. box-shadow: 0;
  349. }
  350. input[type=range]::-ms-thumb {
  351. box-shadow: 0;
  352. border: 0;
  353. height: 15px;
  354. width: 15px;
  355. border-radius: 15px;
  356. background: #03a9f4;
  357. cursor: pointer;
  358. -webkit-appearance: none;
  359. margin-top: 1.5px;
  360. }
  361. .video-container {
  362. position: relative;
  363. padding-bottom: 56.25%;
  364. height: 0;
  365. overflow: hidden;
  366. iframe {
  367. position: absolute;
  368. top: 0;
  369. left: 0;
  370. width: 100%;
  371. height: 100%;
  372. /*pointer-events: none;*/
  373. }
  374. }
  375. .video-col {
  376. padding-right: 0.75rem;
  377. padding-left: 0.75rem;
  378. }
  379. }
  380. .room-title {
  381. left: 50%;
  382. -webkit-transform: translateX(-50%);
  383. transform: translateX(-50%);
  384. font-size: 2.1em;
  385. }
  386. #ratings {
  387. span {
  388. font-size: 1.68rem;
  389. }
  390. i {
  391. color: #9e9e9e !important;
  392. cursor: pointer;
  393. transition: 0.1s color;
  394. }
  395. }
  396. #time-display {
  397. margin-top: 30px;
  398. float: right;
  399. }
  400. #thumbs_up:hover {
  401. color: #87D37C !important;
  402. }
  403. #thumbs_down:hover {
  404. color: #EC644B !important;
  405. }
  406. #song-thumbnail {
  407. max-width: 100%;
  408. width: 85%;
  409. }
  410. .seeker-bar-container {
  411. position: relative;
  412. height: 5px;
  413. display: block;
  414. width: 100%;
  415. overflow: hidden;
  416. }
  417. .seeker-bar {
  418. top: 0;
  419. left: 0;
  420. bottom: 0;
  421. position: absolute;
  422. }
  423. ul {
  424. list-style: none;
  425. margin: 0;
  426. display: block;
  427. }
  428. h1, h2, h3, h4, h5, h6 {
  429. font-weight: 400;
  430. line-height: 1.1;
  431. }
  432. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  433. font-weight: inherit;
  434. }
  435. h1 {
  436. font-size: 4.2rem;
  437. line-height: 110%;
  438. margin: 2.1rem 0 1.68rem 0;
  439. }
  440. h2 {
  441. font-size: 3.56rem;
  442. line-height: 110%;
  443. margin: 1.78rem 0 1.424rem 0;
  444. }
  445. h3 {
  446. font-size: 2.92rem;
  447. line-height: 110%;
  448. margin: 1.46rem 0 1.168rem 0;
  449. }
  450. h4 {
  451. font-size: 2.28rem;
  452. line-height: 110%;
  453. margin: 1.14rem 0 0.912rem 0;
  454. }
  455. h5 {
  456. font-size: 1.64rem;
  457. line-height: 110%;
  458. margin: 0.82rem 0 0.656rem 0;
  459. }
  460. h6 {
  461. font-size: 1rem;
  462. line-height: 110%;
  463. margin: 0.5rem 0 0.4rem 0;
  464. }
  465. .thin {
  466. font-weight: 200;
  467. }
  468. .left {
  469. float: left !important;
  470. }
  471. .right {
  472. float: right !important;
  473. }
  474. .light-blue {
  475. background-color: #03a9f4 !important;
  476. }
  477. .white {
  478. background-color: #FFFFFF !important;
  479. }
  480. .btn-search {
  481. font-size: 14px;
  482. }
  483. </style>