Station.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125
  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. toggleLock: function () {
  313. let _this = this;
  314. socket.emit('stations.toggleLock', this.station._id, this.station.locked, res => {
  315. console.log(res);
  316. if (res.status === 'success') {
  317. _this.station.locked = res.data;
  318. }
  319. });
  320. },
  321. changeVolume: function() {
  322. let local = this;
  323. let volume = $("#volumeSlider").val();
  324. localStorage.setItem("volume", volume);
  325. if (local.playerReady) {
  326. local.player.setVolume(volume);
  327. if (volume > 0) local.player.unMute();
  328. }
  329. },
  330. resumeLocalStation: function() {
  331. this.paused = false;
  332. if (!this.noSong) {
  333. if (this.playerReady) {
  334. this.player.seekTo(this.getTimeElapsed() / 1000 + this.currentSong.skipDuration);
  335. this.player.playVideo();
  336. }
  337. }
  338. },
  339. pauseLocalStation: function() {
  340. this.paused = true;
  341. if (!this.noSong) {
  342. this.timeBeforePause = this.getTimeElapsed();
  343. if (this.playerReady) this.player.pauseVideo();
  344. }
  345. },
  346. skipStation: function () {
  347. let _this = this;
  348. _this.socket.emit('stations.forceSkip', _this.station._id, data => {
  349. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  350. else Toast.methods.addToast('Successfully skipped the station\'s current song.', 4000);
  351. });
  352. },
  353. voteSkipStation: function () {
  354. let _this = this;
  355. _this.socket.emit('stations.voteSkip', _this.station._id, data => {
  356. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  357. else Toast.methods.addToast('Successfully voted to skip the current song.', 4000);
  358. });
  359. },
  360. resumeStation: function () {
  361. let _this = this;
  362. _this.socket.emit('stations.resume', _this.station._id, data => {
  363. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  364. else Toast.methods.addToast('Successfully resumed the station.', 4000);
  365. });
  366. },
  367. pauseStation: function () {
  368. let _this = this;
  369. _this.socket.emit('stations.pause', _this.station._id, data => {
  370. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  371. else Toast.methods.addToast('Successfully paused the station.', 4000);
  372. });
  373. },
  374. toggleMute: function () {
  375. if (this.playerReady) {
  376. let previousVolume = parseInt(localStorage.getItem("volume"));
  377. let volume = this.player.getVolume() <= 0 ? previousVolume : 0;
  378. this.muted = !this.muted;
  379. $("#volumeSlider").val(volume);
  380. this.player.setVolume(volume);
  381. if (!this.muted) localStorage.setItem("volume", volume);
  382. }
  383. },
  384. increaseVolume: function () {
  385. if (this.playerReady) {
  386. let previousVolume = parseInt(localStorage.getItem("volume"));
  387. let volume = previousVolume + 5;
  388. if (previousVolume === 0) this.muted = false;
  389. if (volume > 100) volume = 100;
  390. $("#volumeSlider").val(volume);
  391. this.player.setVolume(volume);
  392. localStorage.setItem("volume", volume);
  393. }
  394. },
  395. toggleLike: function() {
  396. let _this = this;
  397. if (_this.liked) _this.socket.emit('songs.unlike', _this.currentSong.songId, data => {
  398. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  399. }); else _this.socket.emit('songs.like', _this.currentSong.songId, data => {
  400. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  401. });
  402. },
  403. toggleDislike: function() {
  404. let _this = this;
  405. if (_this.disliked) return _this.socket.emit('songs.undislike', _this.currentSong.songId, data => {
  406. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  407. });
  408. _this.socket.emit('songs.dislike', _this.currentSong.songId, data => {
  409. if (data.status !== 'success') Toast.methods.addToast(`Error: ${data.message}`, 8000);
  410. });
  411. },
  412. addFirstPrivatePlaylistSongToQueue: function() {
  413. let _this = this;
  414. let isInQueue = false;
  415. let userId = _this.$parent.userId;
  416. if (_this.type === 'community') {
  417. _this.songsList.forEach((queueSong) => {
  418. if (queueSong.requestedBy === userId) isInQueue = true;
  419. });
  420. if (!isInQueue && _this.privatePlaylistQueueSelected) {
  421. _this.socket.emit('playlists.getFirstSong', _this.privatePlaylistQueueSelected, data => {
  422. if (data.status === 'success') {
  423. console.log(data.song);
  424. let songId = data.song._id;
  425. _this.automaticallyRequestedSongId = data.song.songId;
  426. _this.socket.emit('stations.addToQueue', _this.station._id, data.song.songId, data2 => {
  427. if (data2.status === 'success') {
  428. _this.socket.emit('playlists.moveSongToBottom', _this.privatePlaylistQueueSelected, data.song.songId, data3 => {
  429. if (data3.status === 'success') {}
  430. });
  431. }
  432. });
  433. }
  434. });
  435. }
  436. }
  437. },
  438. joinStation: function () {
  439. let _this = this;
  440. _this.socket.emit('stations.join', _this.stationName, res => {
  441. if (res.status === 'success') {
  442. _this.station = {
  443. _id: res.data._id,
  444. name: _this.stationName,
  445. displayName: res.data.displayName,
  446. description: res.data.description,
  447. privacy: res.data.privacy,
  448. locked: res.data.locked,
  449. partyMode: res.data.partyMode,
  450. owner: res.data.owner,
  451. privatePlaylist: res.data.privatePlaylist
  452. };
  453. _this.currentSong = (res.data.currentSong) ? res.data.currentSong : {};
  454. _this.type = res.data.type;
  455. _this.startedAt = res.data.startedAt;
  456. _this.paused = res.data.paused;
  457. _this.timePaused = res.data.timePaused;
  458. _this.userCount = res.data.userCount;
  459. _this.users = res.data.users;
  460. if (res.data.currentSong) {
  461. _this.noSong = false;
  462. _this.simpleSong = (res.data.currentSong.likes === -1 && res.data.currentSong.dislikes === -1);
  463. if (_this.simpleSong) {
  464. _this.currentSong.skipDuration = 0;
  465. }
  466. _this.youtubeReady();
  467. _this.playVideo();
  468. _this.socket.emit('songs.getOwnSongRatings', res.data.currentSong.songId, data => {
  469. if (_this.currentSong.songId === data.songId) {
  470. _this.liked = data.liked;
  471. _this.disliked = data.disliked;
  472. }
  473. });
  474. } else {
  475. if (_this.playerReady) _this.player.pauseVideo();
  476. _this.noSong = true;
  477. }
  478. if (_this.type === 'community') {
  479. _this.socket.emit('stations.getQueue', _this.station._id, data => {
  480. if (data.status === 'success') _this.songsList = data.queue;
  481. });
  482. }
  483. if (_this.type === 'official') {
  484. _this.socket.emit('stations.getPlaylist', _this.station._id, res => {
  485. if (res.status == 'success') _this.songsList = res.data;
  486. });
  487. }
  488. } else {
  489. _this.$router.go('/404');
  490. Toast.methods.addToast(res.message, 3000);
  491. }
  492. // UNIX client time before ping
  493. let beforePing = Date.now();
  494. _this.socket.emit('apis.ping', res => {
  495. // UNIX client time after ping
  496. let afterPing = Date.now();
  497. // Average time in MS it took between the server responding and the client receiving
  498. let connectionLatency = (afterPing - beforePing) / 2;
  499. console.log(connectionLatency, beforePing - afterPing);
  500. // UNIX server time
  501. let serverDate = res.date;
  502. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  503. let difference = (serverDate + connectionLatency) - afterPing;
  504. console.log("Difference: ", difference);
  505. if (difference > 3000 || difference < -3000) {
  506. console.log("System time difference is bigger than 3 seconds.");
  507. }
  508. _this.systemDifference = difference;
  509. });
  510. });
  511. }
  512. },
  513. ready: function() {
  514. let _this = this;
  515. Date.currently = () => {
  516. return new Date().getTime() + _this.systemDifference;
  517. };
  518. _this.stationName = _this.$route.params.id;
  519. window.stationInterval = 0;
  520. io.getSocket(socket => {
  521. _this.socket = socket;
  522. io.removeAllListeners();
  523. if (_this.socket.connected) _this.joinStation();
  524. io.onConnect(() => {
  525. _this.joinStation();
  526. });
  527. _this.socket.emit('stations.findByName', _this.stationName, res => {
  528. if (res.status === 'error') {
  529. _this.$router.go('/404');
  530. Toast.methods.addToast(res.message, 3000);
  531. } else {
  532. _this.ready = true;
  533. }
  534. });
  535. _this.socket.on('event:songs.next', data => {
  536. _this.previousSong = (_this.currentSong.songId) ? _this.currentSong : null;
  537. _this.currentSong = (data.currentSong) ? data.currentSong : {};
  538. _this.startedAt = data.startedAt;
  539. _this.paused = data.paused;
  540. _this.timePaused = data.timePaused;
  541. if (data.currentSong) {
  542. _this.noSong = false;
  543. _this.simpleSong = (data.currentSong.likes === -1 && data.currentSong.dislikes === -1);
  544. if (_this.simpleSong) _this.currentSong.skipDuration = 0;
  545. if (!_this.playerReady) _this.youtubeReady();
  546. else _this.playVideo();
  547. _this.socket.emit('songs.getOwnSongRatings', data.currentSong.songId, (data) => {
  548. if (_this.currentSong.songId === data.songId) {
  549. _this.liked = data.liked;
  550. _this.disliked = data.disliked;
  551. }
  552. });
  553. } else {
  554. if (_this.playerReady) _this.player.pauseVideo();
  555. _this.noSong = true;
  556. }
  557. let isInQueue = false;
  558. let userId = _this.$parent.userId;
  559. _this.songsList.forEach((queueSong) => {
  560. if (queueSong.requestedBy === userId) isInQueue = true;
  561. });
  562. if (!isInQueue && _this.privatePlaylistQueueSelected && (_this.automaticallyRequestedSongId !== _this.currentSong.songId || !_this.currentSong.songId)) {
  563. _this.addFirstPrivatePlaylistSongToQueue();
  564. }
  565. });
  566. _this.socket.on('event:stations.pause', data => {
  567. _this.pauseLocalStation();
  568. });
  569. _this.socket.on('event:stations.resume', data => {
  570. _this.timePaused = data.timePaused;
  571. _this.resumeLocalStation();
  572. });
  573. _this.socket.on('event:stations.remove', () => {
  574. location.href = '/';
  575. });
  576. _this.socket.on('event:song.like', data => {
  577. if (!this.noSong) {
  578. if (data.songId === _this.currentSong.songId) {
  579. _this.currentSong.dislikes = data.dislikes;
  580. _this.currentSong.likes = data.likes;
  581. }
  582. }
  583. });
  584. _this.socket.on('event:song.dislike', data => {
  585. if (!this.noSong) {
  586. if (data.songId === _this.currentSong.songId) {
  587. _this.currentSong.dislikes = data.dislikes;
  588. _this.currentSong.likes = data.likes;
  589. }
  590. }
  591. });
  592. _this.socket.on('event:song.unlike', data => {
  593. if (!this.noSong) {
  594. if (data.songId === _this.currentSong.songId) {
  595. _this.currentSong.dislikes = data.dislikes;
  596. _this.currentSong.likes = data.likes;
  597. }
  598. }
  599. });
  600. _this.socket.on('event:song.undislike', data => {
  601. if (!this.noSong) {
  602. if (data.songId === _this.currentSong.songId) {
  603. _this.currentSong.dislikes = data.dislikes;
  604. _this.currentSong.likes = data.likes;
  605. }
  606. }
  607. });
  608. _this.socket.on('event:song.newRatings', data => {
  609. if (!this.noSong) {
  610. if (data.songId === _this.currentSong.songId) {
  611. _this.liked = data.liked;
  612. _this.disliked = data.disliked;
  613. }
  614. }
  615. });
  616. _this.socket.on('event:queue.update', queue => {
  617. if (this.type === 'community') this.songsList = queue;
  618. });
  619. _this.socket.on('event:song.voteSkipSong', () => {
  620. if (this.currentSong) this.currentSong.skipVotes++;
  621. });
  622. _this.socket.on('event:privatePlaylist.selected', (playlistId) => {
  623. if (this.type === 'community') {
  624. this.station.privatePlaylist = playlistId;
  625. }
  626. });
  627. _this.socket.on('event:partyMode.updated', (partyMode) => {
  628. if (this.type === 'community') {
  629. this.station.partyMode = partyMode;
  630. }
  631. });
  632. _this.socket.on('event:newOfficialPlaylist', (playlist) => {
  633. console.log(playlist);
  634. if (this.type === 'official') {
  635. this.songsList = playlist;
  636. }
  637. });
  638. _this.socket.on('event:users.updated', users => {
  639. _this.users = users;
  640. });
  641. _this.socket.on('event:userCount.updated', userCount => {
  642. _this.userCount = userCount;
  643. });
  644. });
  645. let volume = parseInt(localStorage.getItem("volume"));
  646. volume = (typeof volume === "number" && !isNaN(volume)) ? volume : 20;
  647. localStorage.setItem("volume", volume);
  648. $("#volumeSlider").val(volume);
  649. },
  650. components: {
  651. OfficialHeader,
  652. CommunityHeader,
  653. SongQueue,
  654. AddToPlaylist,
  655. EditPlaylist,
  656. CreatePlaylist,
  657. EditStation,
  658. Report,
  659. SongsListSidebar,
  660. PlaylistSidebar,
  661. UsersSidebar,
  662. MainFooter
  663. }
  664. }
  665. </script>
  666. <style lang="scss">
  667. .no-song {
  668. color: #03A9F4;
  669. text-align: center;
  670. }
  671. #volumeSlider {
  672. padding: 0 15px;
  673. background: transparent;
  674. }
  675. .volume-slider-wrapper {
  676. margin-top: 0;
  677. position: relative;
  678. display: flex;
  679. align-items: center;
  680. .material-icons { user-select: none; }
  681. }
  682. .material-icons { cursor: pointer; }
  683. .stationDisplayName {
  684. color: white !important;
  685. }
  686. .add-to-playlist {
  687. display: flex;
  688. align-items: center;
  689. justify-content: center;
  690. }
  691. .slideout {
  692. top: 50px;
  693. height: 100%;
  694. position: fixed;
  695. right: 0;
  696. width: 350px;
  697. background-color: white;
  698. box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
  699. .slideout-header {
  700. text-align: center;
  701. background-color: rgb(3, 169, 244) !important;
  702. margin: 0;
  703. padding-top: 5px;
  704. padding-bottom: 7px;
  705. color: white;
  706. }
  707. .slideout-content {
  708. height: 100%;
  709. }
  710. }
  711. .modal-large {
  712. width: 75%;
  713. }
  714. .station {
  715. flex: 1 0 auto;
  716. padding-top: 0.5vw;
  717. transition: all 0.1s;
  718. margin: 0 auto;
  719. max-width: 100%;
  720. width: 90%;
  721. @media only screen and (min-width: 993px) {
  722. width: 70%;
  723. }
  724. @media only screen and (min-width: 601px) {
  725. width: 85%;
  726. }
  727. @media (min-width: 999px) {
  728. .mobile-only {
  729. display: none;
  730. }
  731. .desktop-only {
  732. display: block;
  733. }
  734. }
  735. @media (max-width: 998px) {
  736. .mobile-only {
  737. display: block;
  738. }
  739. .desktop-only {
  740. display: none;
  741. visibility: hidden;
  742. }
  743. }
  744. .mobile-only {
  745. text-align: center;
  746. }
  747. .playlistCard {
  748. margin: 10px;
  749. position: relative;
  750. padding-bottom: calc(31.25% + 7px);
  751. height: 0;
  752. overflow-y: scroll;
  753. .title {
  754. background-color: rgb(3, 169, 244);
  755. text-align: center;
  756. padding: 10px;
  757. color: white;
  758. font-weight: 600;
  759. }
  760. .media { padding: 0 25px; }
  761. .media-content .content {
  762. min-height: 64px;
  763. max-height: 64px;
  764. display: flex;
  765. align-items: center;
  766. }
  767. .content p strong { word-break: break-word; }
  768. .content p small { word-break: break-word; }
  769. .add-to-queue {
  770. width: 100%;
  771. margin-top: 25px;
  772. height: 40px;
  773. border-radius: 0;
  774. background: rgb(3, 169, 244);
  775. color: #fff !important;
  776. border: 0;
  777. &:active, &:focus { border: 0; }
  778. }
  779. .add-to-queue:focus { background: #029ce3; }
  780. .media-right { line-height: 64px; }
  781. }
  782. input[type=range] {
  783. -webkit-appearance: none;
  784. width: 100%;
  785. margin: 7.3px 0;
  786. }
  787. input[type=range]:focus {
  788. outline: none;
  789. }
  790. input[type=range]::-webkit-slider-runnable-track {
  791. width: 100%;
  792. height: 5.2px;
  793. cursor: pointer;
  794. box-shadow: 0;
  795. background: #c2c0c2;
  796. border-radius: 0;
  797. border: 0;
  798. }
  799. input[type=range]::-webkit-slider-thumb {
  800. box-shadow: 0;
  801. border: 0;
  802. height: 19px;
  803. width: 19px;
  804. border-radius: 15px;
  805. background: #03a9f4;
  806. cursor: pointer;
  807. -webkit-appearance: none;
  808. margin-top: -6.5px;
  809. }
  810. input[type=range]::-moz-range-track {
  811. width: 100%;
  812. height: 5.2px;
  813. cursor: pointer;
  814. box-shadow: 0;
  815. background: #c2c0c2;
  816. border-radius: 0;
  817. border: 0;
  818. }
  819. input[type=range]::-moz-range-thumb {
  820. box-shadow: 0;
  821. border: 0;
  822. height: 19px;
  823. width: 19px;
  824. border-radius: 15px;
  825. background: #03a9f4;
  826. cursor: pointer;
  827. -webkit-appearance: none;
  828. margin-top: -6.5px;
  829. }
  830. input[type=range]::-ms-track {
  831. width: 100%;
  832. height: 5.2px;
  833. cursor: pointer;
  834. box-shadow: 0;
  835. background: #c2c0c2;
  836. border-radius: 1.3px;
  837. }
  838. input[type=range]::-ms-fill-lower {
  839. background: #c2c0c2;
  840. border: 0;
  841. border-radius: 0;
  842. box-shadow: 0;
  843. }
  844. input[type=range]::-ms-fill-upper {
  845. background: #c2c0c2;
  846. border: 0;
  847. border-radius: 0;
  848. box-shadow: 0;
  849. }
  850. input[type=range]::-ms-thumb {
  851. box-shadow: 0;
  852. border: 0;
  853. height: 15px;
  854. width: 15px;
  855. border-radius: 15px;
  856. background: #03a9f4;
  857. cursor: pointer;
  858. -webkit-appearance: none;
  859. margin-top: 1.5px;
  860. }
  861. .video-container {
  862. position: relative;
  863. padding-bottom: 56.25%;
  864. height: 0;
  865. overflow: hidden;
  866. iframe {
  867. position: absolute;
  868. top: 0;
  869. left: 0;
  870. width: 100%;
  871. height: 100%;
  872. }
  873. }
  874. .video-col {
  875. padding-right: 0.75rem;
  876. padding-left: 0.75rem;
  877. }
  878. }
  879. .room-title {
  880. left: 50%;
  881. -webkit-transform: translateX(-50%);
  882. transform: translateX(-50%);
  883. font-size: 2.1em;
  884. }
  885. #ratings {
  886. span {
  887. font-size: 1.68rem;
  888. }
  889. i {
  890. color: #9e9e9e !important;
  891. cursor: pointer;
  892. transition: 0.1s color;
  893. }
  894. }
  895. #time-display {
  896. margin-top: 30px;
  897. float: right;
  898. }
  899. #thumbs_up:hover, #thumbs_up.liked {
  900. color: #87D37C !important;
  901. }
  902. #thumbs_down:hover, #thumbs_down.disliked {
  903. color: #EC644B !important;
  904. }
  905. #song-thumbnail {
  906. max-width: 100%;
  907. width: 85%;
  908. }
  909. .seeker-bar-container {
  910. position: relative;
  911. height: 7px;
  912. display: block;
  913. width: 100%;
  914. overflow: hidden;
  915. }
  916. .seeker-bar {
  917. top: 0;
  918. left: 0;
  919. bottom: 0;
  920. position: absolute;
  921. }
  922. ul {
  923. list-style: none;
  924. margin: 0;
  925. display: block;
  926. }
  927. h1, h2, h3, h4, h5, h6 {
  928. font-weight: 400;
  929. line-height: 1.1;
  930. }
  931. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  932. font-weight: inherit;
  933. }
  934. h1 {
  935. font-size: 4.2rem;
  936. line-height: 110%;
  937. margin: 2.1rem 0 1.68rem 0;
  938. }
  939. h2 {
  940. font-size: 3.56rem;
  941. line-height: 110%;
  942. margin: 1.78rem 0 1.424rem 0;
  943. }
  944. h3 {
  945. font-size: 2.92rem;
  946. line-height: 110%;
  947. margin: 1.46rem 0 1.168rem 0;
  948. }
  949. h4 {
  950. font-size: 2.28rem;
  951. line-height: 110%;
  952. margin: 1.14rem 0 0.912rem 0;
  953. }
  954. h5 {
  955. font-size: 1.64rem;
  956. line-height: 110%;
  957. margin: 0.82rem 0 0.656rem 0;
  958. }
  959. h6 {
  960. font-size: 1rem;
  961. line-height: 110%;
  962. margin: 0.5rem 0 0.4rem 0;
  963. }
  964. .thin {
  965. font-weight: 200;
  966. }
  967. .left {
  968. float: left !important;
  969. }
  970. .right {
  971. float: right !important;
  972. }
  973. .light-blue {
  974. background-color: #03a9f4 !important;
  975. }
  976. .white {
  977. background-color: #FFFFFF !important;
  978. }
  979. .btn-search {
  980. font-size: 14px;
  981. }
  982. .menu { padding: 0 10px; }
  983. .menu-list li a:hover { color: #000 !important; }
  984. .menu-list li {
  985. display: flex;
  986. justify-content: space-between;
  987. }
  988. .menu-list a {
  989. /*padding: 0 10px !important;*/
  990. }
  991. .menu-list a:hover {
  992. background-color : transparent;
  993. }
  994. .icons-group { display: flex; }
  995. #like, #dislike {
  996. position: relative;
  997. }
  998. .behind {
  999. z-index: -1;
  1000. }
  1001. .behind:focus {
  1002. z-index: 0;
  1003. }
  1004. .progress {
  1005. width: 50px;
  1006. animation: rotate 0.8s infinite linear;
  1007. border: 8px solid #03A9F4;
  1008. border-right-color: transparent;
  1009. height: 50px;
  1010. position: absolute;
  1011. top: 50%;
  1012. left: 50%;
  1013. }
  1014. @keyframes rotate {
  1015. 0% { transform: rotate(0deg); }
  1016. 100% { transform: rotate(360deg); }
  1017. }
  1018. </style>