Station.vue 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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. position: relative;
  740. padding-bottom: calc(31.25% + 7px);
  741. height: 0;
  742. overflow-y: scroll;
  743. .title {
  744. background-color: rgb(3, 169, 244);
  745. text-align: center;
  746. padding: 10px;
  747. color: white;
  748. font-weight: 600;
  749. }
  750. .media { padding: 0 25px; }
  751. .media-content .content {
  752. min-height: 64px;
  753. max-height: 64px;
  754. display: flex;
  755. align-items: center;
  756. }
  757. .content p strong { word-break: break-word; }
  758. .content p small { word-break: break-word; }
  759. .add-to-queue {
  760. width: 100%;
  761. margin-top: 25px;
  762. height: 40px;
  763. border-radius: 0;
  764. background: rgb(3, 169, 244);
  765. color: #fff !important;
  766. border: 0;
  767. &:active, &:focus { border: 0; }
  768. }
  769. .add-to-queue:focus { background: #029ce3; }
  770. .media-right { line-height: 64px; }
  771. }
  772. input[type=range] {
  773. -webkit-appearance: none;
  774. width: 100%;
  775. margin: 7.3px 0;
  776. }
  777. input[type=range]:focus {
  778. outline: none;
  779. }
  780. input[type=range]::-webkit-slider-runnable-track {
  781. width: 100%;
  782. height: 5.2px;
  783. cursor: pointer;
  784. box-shadow: 0;
  785. background: #c2c0c2;
  786. border-radius: 0;
  787. border: 0;
  788. }
  789. input[type=range]::-webkit-slider-thumb {
  790. box-shadow: 0;
  791. border: 0;
  792. height: 19px;
  793. width: 19px;
  794. border-radius: 15px;
  795. background: #03a9f4;
  796. cursor: pointer;
  797. -webkit-appearance: none;
  798. margin-top: -6.5px;
  799. }
  800. input[type=range]::-moz-range-track {
  801. width: 100%;
  802. height: 5.2px;
  803. cursor: pointer;
  804. box-shadow: 0;
  805. background: #c2c0c2;
  806. border-radius: 0;
  807. border: 0;
  808. }
  809. input[type=range]::-moz-range-thumb {
  810. box-shadow: 0;
  811. border: 0;
  812. height: 19px;
  813. width: 19px;
  814. border-radius: 15px;
  815. background: #03a9f4;
  816. cursor: pointer;
  817. -webkit-appearance: none;
  818. margin-top: -6.5px;
  819. }
  820. input[type=range]::-ms-track {
  821. width: 100%;
  822. height: 5.2px;
  823. cursor: pointer;
  824. box-shadow: 0;
  825. background: #c2c0c2;
  826. border-radius: 1.3px;
  827. }
  828. input[type=range]::-ms-fill-lower {
  829. background: #c2c0c2;
  830. border: 0;
  831. border-radius: 0;
  832. box-shadow: 0;
  833. }
  834. input[type=range]::-ms-fill-upper {
  835. background: #c2c0c2;
  836. border: 0;
  837. border-radius: 0;
  838. box-shadow: 0;
  839. }
  840. input[type=range]::-ms-thumb {
  841. box-shadow: 0;
  842. border: 0;
  843. height: 15px;
  844. width: 15px;
  845. border-radius: 15px;
  846. background: #03a9f4;
  847. cursor: pointer;
  848. -webkit-appearance: none;
  849. margin-top: 1.5px;
  850. }
  851. .video-container {
  852. position: relative;
  853. padding-bottom: 56.25%;
  854. height: 0;
  855. overflow: hidden;
  856. iframe {
  857. position: absolute;
  858. top: 0;
  859. left: 0;
  860. width: 100%;
  861. height: 100%;
  862. }
  863. }
  864. .video-col {
  865. padding-right: 0.75rem;
  866. padding-left: 0.75rem;
  867. }
  868. }
  869. .room-title {
  870. left: 50%;
  871. -webkit-transform: translateX(-50%);
  872. transform: translateX(-50%);
  873. font-size: 2.1em;
  874. }
  875. #ratings {
  876. span {
  877. font-size: 1.68rem;
  878. }
  879. i {
  880. color: #9e9e9e !important;
  881. cursor: pointer;
  882. transition: 0.1s color;
  883. }
  884. }
  885. #time-display {
  886. margin-top: 30px;
  887. float: right;
  888. }
  889. #thumbs_up:hover, #thumbs_up.liked {
  890. color: #87D37C !important;
  891. }
  892. #thumbs_down:hover, #thumbs_down.disliked {
  893. color: #EC644B !important;
  894. }
  895. #song-thumbnail {
  896. max-width: 100%;
  897. width: 85%;
  898. }
  899. .seeker-bar-container {
  900. position: relative;
  901. height: 7px;
  902. display: block;
  903. width: 100%;
  904. overflow: hidden;
  905. }
  906. .seeker-bar {
  907. top: 0;
  908. left: 0;
  909. bottom: 0;
  910. position: absolute;
  911. }
  912. ul {
  913. list-style: none;
  914. margin: 0;
  915. display: block;
  916. }
  917. h1, h2, h3, h4, h5, h6 {
  918. font-weight: 400;
  919. line-height: 1.1;
  920. }
  921. h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {
  922. font-weight: inherit;
  923. }
  924. h1 {
  925. font-size: 4.2rem;
  926. line-height: 110%;
  927. margin: 2.1rem 0 1.68rem 0;
  928. }
  929. h2 {
  930. font-size: 3.56rem;
  931. line-height: 110%;
  932. margin: 1.78rem 0 1.424rem 0;
  933. }
  934. h3 {
  935. font-size: 2.92rem;
  936. line-height: 110%;
  937. margin: 1.46rem 0 1.168rem 0;
  938. }
  939. h4 {
  940. font-size: 2.28rem;
  941. line-height: 110%;
  942. margin: 1.14rem 0 0.912rem 0;
  943. }
  944. h5 {
  945. font-size: 1.64rem;
  946. line-height: 110%;
  947. margin: 0.82rem 0 0.656rem 0;
  948. }
  949. h6 {
  950. font-size: 1rem;
  951. line-height: 110%;
  952. margin: 0.5rem 0 0.4rem 0;
  953. }
  954. .thin {
  955. font-weight: 200;
  956. }
  957. .left {
  958. float: left !important;
  959. }
  960. .right {
  961. float: right !important;
  962. }
  963. .light-blue {
  964. background-color: #03a9f4 !important;
  965. }
  966. .white {
  967. background-color: #FFFFFF !important;
  968. }
  969. .btn-search {
  970. font-size: 14px;
  971. }
  972. .menu { padding: 0 10px; }
  973. .menu-list li a:hover { color: #000 !important; }
  974. .menu-list li {
  975. display: flex;
  976. justify-content: space-between;
  977. }
  978. .menu-list a {
  979. /*padding: 0 10px !important;*/
  980. }
  981. .menu-list a:hover {
  982. background-color : transparent;
  983. }
  984. .icons-group { display: flex; }
  985. #like, #dislike {
  986. position: relative;
  987. }
  988. .behind {
  989. z-index: -1;
  990. }
  991. .behind:focus {
  992. z-index: 0;
  993. }
  994. .progress {
  995. width: 50px;
  996. animation: rotate 0.8s infinite linear;
  997. border: 8px solid #03A9F4;
  998. border-right-color: transparent;
  999. height: 50px;
  1000. position: absolute;
  1001. top: 50%;
  1002. left: 50%;
  1003. }
  1004. @keyframes rotate {
  1005. 0% { transform: rotate(0deg); }
  1006. 100% { transform: rotate(360deg); }
  1007. }
  1008. </style>