Station.vue 36 KB

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