Station.vue 13 KB

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