Station.vue 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. <template>
  2. <official-header v-if='type == "official"'></official-header>
  3. <community-header v-if='type == "community"'></community-header>
  4. <song-queue v-if='modals.addSongToQueue'></song-queue>
  5. <add-to-playlist v-if='modals.addSongToPlaylist'></add-to-playlist>
  6. <edit-playlist v-if='modals.editPlaylist'></edit-playlist>
  7. <create-playlist v-if='modals.createPlaylist'></create-playlist>
  8. <edit-station v-show='modals.editStation'></edit-station>
  9. <report v-if='modals.report'></report>
  10. <songs-list-sidebar v-if='sidebars.songslist'></songs-list-sidebar>
  11. <playlist-sidebar v-if='sidebars.playlist'></playlist-sidebar>
  12. <users-sidebar v-if='sidebars.users'></users-sidebar>
  13. <div class="station">
  14. <div v-show="noSong" class="no-song">
  15. <h1>No song is currently playing</h1>
  16. <h4 v-if='type === "community" && station.partyMode'>
  17. <a href='#' class='no-song' @click='modals.addSongToQueue = true'>Add a song to the queue</a>
  18. </h4>
  19. <h4 v-if='type === "community" && !station.partyMode && $parent.userId === station.owner && !station.privatePlaylist'>
  20. <a href='#' class='no-song' @click='sidebars.playlist = true'>Play a private playlist</a>
  21. </h4>
  22. <h1 v-if='type === "community" && !station.partyMode && $parent.userId === station.owner && station.privatePlaylist'>Maybe you can add some songs to your selected private playlist and then press the skip button</h1>
  23. </div>
  24. <div class="columns" v-show="!noSong">
  25. <div class="column is-8-desktop is-offset-2-desktop is-11-mobile">
  26. <div class="video-container">
  27. <div id="player"></div>
  28. <div class="seeker-bar-container white" id="preview-progress">
  29. <div class="seeker-bar light-blue" style="width: 0%;"></div>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="desktop-only columns is-mobile" v-show="!noSong">
  35. <div class="column is-8-desktop is-offset-2-desktop is-12-mobile">
  36. <div class="columns is-mobile">
  37. <div class="column is-11-desktop" v-bind:class="{'is-7-desktop': !simpleSong}">
  38. <h4 id="time-display">{{timeElapsed}} / {{formatTime(currentSong.duration)}}</h4>
  39. <h3>{{currentSong.title}}</h3>
  40. <h4 class="thin" style="margin-left: 0">{{currentSong.artists}}</h4>
  41. <div class="columns is-mobile">
  42. <form style="margin-top: 12px; margin-bottom: 0;" action="#" class="column is-7-desktop is-4-mobile">
  43. <p class='volume-slider-wrapper'>
  44. <i class="material-icons" @click='toggleMute()' v-if='muted'>volume_mute</i>
  45. <i class="material-icons" @click='toggleMute()' v-else>volume_down</i>
  46. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  47. <i class="material-icons" @click='increaseVolume()'>volume_up</i>
  48. </p>
  49. </form>
  50. <div class="column is-8-mobile is-5-desktop" style="float: right;">
  51. <ul id="ratings" v-if="currentSong.likes !== -1 && currentSong.dislikes !== -1">
  52. <li id="like" class="right" @click="toggleLike()">
  53. <span class="flow-text">{{currentSong.likes}} </span>
  54. <i id="thumbs_up" class="material-icons grey-text" v-bind:class="{ liked: liked }">thumb_up</i>
  55. <a class='absolute-a behind' @click="toggleLike()" href='#'></a>
  56. </li>
  57. <li style="margin-right: 10px;" id="dislike" class="right" @click="toggleDislike()">
  58. <span class="flow-text">{{currentSong.dislikes}} </span>
  59. <i id="thumbs_down" class="material-icons grey-text" v-bind:class="{ disliked: disliked }">thumb_down</i>
  60. <a class='absolute-a behind' @click="toggleDislike()" href='#'></a>
  61. </li>
  62. </ul>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="column is-4-desktop" v-if="!simpleSong">
  67. <img class="image" id="song-thumbnail" style="margin-top: 10px !important" :src="currentSong.thumbnail" alt="Song Thumbnail" onerror="this.src='/assets/notes-transparent.png'" />
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="mobile-only" v-show="!noSong">
  73. <div>
  74. <div>
  75. <div>
  76. <form class="columns" action="#">
  77. <p class='column is-11-mobile volume-slider-wrapper'>
  78. <i class="material-icons" @click='toggleMute()' v-if='muted'>volume_mute</i>
  79. <i class="material-icons" @click='toggleMute()' v-else>volume_down</i>
  80. <input type="range" id="volumeSlider" min="0" max="100" class="active" v-on:change="changeVolume()" v-on:input="changeVolume()">
  81. <i class="material-icons" @click='increaseVolume()'>volume_up</i>
  82. </p>
  83. </form>
  84. <div>
  85. <ul id="ratings" style="display: inline-block;" v-if="currentSong.likes !== -1 && currentSong.dislikes !== -1">
  86. <li id="dislike" style="display: inline-block;margin-right: 10px;" @click="toggleDislike()">
  87. <span class="flow-text">{{currentSong.dislikes}} </span>
  88. <i id="thumbs_down" class="material-icons grey-text" v-bind:class="{ disliked: disliked }">thumb_down</i>
  89. <a class='absolute-a behind' @click="toggleDislike()" href='#'></a>
  90. </li>
  91. <li id="like" style="display: inline-block;" @click="toggleLike()">
  92. <span class="flow-text">{{currentSong.likes}} </span>
  93. <i id="thumbs_up" class="material-icons grey-text" v-bind:class="{ liked: liked }">thumb_up</i>
  94. <a class='absolute-a behind' @click="toggleLike()" href='#'></a>
  95. </li>
  96. </ul>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import { Toast } from 'vue-roaster';
  107. import SongQueue from '../Modals/AddSongToQueue.vue';
  108. import AddToPlaylist from '../Modals/AddSongToPlaylist.vue';
  109. import EditPlaylist from '../Modals/Playlists/Edit.vue';
  110. import CreatePlaylist from '../Modals/Playlists/Create.vue';
  111. import EditStation from '../Modals/EditStation.vue';
  112. import Report from '../Modals/Report.vue';
  113. import SongsListSidebar from '../Sidebars/SongsList.vue';
  114. import PlaylistSidebar from '../Sidebars/Playlist.vue';
  115. import UsersSidebar from '../Sidebars/UsersList.vue';
  116. import OfficialHeader from './OfficialHeader.vue';
  117. import CommunityHeader from './CommunityHeader.vue';
  118. import MainFooter from '../MainFooter.vue';
  119. import io from '../../io';
  120. import auth from '../../auth';
  121. export default {
  122. data() {
  123. return {
  124. type: '',
  125. playerReady: false,
  126. previousSong: null,
  127. currentSong: {},
  128. player: undefined,
  129. timePaused: 0,
  130. paused: false,
  131. muted: false,
  132. timeElapsed: '0:00',
  133. liked: false,
  134. disliked: false,
  135. modals: {
  136. addSongToQueue: false,
  137. addSongToPlaylist: false,
  138. editPlaylist: false,
  139. createPlaylist: false,
  140. editStation: false,
  141. report: false
  142. },
  143. sidebars: {
  144. songslist: false,
  145. users: false,
  146. playlist: false
  147. },
  148. noSong: false,
  149. simpleSong: false,
  150. songsList: [],
  151. timeBeforePause: 0,
  152. station: {},
  153. skipVotes: 0,
  154. privatePlaylistQueueSelected: null,
  155. automaticallyRequestedSongId: null,
  156. systemDifference: 0,
  157. users: [],
  158. userCount: 0
  159. }
  160. },
  161. methods: {
  162. editPlaylist: function (id) {
  163. this.playlistBeingEdited = id;
  164. this.modals.editPlaylist = !this.modals.editPlaylist;
  165. },
  166. editStation: function () {
  167. let _this = this;
  168. this.$broadcast('editStation', {
  169. _id: _this.station._id,
  170. name: _this.station.name,
  171. type: _this.type,
  172. partyMode: _this.station.partyMode,
  173. description: _this.station.description,
  174. privacy: _this.station.privacy,
  175. displayName: _this.station.displayName
  176. });
  177. },
  178. toggleSidebar: function (type) {
  179. Object.keys(this.sidebars).forEach(sidebar => {
  180. if (sidebar !== type) this.sidebars[sidebar] = false;
  181. else this.sidebars[type] = !this.sidebars[type];
  182. });
  183. },
  184. youtubeReady: function() {
  185. let local = this;
  186. if (!local.player) {
  187. local.player = new YT.Player("player", {
  188. height: 270,
  189. width: 480,
  190. videoId: local.currentSong.songId,
  191. startSeconds: local.getTimeElapsed() / 1000 + local.currentSong.skipDuration,
  192. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  193. events: {
  194. 'onReady': function (event) {
  195. local.playerReady = true;
  196. let volume = parseInt(localStorage.getItem("volume"));
  197. volume = (typeof volume === "number") ? volume : 20;
  198. local.player.setVolume(volume);
  199. if (volume > 0) local.player.unMute();
  200. local.playVideo();
  201. },
  202. 'onError': function(err) {
  203. console.log("iframe error", err);
  204. local.voteSkipStation();
  205. },
  206. 'onStateChange': function (event) {
  207. if (event.data === 1 && local.videoLoading === true) {
  208. local.videoLoading = false;
  209. local.player.seekTo(local.getTimeElapsed() / 1000 + local.currentSong.skipDuration, true);
  210. if (local.paused) local.player.pauseVideo();
  211. } else if (event.data === 1 && local.paused) {
  212. local.player.seekTo(local.timeBeforePause / 1000, true);
  213. local.player.pauseVideo();
  214. }
  215. if (event.data === 2 && !local.paused && !local.noSong && (local.player.getDuration() / 1000) < local.currentSong.duration) {
  216. local.player.seekTo(local.getTimeElapsed() / 1000 + local.currentSong.skipDuration, true);
  217. local.player.playVideo();
  218. }
  219. }
  220. }
  221. });
  222. }
  223. },
  224. getTimeElapsed: function() {
  225. let local = this;
  226. if (local.currentSong) return Date.currently() - local.startedAt - local.timePaused;
  227. else return 0;
  228. },
  229. playVideo: function() {
  230. let local = this;
  231. if (local.playerReady) {
  232. local.videoLoading = true;
  233. local.player.loadVideoById(local.currentSong.songId, local.getTimeElapsed() / 1000 + local.currentSong.skipDuration);
  234. if (local.currentSong.artists) local.currentSong.artists = local.currentSong.artists.join(", ");
  235. if (window.stationInterval !== 0) clearInterval(window.stationInterval);
  236. window.stationInterval = setInterval(function () {
  237. local.resizeSeekerbar();
  238. local.calculateTimeElapsed();
  239. }, 250);
  240. }
  241. },
  242. resizeSeekerbar: function() {
  243. let local = this;
  244. if (!local.paused) {
  245. $(".seeker-bar").width(parseInt(((local.getTimeElapsed() / 1000) / local.currentSong.duration * 100)) + "%");
  246. }
  247. },
  248. formatTime: function(duration) {
  249. let d = moment.duration(duration, 'seconds');
  250. if (duration < 0) return "0:00";
  251. return ((d.hours() > 0) ? (d.hours() < 10 ? ("0" + d.hours() + ":") : (d.hours() + ":")) : "") + (d.minutes() + ":") + (d.seconds() < 10 ? ("0" + d.seconds()) : d.seconds());
  252. },
  253. calculateTimeElapsed: function() {
  254. let local = this;
  255. let currentTime = Date.currently();
  256. if (local.currentTime !== undefined && local.paused) {
  257. local.timePaused += (Date.currently() - local.currentTime);
  258. local.currentTime = undefined;
  259. }
  260. let duration = (Date.currently() - local.startedAt - local.timePaused) / 1000;
  261. let songDuration = local.currentSong.duration;
  262. if (songDuration <= duration) local.player.pauseVideo();
  263. if ((!local.paused) && duration <= songDuration) local.timeElapsed = local.formatTime(duration);
  264. },
  265. changeVolume: function() {
  266. let local = this;
  267. let volume = $("#volumeSlider").val();
  268. localStorage.setItem("volume", volume);
  269. if (local.playerReady) {
  270. local.player.setVolume(volume);
  271. if (volume > 0) local.player.unMute();
  272. }
  273. },
  274. resumeLocalStation: function() {
  275. this.paused = false;
  276. if (!this.noSong) {
  277. if (this.playerReady) {
  278. this.player.seekTo(this.getTimeElapsed() / 1000 + this.currentSong.skipDuration);
  279. this.player.playVideo();
  280. }
  281. }
  282. },
  283. pauseLocalStation: function() {
  284. this.paused = true;
  285. if (!this.noSong) {
  286. this.timeBeforePause = this.getTimeElapsed();
  287. if (this.playerReady) this.player.pauseVideo();
  288. }
  289. },
  290. skipStation: function () {
  291. let _this = this;
  292. _this.socket.emit('stations.forceSkip', _this.station._id, data => {
  293. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  294. else Toast.methods.addToast('Successfully skipped the station\'s current song.', 4000);
  295. });
  296. },
  297. voteSkipStation: function () {
  298. let _this = this;
  299. _this.socket.emit('stations.voteSkip', _this.station._id, data => {
  300. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  301. else Toast.methods.addToast('Successfully voted to skip the current song.', 4000);
  302. });
  303. },
  304. resumeStation: function () {
  305. let _this = this;
  306. _this.socket.emit('stations.resume', _this.station._id, data => {
  307. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  308. else Toast.methods.addToast('Successfully resumed the station.', 4000);
  309. });
  310. },
  311. pauseStation: function () {
  312. let _this = this;
  313. _this.socket.emit('stations.pause', _this.station._id, data => {
  314. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  315. else Toast.methods.addToast('Successfully paused the station.', 4000);
  316. });
  317. },
  318. toggleMute: function () {
  319. if (this.playerReady) {
  320. let previousVolume = parseInt(localStorage.getItem("volume"));
  321. let volume = this.player.getVolume() <= 0 ? previousVolume : 0;
  322. this.muted = !this.muted;
  323. $("#volumeSlider").val(volume);
  324. this.player.setVolume(volume);
  325. localStorage.setItem("volume", volume);
  326. }
  327. },
  328. increaseVolume: function () {
  329. if (this.playerReady) {
  330. let previousVolume = parseInt(localStorage.getItem("volume"));
  331. let volume = previousVolume + 5;
  332. if (previousVolume === 0) {
  333. this.muted = false;
  334. }
  335. if (volume > 100) {
  336. volume = 100;
  337. }
  338. console.log(previousVolume, volume);
  339. $("#volumeSlider").val(volume);
  340. this.player.setVolume(volume);
  341. localStorage.setItem("volume", volume);
  342. }
  343. },
  344. toggleLike: function() {
  345. let _this = this;
  346. if (_this.liked) _this.socket.emit('songs.unlike', _this.currentSong.songId, data => {
  347. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  348. }); else _this.socket.emit('songs.like', _this.currentSong.songId, data => {
  349. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  350. });
  351. },
  352. toggleDislike: function() {
  353. let _this = this;
  354. if (_this.disliked) return _this.socket.emit('songs.undislike', _this.currentSong.songId, data => {
  355. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  356. });
  357. _this.socket.emit('songs.dislike', _this.currentSong.songId, data => {
  358. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  359. });
  360. },
  361. addFirstPrivatePlaylistSongToQueue: function() {
  362. let _this = this;
  363. let isInQueue = false;
  364. let userId = _this.$parent.userId;
  365. if (_this.type === 'community') {
  366. _this.songsList.forEach((queueSong) => {
  367. if (queueSong.requestedBy === userId) isInQueue = true;
  368. });
  369. if (!isInQueue && _this.privatePlaylistQueueSelected) {
  370. _this.socket.emit('playlists.getFirstSong', _this.privatePlaylistQueueSelected, data => {
  371. if (data.status === 'success') {
  372. console.log(data.song);
  373. let songId = data.song._id;
  374. _this.automaticallyRequestedSongId = data.song.songId;
  375. _this.socket.emit('stations.addToQueue', _this.station._id, data.song.songId, data => {
  376. if (data.status === 'success') {
  377. _this.socket.emit('playlists.moveSongToBottom', _this.privatePlaylistQueueSelected, songId, data => {
  378. if (data.status === 'success') {}
  379. });
  380. }
  381. });
  382. }
  383. });
  384. }
  385. }
  386. },
  387. joinStation: function () {
  388. let _this = this;
  389. _this.socket.emit('stations.join', _this.stationName, res => {
  390. if (res.status === 'success') {
  391. _this.station = {
  392. _id: res.data._id,
  393. name: _this.stationName,
  394. displayName: res.data.displayName,
  395. description: res.data.description,
  396. privacy: res.data.privacy,
  397. partyMode: res.data.partyMode,
  398. owner: res.data.owner,
  399. privatePlaylist: res.data.privatePlaylist
  400. };
  401. _this.currentSong = (res.data.currentSong) ? res.data.currentSong : {};
  402. _this.type = res.data.type;
  403. _this.startedAt = res.data.startedAt;
  404. _this.paused = res.data.paused;
  405. _this.timePaused = res.data.timePaused;
  406. _this.userCount = res.data.userCount;
  407. _this.users = res.data.users;
  408. if (res.data.currentSong) {
  409. _this.noSong = false;
  410. _this.simpleSong = (res.data.currentSong.likes === -1 && res.data.currentSong.dislikes === -1);
  411. if (_this.simpleSong) {
  412. _this.currentSong.skipDuration = 0;
  413. }
  414. _this.youtubeReady();
  415. _this.playVideo();
  416. _this.socket.emit('songs.getOwnSongRatings', res.data.currentSong._id, data => {
  417. if (_this.currentSong.songId === data.songId) {
  418. _this.liked = data.liked;
  419. _this.disliked = data.disliked;
  420. }
  421. });
  422. } else {
  423. if (_this.playerReady) _this.player.pauseVideo();
  424. _this.noSong = true;
  425. }
  426. if (_this.type === 'community') {
  427. _this.socket.emit('stations.getQueue', _this.station._id, data => {
  428. if (data.status === 'success') _this.songsList = data.queue;
  429. });
  430. }
  431. if (_this.type === 'official') {
  432. _this.socket.emit('stations.getPlaylist', _this.station._id, res => {
  433. if (res.status == 'success') _this.songsList = res.data;
  434. });
  435. }
  436. } else {
  437. _this.$router.go('/404');
  438. Toast.methods.addToast(res.message, 3000);
  439. }
  440. // UNIX client time before ping
  441. let beforePing = Date.now();
  442. _this.socket.emit('apis.ping', res => {
  443. // UNIX client time after ping
  444. let afterPing = Date.now();
  445. // Average time in MS it took between the server responding and the client receiving
  446. let connectionLatency = (afterPing - beforePing) / 2;
  447. console.log(connectionLatency, beforePing - afterPing);
  448. // UNIX server time
  449. let serverDate = res.date;
  450. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  451. let difference = (serverDate + connectionLatency) - afterPing;
  452. console.log("Difference: ", difference);
  453. if (difference > 3000 || difference < -3000) {
  454. console.log("System time difference is bigger than 3 seconds.");
  455. }
  456. _this.systemDifference = difference;
  457. });
  458. });
  459. }
  460. },
  461. ready: function() {
  462. let _this = this;
  463. Date.currently = () => {
  464. return new Date().getTime() + _this.systemDifference;
  465. };
  466. _this.stationName = _this.$route.params.id;
  467. window.stationInterval = 0;
  468. io.getSocket(socket => {
  469. _this.socket = socket;
  470. io.removeAllListeners();
  471. if (_this.socket.connected) _this.joinStation();
  472. io.onConnect(() => {
  473. _this.joinStation();
  474. });
  475. _this.socket.emit('stations.findByName', _this.stationName, res => {
  476. if (res.status === 'error') {
  477. _this.$router.go('/404');
  478. Toast.methods.addToast(res.message, 3000);
  479. }
  480. });
  481. _this.socket.on('event:songs.next', data => {
  482. _this.previousSong = (_this.currentSong.songId) ? _this.currentSong : null;
  483. _this.currentSong = (data.currentSong) ? data.currentSong : {};
  484. _this.startedAt = data.startedAt;
  485. _this.paused = data.paused;
  486. _this.timePaused = data.timePaused;
  487. if (data.currentSong) {
  488. _this.noSong = false;
  489. _this.simpleSong = (data.currentSong.likes === -1 && data.currentSong.dislikes === -1);
  490. if (_this.simpleSong) _this.currentSong.skipDuration = 0;
  491. if (!_this.playerReady) _this.youtubeReady();
  492. else _this.playVideo();
  493. _this.socket.emit('songs.getOwnSongRatings', data.currentSong.songId, (data) => {
  494. if (_this.currentSong.songId === data.songId) {
  495. _this.liked = data.liked;
  496. _this.disliked = data.disliked;
  497. }
  498. });
  499. } else {
  500. if (_this.playerReady) _this.player.pauseVideo();
  501. _this.noSong = true;
  502. }
  503. let isInQueue = false;
  504. let userId = _this.$parent.userId;
  505. _this.songsList.forEach((queueSong) => {
  506. if (queueSong.requestedBy === userId) isInQueue = true;
  507. });
  508. if (!isInQueue && _this.privatePlaylistQueueSelected && (_this.automaticallyRequestedSongId !== _this.currentSong.songId || !_this.currentSong.songId)) {
  509. _this.addFirstPrivatePlaylistSongToQueue();
  510. }
  511. });
  512. _this.socket.on('event:stations.pause', data => {
  513. _this.pauseLocalStation();
  514. });
  515. _this.socket.on('event:stations.resume', data => {
  516. _this.timePaused = data.timePaused;
  517. _this.resumeLocalStation();
  518. });
  519. _this.socket.on('event:stations.remove', () => {
  520. location.href = '/';
  521. });
  522. _this.socket.on('event:song.like', data => {
  523. if (!this.noSong) {
  524. if (data.songId === _this.currentSong.songId) {
  525. _this.currentSong.dislikes = data.dislikes;
  526. _this.currentSong.likes = data.likes;
  527. }
  528. }
  529. });
  530. _this.socket.on('event:song.dislike', data => {
  531. if (!this.noSong) {
  532. if (data.songId === _this.currentSong.songId) {
  533. _this.currentSong.dislikes = data.dislikes;
  534. _this.currentSong.likes = data.likes;
  535. }
  536. }
  537. });
  538. _this.socket.on('event:song.unlike', data => {
  539. if (!this.noSong) {
  540. if (data.songId === _this.currentSong.songId) {
  541. _this.currentSong.dislikes = data.dislikes;
  542. _this.currentSong.likes = data.likes;
  543. }
  544. }
  545. });
  546. _this.socket.on('event:song.undislike', data => {
  547. if (!this.noSong) {
  548. if (data.songId === _this.currentSong.songId) {
  549. _this.currentSong.dislikes = data.dislikes;
  550. _this.currentSong.likes = data.likes;
  551. }
  552. }
  553. });
  554. _this.socket.on('event:song.newRatings', data => {
  555. if (!this.noSong) {
  556. if (data.songId === _this.currentSong.songId) {
  557. _this.liked = data.liked;
  558. _this.disliked = data.disliked;
  559. }
  560. }
  561. });
  562. _this.socket.on('event:queue.update', queue => {
  563. if (this.type === 'community') this.songsList = queue;
  564. });
  565. _this.socket.on('event:song.voteSkipSong', () => {
  566. if (this.currentSong) this.currentSong.skipVotes++;
  567. });
  568. _this.socket.on('event:privatePlaylist.selected', (playlistId) => {
  569. if (this.type === 'community') {
  570. this.station.privatePlaylist = playlistId;
  571. }
  572. });
  573. _this.socket.on('event:partyMode.updated', (partyMode) => {
  574. if (this.type === 'community') {
  575. this.station.partyMode = partyMode;
  576. }
  577. });
  578. _this.socket.on('event:newOfficialPlaylist', (playlist) => {
  579. console.log(playlist);
  580. if (this.type === 'official') {
  581. this.songsList = playlist;
  582. }
  583. });
  584. _this.socket.on('event:users.updated', users => {
  585. _this.users = users;
  586. });
  587. _this.socket.on('event:userCount.updated', userCount => {
  588. _this.userCount = userCount;
  589. });
  590. });
  591. let volume = parseInt(localStorage.getItem("volume"));
  592. volume = (typeof volume === "number" && !isNaN(volume)) ? volume : 20;
  593. localStorage.setItem("volume", volume);
  594. $("#volumeSlider").val(volume);
  595. },
  596. components: {
  597. OfficialHeader,
  598. CommunityHeader,
  599. SongQueue,
  600. AddToPlaylist,
  601. EditPlaylist,
  602. CreatePlaylist,
  603. EditStation,
  604. Report,
  605. SongsListSidebar,
  606. PlaylistSidebar,
  607. UsersSidebar,
  608. MainFooter
  609. }
  610. }
  611. </script>
  612. <style lang="scss">
  613. .no-song {
  614. color: #03A9F4;
  615. text-align: center;
  616. }
  617. #volumeSlider {
  618. padding: 0 15px;
  619. background: transparent;
  620. }
  621. .volume-slider-wrapper {
  622. margin-top: 0;
  623. position: relative;
  624. display: flex;
  625. align-items: center;
  626. }
  627. .material-icons { cursor: pointer; }
  628. .stationDisplayName {
  629. color: white !important;
  630. }
  631. .add-to-playlist {
  632. display: flex;
  633. align-items: center;
  634. justify-content: center;
  635. }
  636. .slideout {
  637. top: 50px;
  638. height: 100%;
  639. position: fixed;
  640. right: 0;
  641. width: 350px;
  642. background-color: white;
  643. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  644. .slideout-header {
  645. text-align: center;
  646. background-color: rgb(3, 169, 244) !important;
  647. margin: 0;
  648. padding-top: 5px;
  649. padding-bottom: 7px;
  650. color: white;
  651. }
  652. .slideout-content {
  653. height: 100%;
  654. }
  655. }
  656. .modal-large {
  657. width: 75%;
  658. }
  659. .station {
  660. flex: 1 0 auto;
  661. padding-top: 0.5vw;
  662. transition: all 0.1s;
  663. margin: 0 auto;
  664. max-width: 100%;
  665. width: 90%;
  666. @media only screen and (min-width: 993px) {
  667. width: 70%;
  668. }
  669. @media only screen and (min-width: 601px) {
  670. width: 85%;
  671. }
  672. @media (min-width: 881px) {
  673. .mobile-only {
  674. display: none;
  675. }
  676. .desktop-only {
  677. display: block;
  678. }
  679. }
  680. @media (max-width: 880px) {
  681. margin-left: 64px;
  682. .mobile-only {
  683. display: block;
  684. }
  685. .desktop-only {
  686. display: none;
  687. visibility: hidden;
  688. }
  689. }
  690. .mobile-only {
  691. text-align: center;
  692. }
  693. input[type=range] {
  694. -webkit-appearance: none;
  695. width: 100%;
  696. margin: 7.3px 0;
  697. }
  698. input[type=range]:focus {
  699. outline: none;
  700. }
  701. input[type=range]::-webkit-slider-runnable-track {
  702. width: 100%;
  703. height: 5.2px;
  704. cursor: pointer;
  705. box-shadow: 0;
  706. background: #c2c0c2;
  707. border-radius: 0;
  708. border: 0;
  709. }
  710. input[type=range]::-webkit-slider-thumb {
  711. box-shadow: 0;
  712. border: 0;
  713. height: 19px;
  714. width: 19px;
  715. border-radius: 15px;
  716. background: #03a9f4;
  717. cursor: pointer;
  718. -webkit-appearance: none;
  719. margin-top: -6.5px;
  720. }
  721. input[type=range]::-moz-range-track {
  722. width: 100%;
  723. height: 5.2px;
  724. cursor: pointer;
  725. box-shadow: 0;
  726. background: #c2c0c2;
  727. border-radius: 0;
  728. border: 0;
  729. }
  730. input[type=range]::-moz-range-thumb {
  731. box-shadow: 0;
  732. border: 0;
  733. height: 19px;
  734. width: 19px;
  735. border-radius: 15px;
  736. background: #03a9f4;
  737. cursor: pointer;
  738. -webkit-appearance: none;
  739. margin-top: -6.5px;
  740. }
  741. input[type=range]::-ms-track {
  742. width: 100%;
  743. height: 5.2px;
  744. cursor: pointer;
  745. box-shadow: 0;
  746. background: #c2c0c2;
  747. border-radius: 1.3px;
  748. }
  749. input[type=range]::-ms-fill-lower {
  750. background: #c2c0c2;
  751. border: 0;
  752. border-radius: 0;
  753. box-shadow: 0;
  754. }
  755. input[type=range]::-ms-fill-upper {
  756. background: #c2c0c2;
  757. border: 0;
  758. border-radius: 0;
  759. box-shadow: 0;
  760. }
  761. input[type=range]::-ms-thumb {
  762. box-shadow: 0;
  763. border: 0;
  764. height: 15px;
  765. width: 15px;
  766. border-radius: 15px;
  767. background: #03a9f4;
  768. cursor: pointer;
  769. -webkit-appearance: none;
  770. margin-top: 1.5px;
  771. }
  772. .video-container {
  773. position: relative;
  774. padding-bottom: 56.25%;
  775. height: 0;
  776. overflow: hidden;
  777. iframe {
  778. position: absolute;
  779. top: 0;
  780. left: 0;
  781. width: 100%;
  782. height: 100%;
  783. }
  784. }
  785. .video-col {
  786. padding-right: 0.75rem;
  787. padding-left: 0.75rem;
  788. }
  789. }
  790. .room-title {
  791. left: 50%;
  792. -webkit-transform: translateX(-50%);
  793. transform: translateX(-50%);
  794. font-size: 2.1em;
  795. }
  796. #ratings {
  797. span {
  798. font-size: 1.68rem;
  799. }
  800. i {
  801. color: #9e9e9e !important;
  802. cursor: pointer;
  803. transition: 0.1s color;
  804. }
  805. }
  806. #time-display {
  807. margin-top: 30px;
  808. float: right;
  809. }
  810. #thumbs_up:hover, #thumbs_up.liked {
  811. color: #87D37C !important;
  812. }
  813. #thumbs_down:hover, #thumbs_down.disliked {
  814. color: #EC644B !important;
  815. }
  816. #song-thumbnail {
  817. max-width: 100%;
  818. width: 85%;
  819. }
  820. .seeker-bar-container {
  821. position: relative;
  822. height: 5px;
  823. display: block;
  824. width: 100%;
  825. overflow: hidden;
  826. }
  827. .seeker-bar {
  828. top: 0;
  829. left: 0;
  830. bottom: 0;
  831. position: absolute;
  832. }
  833. ul {
  834. list-style: none;
  835. margin: 0;
  836. display: block;
  837. }
  838. h1, h2, h3, h4, h5, h6 {
  839. font-weight: 400;
  840. line-height: 1.1;
  841. }
  842. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  843. font-weight: inherit;
  844. }
  845. h1 {
  846. font-size: 4.2rem;
  847. line-height: 110%;
  848. margin: 2.1rem 0 1.68rem 0;
  849. }
  850. h2 {
  851. font-size: 3.56rem;
  852. line-height: 110%;
  853. margin: 1.78rem 0 1.424rem 0;
  854. }
  855. h3 {
  856. font-size: 2.92rem;
  857. line-height: 110%;
  858. margin: 1.46rem 0 1.168rem 0;
  859. }
  860. h4 {
  861. font-size: 2.28rem;
  862. line-height: 110%;
  863. margin: 1.14rem 0 0.912rem 0;
  864. }
  865. h5 {
  866. font-size: 1.64rem;
  867. line-height: 110%;
  868. margin: 0.82rem 0 0.656rem 0;
  869. }
  870. h6 {
  871. font-size: 1rem;
  872. line-height: 110%;
  873. margin: 0.5rem 0 0.4rem 0;
  874. }
  875. .thin {
  876. font-weight: 200;
  877. }
  878. .left {
  879. float: left !important;
  880. }
  881. .right {
  882. float: right !important;
  883. }
  884. .light-blue {
  885. background-color: #03a9f4 !important;
  886. }
  887. .white {
  888. background-color: #FFFFFF !important;
  889. }
  890. .btn-search {
  891. font-size: 14px;
  892. }
  893. .menu { padding: 0 10px; }
  894. .menu-list li a:hover { color: #000 !important; }
  895. .menu-list li {
  896. display: flex;
  897. justify-content: space-between;
  898. }
  899. .menu-list a {
  900. /*padding: 0 10px !important;*/
  901. }
  902. .menu-list a:hover {
  903. background-color : transparent;
  904. }
  905. .icons-group { display: flex; }
  906. #like, #dislike {
  907. position: relative;
  908. }
  909. .behind {
  910. z-index: -1;
  911. }
  912. .behind:focus {
  913. z-index: 0;
  914. }
  915. </style>