Station.vue 12 KB

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