Station.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <template>
  2. <station-header></station-header>
  3. <div class="station">
  4. <div class="row">
  5. <div class="col-md-8 col-md-push-2 col-sm-10 col-sm-push-1 col-xs-12 video-col">
  6. <div class="video-container">
  7. <div id="player"></div>
  8. <!--iframe id="player" frameborder="0" allowfullscreen="1" title="YouTube video player" width="480" height="270" src="https://www.youtube.com/embed/xo1VInw-SKc?controls=0&amp;iv_load_policy=3&amp;rel=0&amp;showinfo=0&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fmusare.com&amp;widgetid=1" kwframeid="1"></iframe-->
  9. </div>
  10. </div>
  11. <div class="col-md-8 col-md-push-2 col-sm-10 col-sm-push-1 col-xs-12">
  12. <div class="row">
  13. <button v-if="paused" @click="unpauseStation()">Unpause</button>
  14. <button v-if="!paused" @click="pauseStation()">Pause</button>
  15. <div class="col-md-8 col-sm-12 col-sm-12">
  16. <h4 id="time-display">{{timeElapsed}} / {{songDuration}}</h4>
  17. <h3>{{title}}</h3>
  18. <h4 class="thin" style="margin-left: 0">{{artists}}</h4>
  19. <div class="row">
  20. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="col-md-4 col-lg-4 col-xs-4 col-sm-4">
  21. <p style="margin-top: 0; position: relative;">
  22. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  23. </p>
  24. </form>
  25. <div class="col-xs-8 col-sm-5 col-md-5" style="float: right;">
  26. <ul id="ratings">
  27. <li id="like" class="right"><span class="flow-text">{{likes}} </span> <i id="thumbs_up" class="material-icons grey-text" @click="toggleLike()">thumb_up</i></li>
  28. <li style="margin-right: 10px;" id="dislike" class="right"><span class="flow-text">{{dislikes}} </span><i id="thumbs_down" class="material-icons grey-text" @click="toggleDislike()">thumb_down</i></li>
  29. </ul>
  30. </div>
  31. </div>
  32. <div class="seeker-bar-container white" id="preview-progress">
  33. <div class="seeker-bar light-blue" style="width: 60.9869%;"></div>
  34. </div>
  35. </div>
  36. <img alt="Not loading" class="img-responsive col-md-4 col-xs-12 col-sm-12" onerror="this.src='../assets/notes.png'" id="song-image" style="margin-top: 10px !important" v-bind:src="image" />
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <main-footer></main-footer>
  42. <div class="modal fade" id="queue" tabindex="-1" role="dialog" aria-labelledby="queue-modal">
  43. <div class="modal-dialog modal-large" role="document">
  44. <div class="modal-content">
  45. <div class="modal-header">
  46. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  47. <h5 class="modal-title">Add to Musare</h5>
  48. </div>
  49. <div class="modal-body">
  50. <input class="form-control" type="text" placeholder="YouTube Query / Video ID / Video link / Playlist link" v-model="queueQuery"/>
  51. <button type="button" class="btn btn-primary" @click="submitQueueQuery()">Search</button>
  52. <button type="button" class="btn btn-error" @click="clearQueueQuery()" v-if="queueQueryActive">Clear List</button>
  53. <div v-if="queueQueryActive">
  54. <h2>Queue Results</h2>
  55. <div v-for="item in queueQueryResults">
  56. <h5>{{item.title}}</h5>
  57. <button @click='addItemToItems(item.id)'>Add</button>
  58. <br>
  59. </div>
  60. </div>
  61. <hr>
  62. <div class="row">
  63. <h2>Items to add</h2>
  64. <div v-for="item in queueItems">
  65. <h5>{{item.title}}</h5>
  66. <br>
  67. </div>
  68. </div>
  69. </div>
  70. <div class="modal-footer">
  71. <button type="button" class="btn btn-primary left" data-dismiss="modal" @click="addItemsToQueue()">Add items to queue</button>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. import StationHeader from '../StationHeader.vue'
  79. import MainFooter from '../MainFooter.vue'
  80. export default {
  81. data() {
  82. return {
  83. playerReady: false,
  84. currentSong: undefined,
  85. player: undefined,
  86. timePaused: 0,
  87. paused: false,
  88. songDuration: "0:00",
  89. timeElapsed: "0:00",
  90. artists: "",
  91. title: "",
  92. image: "",
  93. likes: 0,
  94. dislikes: 0,
  95. interval: 0,
  96. queueQuery: "",
  97. queueQueryActive: false,
  98. queueQueryResults: [],
  99. queueItems: []
  100. }
  101. },
  102. methods: {
  103. youtubeReady: function() {
  104. let local = this;
  105. local.player = new YT.Player("player", {
  106. height: 270,
  107. width: 480,
  108. videoId: local.currentSong.id,
  109. playerVars: {controls: 1, iv_load_policy: 3, rel: 0, showinfo: 0},
  110. events: {
  111. 'onReady': function (event) {
  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) {
  117. local.player.unMute();
  118. }
  119. local.playVideo();
  120. },
  121. 'onStateChange': function (event) {
  122. if (event.data === 1 && local.videoLoading === true) {
  123. local.videoLoading = false;
  124. local.player.seekTo(local.getTimeElapsed() / 1000, true);
  125. if (local.paused) {
  126. local.player.pauseVideo();
  127. }
  128. }
  129. }
  130. }
  131. });
  132. },
  133. startSong: function(song) {
  134. let local = this;
  135. if (local.playerReady) {
  136. }
  137. },
  138. getTimeElapsed: function() {
  139. let local = this;
  140. if (local.currentSong !== undefined) {
  141. return Date.now() - local.currentSong.startedAt - local.timePaused;
  142. }
  143. return 0;
  144. },
  145. pauseVideo: function() {
  146. let local = this;
  147. local.paused = true;
  148. if (local.playerReady) {
  149. local.player.pauseVideo();
  150. }
  151. },
  152. unpauseVideo: function() {
  153. let local = this;
  154. local.paused = false;
  155. if (local.playerReady) {
  156. local.player.seekTo(local.getTimeElapsed() / 1000);
  157. local.player.playVideo();
  158. }
  159. },
  160. playVideo: function() {
  161. let local = this;
  162. if (local.playerReady) {
  163. local.videoLoading = true;
  164. local.player.loadVideoById(local.currentSong.id);
  165. var d = moment.duration(parseInt(local.currentSong.duration), 'seconds');
  166. local.songDuration = d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  167. local.artists = local.currentSong.artists.join(", ");
  168. local.title = local.currentSong.title;
  169. local.image = local.currentSong.image;
  170. local.likes = local.currentSong.likes;
  171. local.dislikes = local.currentSong.dislikes;
  172. if (local.interval !== 0) {
  173. clearInterval(local.interval);
  174. }
  175. local.interval = setInterval(function () {
  176. local.resizeSeekerbar();
  177. local.calculateTimeElapsed();
  178. }, 250);
  179. }
  180. },
  181. resizeSeekerbar: function() {
  182. let local = this;
  183. if (!local.paused) {
  184. $(".seeker-bar").width(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100) + "%");
  185. }
  186. },
  187. calculateTimeElapsed: function() {
  188. let local = this;
  189. let currentTime = Date.now();
  190. if (local.timePausedCurrentTime !== undefined && local.paused) {
  191. local.timePaused += (Date.now() - local.timePausedCurrentTime);
  192. local.timePausedCurrentTime = undefined;
  193. }
  194. let duration = (Date.now() - local.currentSong.startedAt - local.timePaused) / 1000;
  195. let songDuration = local.currentSong.duration;
  196. if (songDuration <= duration) {
  197. local.player.pauseVideo();
  198. }
  199. let d = moment.duration(duration, 'seconds');
  200. console.log(duration, " ", local.timePaused);
  201. if ((!local.paused || local.timeElapsed === "0:00") && duration <= songDuration) {
  202. local.timeElapsed = d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  203. }
  204. },
  205. changeVolume: function() {
  206. let local = this;
  207. let volume = $("#volumeSlider").val();
  208. localStorage.setItem("volume", volume);
  209. if (local.playerReady) {
  210. local.player.setVolume(volume);
  211. if (volume > 0) {
  212. local.player.unMute();
  213. }
  214. }
  215. },
  216. unpauseStation: function() {
  217. console.log("UNPAUSE1");
  218. let local = this;
  219. local.stationSocket.emit("unpause");
  220. },
  221. pauseStation: function() {
  222. console.log("PAUSE1");
  223. let local = this;
  224. local.stationSocket.emit("pause");
  225. },
  226. toggleLike: function() {
  227. let local = this;
  228. local.stationSocket.emit("toggleLike");//TODO Add code here to see if this was a success or not
  229. },
  230. toggleDislike: function() {
  231. let local = this;
  232. local.stationSocket.emit("toggleDislike");//TODO Add code here to see if this was a success or not
  233. },
  234. addItemToItems: function(id) {
  235. let local = this;
  236. let ids = local.queueItems.map(function(item) {
  237. return item.id;
  238. });
  239. let item;
  240. local.queueQueryResults.forEach(function(result) {
  241. if (result.id === id) {
  242. console.log(result);
  243. item = result;
  244. }
  245. });
  246. if (ids.indexOf(id) === -1) {
  247. console.log(item, 222);
  248. local.queueItems.push(item);
  249. local.queueQuery = "";
  250. local.queueQueryActive = false;
  251. local.queueQueryResults = [];
  252. } else {
  253. //TODO Error
  254. }
  255. },
  256. addItemsToQueue: function() {
  257. let local = this;
  258. let items = local.queueItems;
  259. local.socket.emit("/songs/queue/addSongs/:songs", items, function(data) {
  260. console.log(data);
  261. if (!data.err) {
  262. local.queueItems = [];
  263. $('#queue').modal('hide');
  264. }
  265. });
  266. },
  267. submitQueueQuery: function() {
  268. let local = this;
  269. let query = local.queueQuery;
  270. local.socket.emit("/youtube/getVideos/:query", query, function(data) {
  271. if (!data.err) {
  272. /*queueQueryActive:
  273. queueQueryResults:*/
  274. if (data.type === "playlist") {
  275. let added = 0;
  276. let duplicate = 0;
  277. let items = [];
  278. let ids = local.queueItems.map(function(item) {
  279. return item.id;
  280. });
  281. data.items.forEach(function(item) {
  282. if (ids.indexOf(item.id) === -1) {
  283. items.push(item);
  284. added++;
  285. } else {
  286. duplicate++;
  287. }
  288. });
  289. //TODO Give result
  290. local.queueItems = local.queueItems.concat(items);
  291. } else if (data.type === "video") {
  292. let ids = local.queueItems.map(function(item) {
  293. return item.id;
  294. });
  295. if (data.item !== undefined) {
  296. if (ids.indexOf(data.item.id)) {
  297. local.queueItems.push(data.item);
  298. }
  299. }
  300. //TODO Give result
  301. } else {
  302. local.queueQueryResults = [];
  303. data.items.forEach(function(item) {
  304. local.queueQueryResults.push(item);
  305. });
  306. //TODO Give result
  307. local.queueQueryActive = true;
  308. }
  309. }
  310. });
  311. }
  312. },
  313. ready: function() {
  314. let local = this;
  315. window.onYouTubeIframeAPIReady = function() {
  316. local.youtubeReady();
  317. };
  318. local.socket = this.$parent.socket;
  319. local.stationSocket = io.connect('http://dev.musare.com/edm');
  320. local.stationSocket.on("skippedSong", function(currentSong) {
  321. console.log("SKIPPED SONG");
  322. local.currentSong = currentSong;
  323. local.timePaused = 0;
  324. local.playVideo();
  325. });
  326. local.stationSocket.on("pause", function() {
  327. console.log("PAUSE");
  328. local.pauseVideo();
  329. });
  330. local.stationSocket.on("unpause", function(timePaused) {
  331. console.log("UNPAUSE");
  332. local.timePaused = timePaused;
  333. local.unpauseVideo();
  334. });
  335. let volume = parseInt(localStorage.getItem("volume"));
  336. volume = (typeof volume === "number") ? volume : 20;
  337. $("#volumeSlider").val(volume);
  338. // TODO: Remove this
  339. local.socket.emit("/stations/join/:id", "edm", function(data) {
  340. local.currentSong = data.data.currentSong;
  341. local.paused = data.data.paused;
  342. local.timePaused = data.data.timePaused;
  343. local.timePausedCurrentTime = data.data.currentTime;
  344. let tag = document.createElement('script');
  345. tag.src = "https://www.youtube.com/iframe_api";
  346. let firstScriptTag = document.getElementsByTagName('script')[0];
  347. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  348. });
  349. },
  350. components: { StationHeader, MainFooter }
  351. }
  352. </script>
  353. <style lang="sass">
  354. .modal-large {
  355. width: 75%;
  356. }
  357. .station {
  358. flex: 1 0 auto;
  359. padding-top: 4.5vw;
  360. transition: all 0.1s;
  361. margin: 0 auto;
  362. max-width: 1280px;
  363. width: 90%;
  364. @media only screen and (min-width: 993px) {
  365. width: 70%;
  366. }
  367. @media only screen and (min-width: 601px) {
  368. width: 85%;
  369. }
  370. input[type=range] {
  371. -webkit-appearance: none;
  372. width: 100%;
  373. margin: 7.3px 0;
  374. }
  375. input[type=range]:focus {
  376. outline: none;
  377. }
  378. input[type=range]::-webkit-slider-runnable-track {
  379. width: 100%;
  380. height: 5.2px;
  381. cursor: pointer;
  382. box-shadow: 0;
  383. background: #c2c0c2;
  384. border-radius: 0;
  385. border: 0;
  386. }
  387. input[type=range]::-webkit-slider-thumb {
  388. box-shadow: 0;
  389. border: 0;
  390. height: 19px;
  391. width: 19px;
  392. border-radius: 15px;
  393. background: #03a9f4;
  394. cursor: pointer;
  395. -webkit-appearance: none;
  396. margin-top: -6.5px;
  397. }
  398. input[type=range]::-moz-range-track {
  399. width: 100%;
  400. height: 5.2px;
  401. cursor: pointer;
  402. box-shadow: 0;
  403. background: #c2c0c2;
  404. border-radius: 0;
  405. border: 0;
  406. }
  407. input[type=range]::-moz-range-thumb {
  408. box-shadow: 0;
  409. border: 0;
  410. height: 19px;
  411. width: 19px;
  412. border-radius: 15px;
  413. background: #03a9f4;
  414. cursor: pointer;
  415. -webkit-appearance: none;
  416. margin-top: -6.5px;
  417. }
  418. input[type=range]::-ms-track {
  419. width: 100%;
  420. height: 5.2px;
  421. cursor: pointer;
  422. box-shadow: 0;
  423. background: #c2c0c2;
  424. border-radius: 1.3px;
  425. }
  426. input[type=range]::-ms-fill-lower {
  427. background: #c2c0c2;
  428. border: 0;
  429. border-radius: 0;
  430. box-shadow: 0;
  431. }
  432. input[type=range]::-ms-fill-upper {
  433. background: #c2c0c2;
  434. border: 0;
  435. border-radius: 0;
  436. box-shadow: 0;
  437. }
  438. input[type=range]::-ms-thumb {
  439. box-shadow: 0;
  440. border: 0;
  441. height: 15px;
  442. width: 15px;
  443. border-radius: 15px;
  444. background: #03a9f4;
  445. cursor: pointer;
  446. -webkit-appearance: none;
  447. margin-top: 1.5px;
  448. }
  449. .video-container {
  450. position: relative;
  451. padding-bottom: 56.25%;
  452. height: 0;
  453. overflow: hidden;
  454. iframe {
  455. position: absolute;
  456. top: 0;
  457. left: 0;
  458. width: 100%;
  459. height: 100%;
  460. pointer-events: none;
  461. }
  462. }
  463. .video-col {
  464. padding-right: 0.75rem;
  465. padding-left: 0.75rem;
  466. }
  467. }
  468. .room-title {
  469. left: 50%;
  470. -webkit-transform: translateX(-50%);
  471. transform: translateX(-50%);
  472. font-size: 2.1em;
  473. }
  474. #ratings {
  475. span {
  476. font-size: 1.68rem;
  477. }
  478. i {
  479. color: #9e9e9e !important;
  480. cursor: pointer;
  481. transition: 0.1s color;
  482. }
  483. }
  484. #time-display {
  485. margin-top: 30px;
  486. float: right;
  487. }
  488. #thumbs_up:hover {
  489. color: #87D37C !important;
  490. }
  491. #thumbs_down:hover {
  492. color: #EC644B !important;
  493. }
  494. .seeker-bar-container {
  495. position: relative;
  496. height: 5px;
  497. display: block;
  498. width: 100%;
  499. overflow: hidden;
  500. margin-top: 20px;
  501. }
  502. .seeker-bar {
  503. top: 0;
  504. left: 0;
  505. bottom: 0;
  506. position: absolute;
  507. }
  508. ul {
  509. list-style: none;
  510. margin: 0;
  511. display: block;
  512. }
  513. h1, h2, h3, h4, h5, h6 {
  514. font-weight: 400;
  515. line-height: 1.1;
  516. }
  517. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  518. font-weight: inherit;
  519. }
  520. h1 {
  521. font-size: 4.2rem;
  522. line-height: 110%;
  523. margin: 2.1rem 0 1.68rem 0;
  524. }
  525. h2 {
  526. font-size: 3.56rem;
  527. line-height: 110%;
  528. margin: 1.78rem 0 1.424rem 0;
  529. }
  530. h3 {
  531. font-size: 2.92rem;
  532. line-height: 110%;
  533. margin: 1.46rem 0 1.168rem 0;
  534. }
  535. h4 {
  536. font-size: 2.28rem;
  537. line-height: 110%;
  538. margin: 1.14rem 0 0.912rem 0;
  539. }
  540. h5 {
  541. font-size: 1.64rem;
  542. line-height: 110%;
  543. margin: 0.82rem 0 0.656rem 0;
  544. }
  545. h6 {
  546. font-size: 1rem;
  547. line-height: 110%;
  548. margin: 0.5rem 0 0.4rem 0;
  549. }
  550. .thin {
  551. font-weight: 200;
  552. }
  553. .left {
  554. float: left !important;
  555. }
  556. .right {
  557. float: right !important;
  558. }
  559. .light-blue {
  560. background-color: #03a9f4 !important;
  561. }
  562. .white {
  563. background-color: #FFFFFF !important;
  564. }
  565. </style>