Station.vue 33 KB

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