Station.vue 33 KB

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