Station.vue 31 KB

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