index.vue 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. <template>
  2. <div :style="'--station-theme: ' + theme">
  3. <metadata v-if="exists && !loading" :title="`${station.displayName}`" />
  4. <metadata v-else-if="!exists && !loading" :title="`Not found`" />
  5. <main-header v-if="exists" />
  6. <div
  7. id="station-outer-container"
  8. :style="[!exists ? { margin: 0, padding: 0 } : {}]"
  9. >
  10. <div v-show="loading" class="progress" />
  11. <div
  12. v-show="!loading && exists"
  13. id="station-inner-container"
  14. :class="{ 'nothing-here': noSong }"
  15. >
  16. <div id="station-left-column" class="column">
  17. <div class="player-container quadrant" v-show="!noSong">
  18. <div id="video-container">
  19. <div
  20. id="stationPlayer"
  21. style="width: 100%; height: 100%"
  22. />
  23. <div
  24. class="player-cannot-autoplay"
  25. v-if="!canAutoplay"
  26. >
  27. <p>
  28. Please click anywhere on the screen for the
  29. video to start
  30. </p>
  31. </div>
  32. </div>
  33. <div id="seeker-bar-container">
  34. <div id="seeker-bar" style="width: 0%" />
  35. </div>
  36. <div id="control-bar-container">
  37. <div id="left-buttons">
  38. <!-- Debug Box -->
  39. <button
  40. class="button is-primary"
  41. @click="togglePlayerDebugBox()"
  42. @dblclick="resetPlayerDebugBox()"
  43. >
  44. <i class="material-icons icon-with-button">
  45. bug_report
  46. </i>
  47. </button>
  48. <!-- Local Pause/Resume Button -->
  49. <button
  50. class="button is-primary"
  51. @click="resumeLocalStation()"
  52. id="local-resume"
  53. v-if="localPaused"
  54. >
  55. <i class="material-icons">play_arrow</i>
  56. </button>
  57. <button
  58. class="button is-primary"
  59. @click="pauseLocalStation()"
  60. id="local-pause"
  61. v-else
  62. >
  63. <i class="material-icons">pause</i>
  64. </button>
  65. <!-- Vote to Skip Button -->
  66. <button
  67. v-if="loggedIn"
  68. class="button is-primary"
  69. @click="voteSkipStation()"
  70. >
  71. <i class="material-icons icon-with-button"
  72. >skip_next</i
  73. >
  74. {{ currentSong.skipVotes }}
  75. </button>
  76. </div>
  77. <div id="duration">
  78. <p>
  79. {{ timeElapsed }} /
  80. {{ utils.formatTime(currentSong.duration) }}
  81. </p>
  82. </div>
  83. <p id="volume-control">
  84. <i
  85. v-if="muted"
  86. class="material-icons"
  87. @click="toggleMute()"
  88. >volume_mute</i
  89. >
  90. <i
  91. v-else
  92. class="material-icons"
  93. @click="toggleMute()"
  94. >volume_down</i
  95. >
  96. <input
  97. v-model="volumeSliderValue"
  98. type="range"
  99. min="0"
  100. max="10000"
  101. class="volume-slider active"
  102. @change="changeVolume()"
  103. @input="changeVolume()"
  104. />
  105. <i
  106. class="material-icons"
  107. @click="increaseVolume()"
  108. >volume_up</i
  109. >
  110. </p>
  111. <div id="right-buttons" v-if="loggedIn">
  112. <!-- Ratings (Like/Dislike) Buttons -->
  113. <div
  114. id="ratings"
  115. v-if="
  116. currentSong.likes !== -1 &&
  117. currentSong.dislikes !== -1
  118. "
  119. :class="{
  120. liked: liked,
  121. disliked: disliked
  122. }"
  123. >
  124. <!-- Like Song Button -->
  125. <button
  126. class="button is-success"
  127. id="like-song"
  128. @click="toggleLike()"
  129. >
  130. <i
  131. class="material-icons icon-with-button"
  132. :class="{ liked: liked }"
  133. >thumb_up_alt</i
  134. >{{ currentSong.likes }}
  135. </button>
  136. <!-- Dislike Song Button -->
  137. <button
  138. class="button is-danger"
  139. id="dislike-song"
  140. @click="toggleDislike()"
  141. >
  142. <i
  143. class="material-icons icon-with-button"
  144. :class="{
  145. disliked: disliked
  146. }"
  147. >thumb_down_alt</i
  148. >{{ currentSong.dislikes }}
  149. </button>
  150. </div>
  151. <!-- Add Song To Playlist Button & Dropdown -->
  152. <div id="add-song-to-playlist">
  153. <div class="control has-addons">
  154. <button
  155. class="button is-primary"
  156. @click="
  157. showPlaylistDropdown = !showPlaylistDropdown
  158. "
  159. >
  160. <i class="material-icons">queue</i>
  161. </button>
  162. <button
  163. class="button"
  164. id="dropdown-toggle"
  165. @click="
  166. showPlaylistDropdown = !showPlaylistDropdown
  167. "
  168. >
  169. <i class="material-icons">
  170. {{
  171. showPlaylistDropdown
  172. ? "expand_more"
  173. : "expand_less"
  174. }}
  175. </i>
  176. </button>
  177. </div>
  178. <add-to-playlist-dropdown
  179. v-if="showPlaylistDropdown"
  180. />
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <p class="player-container nothing-here-text" v-if="noSong">
  186. No song is currently playing
  187. </p>
  188. <div v-if="!noSong" id="current-next-row">
  189. <div
  190. id="currently-playing-container"
  191. class="quadrant"
  192. :class="{ 'no-currently-playing': noSong }"
  193. >
  194. <currently-playing />
  195. <!-- <p v-else class="nothing-here-text">
  196. No song is currently playing
  197. </p> -->
  198. </div>
  199. </div>
  200. </div>
  201. <div id="station-right-column" class="column">
  202. <div id="about-station-container" class="quadrant">
  203. <div id="station-info">
  204. <div class="row" id="station-name">
  205. <h1>{{ station.displayName }}</h1>
  206. <a href="#">
  207. <!-- Favorite Station Button -->
  208. <i
  209. v-if="loggedIn && station.isFavorited"
  210. @click.prevent="unfavoriteStation()"
  211. class="material-icons"
  212. >star</i
  213. >
  214. <i
  215. v-if="loggedIn && !station.isFavorited"
  216. @click.prevent="favoriteStation()"
  217. class="material-icons"
  218. >star_border</i
  219. >
  220. </a>
  221. </div>
  222. <p>{{ station.description }}</p>
  223. </div>
  224. <div id="admin-buttons" v-if="isOwnerOrAdmin()">
  225. <!-- (Admin) Pause/Resume Button -->
  226. <button
  227. class="button is-danger"
  228. v-if="stationPaused"
  229. @click="resumeStation()"
  230. >
  231. <i class="material-icons icon-with-button"
  232. >play_arrow</i
  233. >
  234. <span class="optional-desktop-only-text">
  235. Resume Station
  236. </span>
  237. </button>
  238. <button
  239. class="button is-danger"
  240. @click="pauseStation()"
  241. v-else
  242. >
  243. <i class="material-icons icon-with-button"
  244. >pause</i
  245. >
  246. <span class="optional-desktop-only-text">
  247. Pause Station
  248. </span>
  249. </button>
  250. <!-- (Admin) Skip Button -->
  251. <button
  252. class="button is-danger"
  253. @click="skipStation()"
  254. >
  255. <i class="material-icons icon-with-button"
  256. >skip_next</i
  257. >
  258. <span class="optional-desktop-only-text">
  259. Force Skip
  260. </span>
  261. </button>
  262. <!-- (Admin) Station Settings Button -->
  263. <button
  264. class="button is-primary"
  265. @click="openSettings()"
  266. >
  267. <i class="material-icons icon-with-button"
  268. >settings</i
  269. >
  270. <span class="optional-desktop-only-text">
  271. Station settings
  272. </span>
  273. </button>
  274. </div>
  275. </div>
  276. <div id="sidebar-container" class="quadrant">
  277. <station-sidebar />
  278. </div>
  279. </div>
  280. </div>
  281. <song-queue v-if="modals.addSongToQueue" />
  282. <edit-playlist v-if="modals.editPlaylist" />
  283. <create-playlist v-if="modals.createPlaylist" />
  284. <edit-station v-if="modals.editStation" store="station" />
  285. <report v-if="modals.report" />
  286. </div>
  287. <main-footer v-if="exists" />
  288. <edit-song
  289. v-if="modals.editSong"
  290. :song-id="editingSongId"
  291. song-type="songs"
  292. sector="station"
  293. />
  294. <floating-box id="player-debug-box" ref="playerDebugBox">
  295. <template #body>
  296. <span><b>YouTube id</b>: {{ currentSong.songId }}</span>
  297. <span><b>Duration</b>: {{ currentSong.duration }}</span>
  298. <span
  299. ><b>Skip duration</b>: {{ currentSong.skipDuration }}</span
  300. >
  301. <span><b>Can autoplay</b>: {{ canAutoplay }}</span>
  302. <span
  303. ><b>Attempts to play video</b>:
  304. {{ attemptsToPlayVideo }}</span
  305. >
  306. <span
  307. ><b>Last time requested if can autoplay</b>:
  308. {{ lastTimeRequestedIfCanAutoplay }}</span
  309. >
  310. <span><b>Loading</b>: {{ loading }}</span>
  311. <span><b>Playback rate</b>: {{ playbackRate }}</span>
  312. <span><b>Player ready</b>: {{ playerReady }}</span>
  313. <span><b>Ready</b>: {{ ready }}</span>
  314. <span><b>Seeking</b>: {{ seeking }}</span>
  315. <span><b>System difference</b>: {{ systemDifference }}</span>
  316. <span><b>Time before paused</b>: {{ timeBeforePause }}</span>
  317. <span><b>Time elapsed</b>: {{ timeElapsed }}</span>
  318. <span><b>Time paused</b>: {{ timePaused }}</span>
  319. <span><b>Volume slider value</b>: {{ volumeSliderValue }}</span>
  320. <span><b>Local paused</b>: {{ localPaused }}</span>
  321. <span><b>No song</b>: {{ noSong }}</span>
  322. <span
  323. ><b>Private playlist queue selected</b>:
  324. {{ privatePlaylistQueueSelected }}</span
  325. >
  326. <span><b>Station paused</b>: {{ stationPaused }}</span>
  327. <span
  328. ><b>Station Genres</b>:
  329. {{ station.genres.join(", ") }}</span
  330. >
  331. <span
  332. ><b>Station Blacklisted Genres</b>:
  333. {{ station.blacklistedGenres.join(", ") }}</span
  334. >
  335. </template>
  336. </floating-box>
  337. <Z404 v-if="!exists"></Z404>
  338. </div>
  339. </template>
  340. <script>
  341. import { mapState, mapActions } from "vuex";
  342. import Toast from "toasters";
  343. import MainHeader from "../../components/layout/MainHeader.vue";
  344. import MainFooter from "../../components/layout/MainFooter.vue";
  345. import Z404 from "../404.vue";
  346. import FloatingBox from "../../components/ui/FloatingBox.vue";
  347. import AddToPlaylistDropdown from "./components/AddToPlaylistDropdown.vue";
  348. import io from "../../io";
  349. import keyboardShortcuts from "../../keyboardShortcuts";
  350. import utils from "../../../js/utils";
  351. import CurrentlyPlaying from "./components/CurrentlyPlaying.vue";
  352. import StationSidebar from "./components/Sidebar/index.vue";
  353. export default {
  354. components: {
  355. MainHeader,
  356. MainFooter,
  357. SongQueue: () => import("./AddSongToQueue.vue"),
  358. EditPlaylist: () => import("../../components/modals/EditPlaylist.vue"),
  359. CreatePlaylist: () =>
  360. import("../../components/modals/CreatePlaylist.vue"),
  361. EditStation: () => import("../../components/modals/EditStation.vue"),
  362. Report: () => import("./Report.vue"),
  363. Z404,
  364. FloatingBox,
  365. CurrentlyPlaying,
  366. StationSidebar,
  367. AddToPlaylistDropdown,
  368. EditSong: () => import("../../components/modals/EditSong.vue")
  369. },
  370. data() {
  371. return {
  372. utils,
  373. title: "Station",
  374. loading: true,
  375. ready: false,
  376. exists: true,
  377. playerReady: false,
  378. player: undefined,
  379. timePaused: 0,
  380. muted: false,
  381. timeElapsed: "0:00",
  382. liked: false,
  383. disliked: false,
  384. timeBeforePause: 0,
  385. skipVotes: 0,
  386. automaticallyRequestedSongId: null,
  387. systemDifference: 0,
  388. attemptsToPlayVideo: 0,
  389. canAutoplay: true,
  390. lastTimeRequestedIfCanAutoplay: 0,
  391. seeking: false,
  392. playbackRate: 1,
  393. volumeSliderValue: 0,
  394. showPlaylistDropdown: false,
  395. editingSongId: "",
  396. theme: "rgb(2, 166, 242)"
  397. };
  398. },
  399. computed: {
  400. ...mapState("modals", {
  401. modals: state => state.modals.station
  402. }),
  403. ...mapState("station", {
  404. station: state => state.station,
  405. currentSong: state => state.currentSong,
  406. songsList: state => state.songsList,
  407. stationPaused: state => state.stationPaused,
  408. localPaused: state => state.localPaused,
  409. noSong: state => state.noSong,
  410. privatePlaylistQueueSelected: state =>
  411. state.privatePlaylistQueueSelected
  412. }),
  413. ...mapState({
  414. loggedIn: state => state.user.auth.loggedIn,
  415. userId: state => state.user.auth.userId,
  416. role: state => state.user.auth.role
  417. })
  418. },
  419. mounted() {
  420. window.scrollTo(0, 0);
  421. Date.currently = () => {
  422. return new Date().getTime() + this.systemDifference;
  423. };
  424. this.stationName = this.$route.params.id;
  425. window.stationInterval = 0;
  426. io.getSocket(socket => {
  427. this.socket = socket;
  428. if (this.socket.connected) this.join();
  429. io.onConnect(this.join);
  430. this.socket.emit("stations.existsByName", this.stationName, res => {
  431. if (res.status === "failure" || !res.exists) {
  432. this.loading = false;
  433. this.exists = false;
  434. }
  435. });
  436. this.socket.on("event:songs.next", data => {
  437. const previousSong = this.currentSong.songId
  438. ? this.currentSong
  439. : null;
  440. this.updatePreviousSong(previousSong);
  441. const { currentSong } = data;
  442. if (currentSong && !currentSong.thumbnail)
  443. currentSong.ytThumbnail = `https://img.youtube.com/vi/${currentSong.songId}/mqdefault.jpg`;
  444. this.updateCurrentSong(currentSong || {});
  445. this.startedAt = data.startedAt;
  446. this.updateStationPaused(data.paused);
  447. this.timePaused = data.timePaused;
  448. if (currentSong) {
  449. this.updateNoSong(false);
  450. if (this.currentSong.artists)
  451. this.currentSong.artists = this.currentSong.artists.join(
  452. ", "
  453. );
  454. if (!this.playerReady) this.youtubeReady();
  455. else this.playVideo();
  456. this.socket.emit(
  457. "songs.getOwnSongRatings",
  458. data.currentSong.songId,
  459. song => {
  460. if (this.currentSong.songId === song.songId) {
  461. this.liked = song.liked;
  462. this.disliked = song.disliked;
  463. if (
  464. this.autoSkipDisliked &&
  465. song.disliked === true
  466. ) {
  467. this.voteSkipStation();
  468. new Toast({
  469. content:
  470. "Automatically voted to skip disliked song.",
  471. timeout: 4000
  472. });
  473. }
  474. }
  475. }
  476. );
  477. } else {
  478. if (this.playerReady) this.player.pauseVideo();
  479. this.updateNoSong(true);
  480. }
  481. let isInQueue = false;
  482. this.songsList.forEach(queueSong => {
  483. if (queueSong.requestedBy === this.userId) isInQueue = true;
  484. });
  485. if (
  486. !isInQueue &&
  487. this.privatePlaylistQueueSelected &&
  488. (this.automaticallyRequestedSongId !==
  489. this.currentSong.songId ||
  490. !this.currentSong.songId)
  491. ) {
  492. this.addFirstPrivatePlaylistSongToQueue();
  493. }
  494. });
  495. this.socket.on("event:stations.pause", data => {
  496. this.pausedAt = data.pausedAt;
  497. this.updateStationPaused(true);
  498. this.pauseLocalPlayer();
  499. });
  500. this.socket.on("event:stations.resume", data => {
  501. this.timePaused = data.timePaused;
  502. this.updateStationPaused(false);
  503. if (!this.localPaused) this.resumeLocalPlayer();
  504. });
  505. this.socket.on("event:stations.remove", () => {
  506. window.location.href = "/";
  507. return true;
  508. });
  509. this.socket.on("event:song.like", data => {
  510. if (!this.noSong) {
  511. if (data.songId === this.currentSong.songId) {
  512. this.currentSong.dislikes = data.dislikes;
  513. this.currentSong.likes = data.likes;
  514. }
  515. }
  516. });
  517. this.socket.on("event:song.dislike", data => {
  518. if (!this.noSong) {
  519. if (data.songId === this.currentSong.songId) {
  520. this.currentSong.dislikes = data.dislikes;
  521. this.currentSong.likes = data.likes;
  522. }
  523. }
  524. });
  525. this.socket.on("event:song.unlike", data => {
  526. if (!this.noSong) {
  527. if (data.songId === this.currentSong.songId) {
  528. this.currentSong.dislikes = data.dislikes;
  529. this.currentSong.likes = data.likes;
  530. }
  531. }
  532. });
  533. this.socket.on("event:song.undislike", data => {
  534. if (!this.noSong) {
  535. if (data.songId === this.currentSong.songId) {
  536. this.currentSong.dislikes = data.dislikes;
  537. this.currentSong.likes = data.likes;
  538. }
  539. }
  540. });
  541. this.socket.on("event:song.newRatings", data => {
  542. if (!this.noSong) {
  543. if (data.songId === this.currentSong.songId) {
  544. this.liked = data.liked;
  545. this.disliked = data.disliked;
  546. }
  547. }
  548. });
  549. this.socket.on("event:queue.update", queue => {
  550. if (this.station.type === "community")
  551. this.updateSongsList(queue);
  552. });
  553. this.socket.on("event:song.voteSkipSong", () => {
  554. if (this.currentSong) this.currentSong.skipVotes += 1;
  555. });
  556. this.socket.on("event:privatePlaylist.selected", playlistId => {
  557. if (this.station.type === "community") {
  558. this.station.privatePlaylist = playlistId;
  559. }
  560. });
  561. this.socket.on("event:privatePlaylist.deselected", () => {
  562. if (this.station.type === "community") {
  563. this.station.privatePlaylist = null;
  564. }
  565. });
  566. this.socket.on("event:partyMode.updated", partyMode => {
  567. if (this.station.type === "community") {
  568. this.station.partyMode = partyMode;
  569. }
  570. });
  571. this.socket.on("event:theme.updated", theme => {
  572. this.station.theme = theme;
  573. if (theme === "blue") {
  574. this.theme = "rgb(2, 166, 242)";
  575. } else if (theme === "purple") {
  576. this.theme = "rgb(143, 40, 140)";
  577. } else if (theme === "teal") {
  578. this.theme = "rgb(0, 209, 178)";
  579. }
  580. });
  581. this.socket.on("event:newOfficialPlaylist", playlist => {
  582. if (this.station.type === "official") {
  583. this.updateSongsList(playlist);
  584. }
  585. });
  586. this.socket.on("event:users.updated", users => {
  587. this.updateUsers(users);
  588. });
  589. this.socket.on("event:userCount.updated", userCount => {
  590. this.updateUserCount(userCount);
  591. });
  592. this.socket.on("event:queueLockToggled", locked => {
  593. this.station.locked = locked;
  594. });
  595. this.socket.on("event:user.favoritedStation", stationId => {
  596. if (stationId === this.station._id)
  597. this.updateIfStationIsFavorited({ isFavorited: true });
  598. });
  599. this.socket.on("event:user.unfavoritedStation", stationId => {
  600. if (stationId === this.station._id)
  601. this.updateIfStationIsFavorited({ isFavorited: false });
  602. });
  603. });
  604. if (JSON.parse(localStorage.getItem("muted"))) {
  605. this.muted = true;
  606. this.player.setVolume(0);
  607. this.volumeSliderValue = 0 * 100;
  608. } else {
  609. let volume = parseFloat(localStorage.getItem("volume"));
  610. volume =
  611. typeof volume === "number" && !Number.isNaN(volume)
  612. ? volume
  613. : 20;
  614. localStorage.setItem("volume", volume);
  615. this.volumeSliderValue = volume * 100;
  616. }
  617. },
  618. beforeDestroy() {
  619. /** Reset Songslist */
  620. this.updateSongsList([]);
  621. const shortcutNames = [
  622. "station.pauseResume",
  623. "station.skipStation",
  624. "station.lowerVolumeLarge",
  625. "station.lowerVolumeSmall",
  626. "station.increaseVolumeLarge",
  627. "station.increaseVolumeSmall",
  628. "station.toggleDebug"
  629. ];
  630. shortcutNames.forEach(shortcutName => {
  631. keyboardShortcuts.unregisterShortcut(shortcutName);
  632. });
  633. },
  634. methods: {
  635. isOwnerOnly() {
  636. return this.loggedIn && this.userId === this.station.owner;
  637. },
  638. isAdminOnly() {
  639. return this.loggedIn && this.role === "admin";
  640. },
  641. isOwnerOrAdmin() {
  642. return this.isOwnerOnly() || this.isAdminOnly();
  643. },
  644. openSettings() {
  645. this.editStation({
  646. _id: this.station._id,
  647. name: this.station.name,
  648. type: this.station.type,
  649. partyMode: this.station.partyMode,
  650. description: this.station.description,
  651. privacy: this.station.privacy,
  652. displayName: this.station.displayName,
  653. locked: this.station.locked,
  654. genres: this.station.genres,
  655. blacklistedGenres: this.station.blacklistedGenres,
  656. theme: this.station.theme
  657. });
  658. this.openModal({
  659. sector: "station",
  660. modal: "editStation"
  661. });
  662. },
  663. removeFromQueue(songId) {
  664. window.socket.emit(
  665. "stations.removeFromQueue",
  666. this.station._id,
  667. songId,
  668. res => {
  669. if (res.status === "success") {
  670. new Toast({
  671. content:
  672. "Successfully removed song from the queue.",
  673. timeout: 4000
  674. });
  675. } else new Toast({ content: res.message, timeout: 8000 });
  676. }
  677. );
  678. },
  679. youtubeReady() {
  680. if (!this.player) {
  681. this.player = new window.YT.Player("stationPlayer", {
  682. height: 270,
  683. width: 480,
  684. videoId: this.currentSong.songId,
  685. host: "https://www.youtube-nocookie.com",
  686. startSeconds:
  687. this.getTimeElapsed() / 1000 +
  688. this.currentSong.skipDuration,
  689. playerVars: {
  690. controls: 0,
  691. iv_load_policy: 3,
  692. rel: 0,
  693. showinfo: 0
  694. },
  695. events: {
  696. onReady: () => {
  697. this.playerReady = true;
  698. let volume = parseInt(
  699. localStorage.getItem("volume")
  700. );
  701. volume = typeof volume === "number" ? volume : 20;
  702. this.player.setVolume(volume);
  703. if (volume > 0) {
  704. this.player.unMute();
  705. }
  706. if (this.muted) this.player.mute();
  707. this.playVideo();
  708. },
  709. onError: err => {
  710. console.log("iframe error", err);
  711. if (this.loggedIn) {
  712. new Toast({
  713. content:
  714. "Error with YouTube Embed, voted to skip the current song.",
  715. timeout: 8000
  716. });
  717. this.voteSkipStation();
  718. } else {
  719. new Toast({
  720. content: "Error with YouTube Embed",
  721. timeout: 8000
  722. });
  723. }
  724. },
  725. onStateChange: event => {
  726. if (
  727. event.data === window.YT.PlayerState.PLAYING &&
  728. this.videoLoading === true
  729. ) {
  730. this.videoLoading = false;
  731. this.player.seekTo(
  732. this.getTimeElapsed() / 1000 +
  733. this.currentSong.skipDuration,
  734. true
  735. );
  736. if (this.localPaused || this.stationPaused)
  737. this.player.pauseVideo();
  738. } else if (
  739. event.data === window.YT.PlayerState.PLAYING &&
  740. (this.localPaused || this.stationPaused)
  741. ) {
  742. this.player.seekTo(
  743. this.timeBeforePause / 1000,
  744. true
  745. );
  746. this.player.pauseVideo();
  747. } else if (
  748. event.data === window.YT.PlayerState.PLAYING &&
  749. this.seeking === true
  750. ) {
  751. this.seeking = false;
  752. }
  753. if (
  754. event.data === window.YT.PlayerState.PAUSED &&
  755. !this.localPaused &&
  756. !this.stationPaused &&
  757. !this.noSong &&
  758. this.player.getDuration() / 1000 <
  759. this.currentSong.duration
  760. ) {
  761. this.player.seekTo(
  762. this.getTimeElapsed() / 1000 +
  763. this.currentSong.skipDuration,
  764. true
  765. );
  766. this.player.playVideo();
  767. }
  768. }
  769. }
  770. });
  771. }
  772. },
  773. getTimeElapsed() {
  774. if (this.currentSong) {
  775. let { timePaused } = this;
  776. if (this.stationPaused)
  777. timePaused += Date.currently() - this.pausedAt;
  778. return Date.currently() - this.startedAt - timePaused;
  779. }
  780. return 0;
  781. },
  782. playVideo() {
  783. if (this.playerReady) {
  784. this.videoLoading = true;
  785. this.player.loadVideoById(
  786. this.currentSong.songId,
  787. this.getTimeElapsed() / 1000 + this.currentSong.skipDuration
  788. );
  789. if (window.stationInterval !== 0)
  790. clearInterval(window.stationInterval);
  791. window.stationInterval = setInterval(() => {
  792. this.resizeSeekerbar();
  793. this.calculateTimeElapsed();
  794. }, 150);
  795. }
  796. },
  797. resizeSeekerbar() {
  798. if (!this.stationPaused) {
  799. document.getElementById(
  800. "seeker-bar"
  801. ).style.width = `${parseFloat(
  802. (this.getTimeElapsed() / 1000 / this.currentSong.duration) *
  803. 100
  804. )}%`;
  805. }
  806. },
  807. calculateTimeElapsed() {
  808. if (
  809. this.playerReady &&
  810. this.currentSong &&
  811. this.player.getPlayerState() === -1
  812. ) {
  813. if (this.attemptsToPlayVideo >= 5) {
  814. if (
  815. Date.now() - this.lastTimeRequestedIfCanAutoplay >
  816. 2000
  817. ) {
  818. this.lastTimeRequestedIfCanAutoplay = Date.now();
  819. window.canAutoplay.video().then(({ result }) => {
  820. if (result) {
  821. this.attemptsToPlayVideo = 0;
  822. this.canAutoplay = true;
  823. } else {
  824. this.canAutoplay = false;
  825. }
  826. });
  827. }
  828. } else {
  829. this.player.playVideo();
  830. this.attemptsToPlayVideo += 1;
  831. }
  832. }
  833. if (!this.stationPaused && !this.localPaused) {
  834. const timeElapsed = this.getTimeElapsed();
  835. const currentPlayerTime =
  836. Math.max(
  837. this.player.getCurrentTime() -
  838. this.currentSong.skipDuration,
  839. 0
  840. ) * 1000;
  841. const difference = timeElapsed - currentPlayerTime;
  842. // console.log(difference);
  843. let playbackRate = 1;
  844. if (difference < -2000) {
  845. if (!this.seeking) {
  846. this.seeking = true;
  847. this.player.seekTo(
  848. this.getTimeElapsed() / 1000 +
  849. this.currentSong.skipDuration
  850. );
  851. }
  852. } else if (difference < -200) {
  853. // console.log("Difference0.8");
  854. playbackRate = 0.8;
  855. } else if (difference < -50) {
  856. // console.log("Difference0.9");
  857. playbackRate = 0.9;
  858. } else if (difference < -25) {
  859. // console.log("Difference0.99");
  860. playbackRate = 0.95;
  861. } else if (difference > 2000) {
  862. if (!this.seeking) {
  863. this.seeking = true;
  864. this.player.seekTo(
  865. this.getTimeElapsed() / 1000 +
  866. this.currentSong.skipDuration
  867. );
  868. }
  869. } else if (difference > 200) {
  870. // console.log("Difference1.2");
  871. playbackRate = 1.2;
  872. } else if (difference > 50) {
  873. // console.log("Difference1.1");
  874. playbackRate = 1.1;
  875. } else if (difference > 25) {
  876. // console.log("Difference1.01");
  877. playbackRate = 1.05;
  878. } else if (this.player.getPlaybackRate !== 1.0) {
  879. // console.log("NDifference1.0");
  880. this.player.setPlaybackRate(1.0);
  881. }
  882. if (this.playbackRate !== playbackRate) {
  883. this.player.setPlaybackRate(playbackRate);
  884. this.playbackRate = playbackRate;
  885. }
  886. }
  887. /* if (this.currentTime !== undefined && this.paused) {
  888. this.timePaused += Date.currently() - this.currentTime;
  889. this.currentTime = undefined;
  890. } */
  891. let { timePaused } = this;
  892. if (this.stationPaused)
  893. timePaused += Date.currently() - this.pausedAt;
  894. const duration =
  895. (Date.currently() - this.startedAt - timePaused) / 1000;
  896. const songDuration = this.currentSong.duration;
  897. if (songDuration <= duration) this.player.pauseVideo();
  898. if (!this.stationPaused && duration <= songDuration)
  899. this.timeElapsed = utils.formatTime(duration);
  900. },
  901. toggleLock() {
  902. window.socket.emit("stations.toggleLock", this.station._id, res => {
  903. if (res.status === "success") {
  904. new Toast({
  905. content: "Successfully toggled the queue lock.",
  906. timeout: 4000
  907. });
  908. } else new Toast({ content: res.message, timeout: 8000 });
  909. });
  910. },
  911. changeVolume() {
  912. const volume = this.volumeSliderValue;
  913. localStorage.setItem("volume", volume / 100);
  914. if (this.playerReady) {
  915. this.player.setVolume(volume / 100);
  916. if (volume > 0) {
  917. this.player.unMute();
  918. localStorage.setItem("muted", false);
  919. this.muted = false;
  920. }
  921. }
  922. },
  923. resumeLocalStation() {
  924. this.updateLocalPaused(false);
  925. if (!this.stationPaused) this.resumeLocalPlayer();
  926. },
  927. pauseLocalStation() {
  928. this.updateLocalPaused(true);
  929. this.pauseLocalPlayer();
  930. },
  931. resumeLocalPlayer() {
  932. if (!this.noSong) {
  933. if (this.playerReady) {
  934. this.player.seekTo(
  935. this.getTimeElapsed() / 1000 +
  936. this.currentSong.skipDuration
  937. );
  938. this.player.playVideo();
  939. }
  940. }
  941. },
  942. pauseLocalPlayer() {
  943. if (!this.noSong) {
  944. this.timeBeforePause = this.getTimeElapsed();
  945. if (this.playerReady) this.player.pauseVideo();
  946. }
  947. },
  948. skipStation() {
  949. this.socket.emit("stations.forceSkip", this.station._id, data => {
  950. if (data.status !== "success")
  951. new Toast({
  952. content: `Error: ${data.message}`,
  953. timeout: 8000
  954. });
  955. else
  956. new Toast({
  957. content:
  958. "Successfully skipped the station's current song.",
  959. timeout: 4000
  960. });
  961. });
  962. },
  963. voteSkipStation() {
  964. this.socket.emit("stations.voteSkip", this.station._id, data => {
  965. if (data.status !== "success")
  966. new Toast({
  967. content: `Error: ${data.message}`,
  968. timeout: 8000
  969. });
  970. else
  971. new Toast({
  972. content: "Successfully voted to skip the current song.",
  973. timeout: 4000
  974. });
  975. });
  976. },
  977. resumeStation() {
  978. this.socket.emit("stations.resume", this.station._id, data => {
  979. if (data.status !== "success")
  980. new Toast({
  981. content: `Error: ${data.message}`,
  982. timeout: 8000
  983. });
  984. else
  985. new Toast({
  986. content: "Successfully resumed the station.",
  987. timeout: 4000
  988. });
  989. });
  990. },
  991. pauseStation() {
  992. this.socket.emit("stations.pause", this.station._id, data => {
  993. if (data.status !== "success")
  994. new Toast({
  995. content: `Error: ${data.message}`,
  996. timeout: 8000
  997. });
  998. else
  999. new Toast({
  1000. content: "Successfully paused the station.",
  1001. timeout: 4000
  1002. });
  1003. });
  1004. },
  1005. toggleMute() {
  1006. if (this.playerReady) {
  1007. const previousVolume = parseFloat(
  1008. localStorage.getItem("volume")
  1009. );
  1010. const volume =
  1011. this.player.getVolume() * 100 <= 0 ? previousVolume : 0;
  1012. this.muted = !this.muted;
  1013. localStorage.setItem("muted", this.muted);
  1014. this.volumeSliderValue = volume * 100;
  1015. this.player.setVolume(volume);
  1016. if (!this.muted) localStorage.setItem("volume", volume);
  1017. }
  1018. },
  1019. increaseVolume() {
  1020. if (this.playerReady) {
  1021. const previousVolume = parseInt(localStorage.getItem("volume"));
  1022. let volume = previousVolume + 5;
  1023. if (previousVolume === 0) {
  1024. this.muted = false;
  1025. localStorage.setItem("muted", false);
  1026. }
  1027. if (volume > 100) volume = 100;
  1028. this.volumeSliderValue = volume * 100;
  1029. this.player.setVolume(volume);
  1030. localStorage.setItem("volume", volume);
  1031. }
  1032. },
  1033. toggleLike() {
  1034. if (this.liked)
  1035. this.socket.emit(
  1036. "songs.unlike",
  1037. this.currentSong.songId,
  1038. data => {
  1039. if (data.status !== "success")
  1040. new Toast({
  1041. content: `Error: ${data.message}`,
  1042. timeout: 8000
  1043. });
  1044. }
  1045. );
  1046. else
  1047. this.socket.emit(
  1048. "songs.like",
  1049. this.currentSong.songId,
  1050. data => {
  1051. if (data.status !== "success")
  1052. new Toast({
  1053. content: `Error: ${data.message}`,
  1054. timeout: 8000
  1055. });
  1056. }
  1057. );
  1058. },
  1059. toggleDislike() {
  1060. if (this.disliked)
  1061. return this.socket.emit(
  1062. "songs.undislike",
  1063. this.currentSong.songId,
  1064. data => {
  1065. if (data.status !== "success")
  1066. new Toast({
  1067. content: `Error: ${data.message}`,
  1068. timeout: 8000
  1069. });
  1070. }
  1071. );
  1072. return this.socket.emit(
  1073. "songs.dislike",
  1074. this.currentSong.songId,
  1075. data => {
  1076. if (data.status !== "success")
  1077. new Toast({
  1078. content: `Error: ${data.message}`,
  1079. timeout: 8000
  1080. });
  1081. }
  1082. );
  1083. },
  1084. addFirstPrivatePlaylistSongToQueue() {
  1085. let isInQueue = false;
  1086. if (
  1087. this.station.type === "community" &&
  1088. this.station.partyMode === true
  1089. ) {
  1090. this.songsList.forEach(queueSong => {
  1091. if (queueSong.requestedBy === this.userId) isInQueue = true;
  1092. });
  1093. if (!isInQueue && this.privatePlaylistQueueSelected) {
  1094. this.socket.emit(
  1095. "playlists.getFirstSong",
  1096. this.privatePlaylistQueueSelected,
  1097. data => {
  1098. if (data.status === "success") {
  1099. if (data.song) {
  1100. if (data.song.duration < 15 * 60) {
  1101. this.automaticallyRequestedSongId =
  1102. data.song.songId;
  1103. this.socket.emit(
  1104. "stations.addToQueue",
  1105. this.station._id,
  1106. data.song.songId,
  1107. data2 => {
  1108. if (
  1109. data2.status === "success"
  1110. ) {
  1111. this.socket.emit(
  1112. "playlists.moveSongToBottom",
  1113. this
  1114. .privatePlaylistQueueSelected,
  1115. data.song.songId,
  1116. data3 => {
  1117. if (
  1118. data3.status ===
  1119. "success"
  1120. ) {
  1121. console.log(
  1122. "This comment is just here because of eslint/prettier issues, ignore it"
  1123. );
  1124. }
  1125. }
  1126. );
  1127. }
  1128. }
  1129. );
  1130. } else {
  1131. new Toast({
  1132. content: `Top song in playlist was too long to be added.`,
  1133. timeout: 3000
  1134. });
  1135. this.socket.emit(
  1136. "playlists.moveSongToBottom",
  1137. this.privatePlaylistQueueSelected,
  1138. data.song.songId,
  1139. data3 => {
  1140. if (
  1141. data3.status === "success"
  1142. ) {
  1143. setTimeout(() => {
  1144. this.addFirstPrivatePlaylistSongToQueue();
  1145. }, 3000);
  1146. }
  1147. }
  1148. );
  1149. }
  1150. } else {
  1151. new Toast({
  1152. content: `Selected playlist has no songs.`,
  1153. timeout: 4000
  1154. });
  1155. }
  1156. }
  1157. }
  1158. );
  1159. }
  1160. }
  1161. },
  1162. togglePlayerDebugBox() {
  1163. this.$refs.playerDebugBox.toggleBox();
  1164. },
  1165. resetPlayerDebugBox() {
  1166. this.$refs.playerDebugBox.resetBox();
  1167. },
  1168. join() {
  1169. this.socket.emit("stations.join", this.stationName, res => {
  1170. if (res.status === "success") {
  1171. this.loading = false;
  1172. const {
  1173. _id,
  1174. displayName,
  1175. description,
  1176. privacy,
  1177. locked,
  1178. partyMode,
  1179. owner,
  1180. privatePlaylist,
  1181. type,
  1182. genres,
  1183. blacklistedGenres,
  1184. isFavorited,
  1185. theme
  1186. } = res.data;
  1187. this.joinStation({
  1188. _id,
  1189. name: this.stationName,
  1190. displayName,
  1191. description,
  1192. privacy,
  1193. locked,
  1194. partyMode,
  1195. owner,
  1196. privatePlaylist,
  1197. type,
  1198. genres,
  1199. blacklistedGenres,
  1200. isFavorited,
  1201. theme
  1202. });
  1203. if (this.station.theme === "blue") {
  1204. this.theme = "rgb(2, 166, 242)";
  1205. } else if (this.station.theme === "purple") {
  1206. this.theme = "rgb(143, 40, 140)";
  1207. } else if (this.station.theme === "teal") {
  1208. this.theme = "rgb(0, 209, 178)";
  1209. }
  1210. const currentSong = res.data.currentSong
  1211. ? res.data.currentSong
  1212. : {};
  1213. if (currentSong.artists)
  1214. currentSong.artists = currentSong.artists.join(", ");
  1215. if (currentSong && !currentSong.thumbnail)
  1216. currentSong.ytThumbnail = `https://img.youtube.com/vi/${currentSong.songId}/mqdefault.jpg`;
  1217. this.updateCurrentSong(currentSong);
  1218. this.startedAt = res.data.startedAt;
  1219. this.updateStationPaused(res.data.paused);
  1220. this.timePaused = res.data.timePaused;
  1221. this.updateUserCount(res.data.userCount);
  1222. this.updateUsers(res.data.users);
  1223. this.pausedAt = res.data.pausedAt;
  1224. if (res.data.currentSong) {
  1225. this.updateNoSong(false);
  1226. this.youtubeReady();
  1227. this.playVideo();
  1228. this.socket.emit(
  1229. "songs.getOwnSongRatings",
  1230. res.data.currentSong.songId,
  1231. data => {
  1232. if (this.currentSong.songId === data.songId) {
  1233. this.liked = data.liked;
  1234. this.disliked = data.disliked;
  1235. }
  1236. }
  1237. );
  1238. } else {
  1239. if (this.playerReady) this.player.pauseVideo();
  1240. this.updateNoSong(true);
  1241. }
  1242. if (type === "community" && partyMode === true) {
  1243. this.socket.emit("stations.getQueue", _id, res => {
  1244. if (res.status === "success") {
  1245. this.updateSongsList(res.queue);
  1246. }
  1247. });
  1248. }
  1249. if (this.isOwnerOrAdmin()) {
  1250. keyboardShortcuts.registerShortcut(
  1251. "station.pauseResume",
  1252. {
  1253. keyCode: 32,
  1254. shift: false,
  1255. ctrl: true,
  1256. preventDefault: true,
  1257. handler: () => {
  1258. if (this.stationPaused)
  1259. this.resumeStation();
  1260. else this.pauseStation();
  1261. }
  1262. }
  1263. );
  1264. keyboardShortcuts.registerShortcut(
  1265. "station.skipStation",
  1266. {
  1267. keyCode: 39,
  1268. shift: false,
  1269. ctrl: true,
  1270. preventDefault: true,
  1271. handler: () => {
  1272. this.skipStation();
  1273. }
  1274. }
  1275. );
  1276. }
  1277. keyboardShortcuts.registerShortcut(
  1278. "station.lowerVolumeLarge",
  1279. {
  1280. keyCode: 40,
  1281. shift: false,
  1282. ctrl: true,
  1283. preventDefault: true,
  1284. handler: () => {
  1285. this.volumeSliderValue -= 1000;
  1286. this.changeVolume();
  1287. }
  1288. }
  1289. );
  1290. keyboardShortcuts.registerShortcut(
  1291. "station.lowerVolumeSmall",
  1292. {
  1293. keyCode: 40,
  1294. shift: true,
  1295. ctrl: true,
  1296. preventDefault: true,
  1297. handler: () => {
  1298. this.volumeSliderValue -= 100;
  1299. this.changeVolume();
  1300. }
  1301. }
  1302. );
  1303. keyboardShortcuts.registerShortcut(
  1304. "station.increaseVolumeLarge",
  1305. {
  1306. keyCode: 38,
  1307. shift: false,
  1308. ctrl: true,
  1309. preventDefault: true,
  1310. handler: () => {
  1311. this.volumeSliderValue += 1000;
  1312. this.changeVolume();
  1313. }
  1314. }
  1315. );
  1316. keyboardShortcuts.registerShortcut(
  1317. "station.increaseVolumeSmall",
  1318. {
  1319. keyCode: 38,
  1320. shift: true,
  1321. ctrl: true,
  1322. preventDefault: true,
  1323. handler: () => {
  1324. this.volumeSliderValue += 100;
  1325. this.changeVolume();
  1326. }
  1327. }
  1328. );
  1329. keyboardShortcuts.registerShortcut("station.toggleDebug", {
  1330. keyCode: 68,
  1331. shift: false,
  1332. ctrl: true,
  1333. preventDefault: true,
  1334. handler: () => {
  1335. this.togglePlayerDebugBox();
  1336. }
  1337. });
  1338. // UNIX client time before ping
  1339. const beforePing = Date.now();
  1340. this.socket.emit("apis.ping", pong => {
  1341. // UNIX client time after ping
  1342. const afterPing = Date.now();
  1343. // Average time in MS it took between the server responding and the client receiving
  1344. const connectionLatency = (afterPing - beforePing) / 2;
  1345. console.log(connectionLatency, beforePing - afterPing);
  1346. // UNIX server time
  1347. const serverDate = pong.date;
  1348. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  1349. const difference =
  1350. serverDate + connectionLatency - afterPing;
  1351. console.log("Difference: ", difference);
  1352. if (difference > 3000 || difference < -3000) {
  1353. console.log(
  1354. "System time difference is bigger than 3 seconds."
  1355. );
  1356. }
  1357. this.systemDifference = difference;
  1358. });
  1359. } else {
  1360. this.loading = false;
  1361. this.exists = false;
  1362. }
  1363. });
  1364. },
  1365. favoriteStation() {
  1366. this.socket.emit(
  1367. "stations.favoriteStation",
  1368. this.station._id,
  1369. res => {
  1370. if (res.status === "success") {
  1371. new Toast({
  1372. content: "Successfully favorited station.",
  1373. timeout: 4000
  1374. });
  1375. } else new Toast({ content: res.message, timeout: 8000 });
  1376. }
  1377. );
  1378. },
  1379. unfavoriteStation() {
  1380. this.socket.emit(
  1381. "stations.unfavoriteStation",
  1382. this.station._id,
  1383. res => {
  1384. if (res.status === "success") {
  1385. new Toast({
  1386. content: "Successfully unfavorited station.",
  1387. timeout: 4000
  1388. });
  1389. } else new Toast({ content: res.message, timeout: 8000 });
  1390. }
  1391. );
  1392. },
  1393. editSong(song) {
  1394. this.editingSongId = song._id;
  1395. this.openModal({ sector: "station", modal: "editSong" });
  1396. },
  1397. ...mapActions("modals", ["openModal"]),
  1398. ...mapActions("station", [
  1399. "joinStation",
  1400. "updateUserCount",
  1401. "updateUsers",
  1402. "updateCurrentSong",
  1403. "updatePreviousSong",
  1404. "updateSongsList",
  1405. "updateStationPaused",
  1406. "updateLocalPaused",
  1407. "updateNoSong",
  1408. "editStation",
  1409. "updateIfStationIsFavorited"
  1410. ]),
  1411. ...mapActions("editSongModal", ["stopVideo"])
  1412. }
  1413. };
  1414. </script>
  1415. <style lang="scss" scoped>
  1416. @import "../../styles/global.scss";
  1417. .progress {
  1418. width: 50px;
  1419. animation: rotate 0.8s infinite linear;
  1420. border: 8px solid $primary-color;
  1421. border-right-color: transparent;
  1422. height: 50px;
  1423. position: absolute;
  1424. top: 50%;
  1425. left: 50%;
  1426. }
  1427. @keyframes rotate {
  1428. 0% {
  1429. transform: rotate(0deg);
  1430. }
  1431. 100% {
  1432. transform: rotate(360deg);
  1433. }
  1434. }
  1435. .nav,
  1436. .button.is-primary {
  1437. background-color: var(--station-theme) !important;
  1438. }
  1439. .button.is-primary:hover,
  1440. .button.is-primary:focus {
  1441. filter: brightness(90%);
  1442. }
  1443. #player-debug-box {
  1444. .box-body {
  1445. flex-direction: column;
  1446. b {
  1447. color: #000;
  1448. }
  1449. }
  1450. }
  1451. .night-mode {
  1452. #currently-playing-container,
  1453. #about-station-container,
  1454. #control-bar-container,
  1455. .player-container {
  1456. background-color: $night-mode-bg-secondary !important;
  1457. }
  1458. #video-container,
  1459. #control-bar-container {
  1460. border: 0 !important;
  1461. }
  1462. #seeker-bar-container {
  1463. background-color: $night-mode-bg-secondary !important;
  1464. }
  1465. #dropdown-toggle {
  1466. background-color: $dark-grey !important;
  1467. border: 0;
  1468. i {
  1469. color: #fff;
  1470. }
  1471. }
  1472. }
  1473. #station-outer-container {
  1474. margin: 0 auto;
  1475. padding: 20px 40px;
  1476. height: 100%;
  1477. width: 100%;
  1478. max-width: 1800px;
  1479. display: flex;
  1480. #station-inner-container {
  1481. height: 100%;
  1482. width: 100%;
  1483. min-height: calc(100vh - 64px - 190px);
  1484. display: flex;
  1485. flex-direction: row;
  1486. flex-wrap: wrap;
  1487. .row {
  1488. display: flex;
  1489. flex-direction: row;
  1490. max-width: 100%;
  1491. }
  1492. .column {
  1493. display: flex;
  1494. flex-direction: column;
  1495. }
  1496. .quadrant {
  1497. border-radius: 5px;
  1498. margin: 10px;
  1499. flex-grow: 1;
  1500. }
  1501. .quadrant:not(#sidebar-container) {
  1502. background-color: #fff;
  1503. border: 1px solid $light-grey-2;
  1504. }
  1505. #station-left-column {
  1506. padding: 0;
  1507. }
  1508. #station-right-column {
  1509. max-width: 650px;
  1510. padding: 0;
  1511. }
  1512. #about-station-container {
  1513. padding: 20px;
  1514. display: flex;
  1515. flex-direction: column;
  1516. flex-grow: unset;
  1517. #station-info {
  1518. #station-name {
  1519. flex-direction: row !important;
  1520. h1 {
  1521. margin: 0;
  1522. font-size: 36px;
  1523. line-height: 0.8;
  1524. }
  1525. i {
  1526. margin-left: 10px;
  1527. font-size: 30px;
  1528. color: $yellow;
  1529. }
  1530. }
  1531. p {
  1532. max-width: 700px;
  1533. margin-bottom: 10px;
  1534. }
  1535. }
  1536. #admin-buttons {
  1537. display: flex;
  1538. .button {
  1539. margin: 3px;
  1540. }
  1541. }
  1542. }
  1543. #current-next-row {
  1544. display: flex;
  1545. flex-direction: row;
  1546. #currently-playing-container,
  1547. #next-up-container {
  1548. overflow: hidden;
  1549. flex-basis: 50%;
  1550. .nothing-here-text {
  1551. height: 100%;
  1552. }
  1553. }
  1554. }
  1555. .player-container {
  1556. height: inherit;
  1557. background-color: #fff;
  1558. display: flex;
  1559. flex-direction: column;
  1560. border: 1px solid $light-grey-2;
  1561. border-radius: 5px;
  1562. overflow: hidden;
  1563. flex-grow: 1;
  1564. &.nothing-here-text {
  1565. border: 1px solid $light-grey-2;
  1566. border-radius: 5px;
  1567. margin: 10px;
  1568. }
  1569. #video-container {
  1570. width: 100%;
  1571. height: 100%;
  1572. .player-cannot-autoplay {
  1573. position: relative;
  1574. width: 100%;
  1575. height: 100%;
  1576. bottom: calc(100% + 5px);
  1577. background: var(--station-theme);
  1578. display: flex;
  1579. align-items: center;
  1580. justify-content: center;
  1581. p {
  1582. color: $white;
  1583. font-size: 26px;
  1584. text-align: center;
  1585. }
  1586. }
  1587. }
  1588. #seeker-bar-container {
  1589. background-color: #fff;
  1590. position: relative;
  1591. height: 7px;
  1592. display: block;
  1593. width: 100%;
  1594. overflow: hidden;
  1595. #seeker-bar {
  1596. background-color: var(--station-theme);
  1597. top: 0;
  1598. left: 0;
  1599. bottom: 0;
  1600. position: absolute;
  1601. }
  1602. }
  1603. #control-bar-container {
  1604. display: flex;
  1605. justify-content: space-around;
  1606. padding: 10px 0;
  1607. width: 100%;
  1608. background: #fff;
  1609. flex-direction: column;
  1610. flex-flow: wrap;
  1611. .button:not(#dropdown-toggle) {
  1612. width: 75px;
  1613. }
  1614. #left-buttons,
  1615. #right-buttons {
  1616. margin: 3px;
  1617. }
  1618. #left-buttons {
  1619. display: flex;
  1620. .button:not(:first-of-type) {
  1621. margin-left: 5px;
  1622. }
  1623. }
  1624. #duration {
  1625. margin: 3px;
  1626. display: flex;
  1627. align-items: center;
  1628. p {
  1629. font-size: 22px;
  1630. /** prevents duration width slightly varying and shifting other controls slightly */
  1631. width: 150px;
  1632. text-align: center;
  1633. }
  1634. }
  1635. #volume-control {
  1636. margin: 3px;
  1637. margin-top: 0;
  1638. display: flex;
  1639. align-items: center;
  1640. cursor: pointer;
  1641. .volume-slider {
  1642. width: 100%;
  1643. padding: 0 15px;
  1644. background: transparent;
  1645. min-width: 100px;
  1646. }
  1647. input[type="range"] {
  1648. -webkit-appearance: none;
  1649. margin: 7.3px 0;
  1650. }
  1651. input[type="range"]:focus {
  1652. outline: none;
  1653. }
  1654. input[type="range"]::-webkit-slider-runnable-track {
  1655. width: 100%;
  1656. height: 5.2px;
  1657. cursor: pointer;
  1658. box-shadow: 0;
  1659. background: $light-grey-2;
  1660. border-radius: 0;
  1661. border: 0;
  1662. }
  1663. input[type="range"]::-webkit-slider-thumb {
  1664. box-shadow: 0;
  1665. border: 0;
  1666. height: 19px;
  1667. width: 19px;
  1668. border-radius: 15px;
  1669. background: var(--station-theme);
  1670. cursor: pointer;
  1671. -webkit-appearance: none;
  1672. margin-top: -6.5px;
  1673. }
  1674. input[type="range"]::-moz-range-track {
  1675. width: 100%;
  1676. height: 5.2px;
  1677. cursor: pointer;
  1678. box-shadow: 0;
  1679. background: $light-grey-2;
  1680. border-radius: 0;
  1681. border: 0;
  1682. }
  1683. input[type="range"]::-moz-range-thumb {
  1684. box-shadow: 0;
  1685. border: 0;
  1686. height: 19px;
  1687. width: 19px;
  1688. border-radius: 15px;
  1689. background: var(--station-theme);
  1690. cursor: pointer;
  1691. -webkit-appearance: none;
  1692. margin-top: -6.5px;
  1693. }
  1694. input[type="range"]::-ms-track {
  1695. width: 100%;
  1696. height: 5.2px;
  1697. cursor: pointer;
  1698. box-shadow: 0;
  1699. background: $light-grey-2;
  1700. border-radius: 1.3px;
  1701. }
  1702. input[type="range"]::-ms-fill-lower {
  1703. background: $light-grey-2;
  1704. border: 0;
  1705. border-radius: 0;
  1706. box-shadow: 0;
  1707. }
  1708. input[type="range"]::-ms-fill-upper {
  1709. background: $light-grey-2;
  1710. border: 0;
  1711. border-radius: 0;
  1712. box-shadow: 0;
  1713. }
  1714. input[type="range"]::-ms-thumb {
  1715. box-shadow: 0;
  1716. border: 0;
  1717. height: 15px;
  1718. width: 15px;
  1719. border-radius: 15px;
  1720. background: var(--station-theme);
  1721. cursor: pointer;
  1722. -webkit-appearance: none;
  1723. margin-top: 1.5px;
  1724. }
  1725. }
  1726. #right-buttons {
  1727. display: flex;
  1728. #dropdown-toggle {
  1729. width: 35px;
  1730. }
  1731. #dislike-song,
  1732. #add-song-to-playlist .button:not(#dropdown-toggle) {
  1733. margin-left: 5px;
  1734. }
  1735. #ratings {
  1736. display: flex;
  1737. #like-song:hover,
  1738. #like-song.liked {
  1739. background-color: darken($green, 5%) !important;
  1740. }
  1741. #dislike-song:hover,
  1742. #dislike-song.disliked {
  1743. background-color: darken($red, 5%) !important;
  1744. }
  1745. &.liked #dislike-song,
  1746. &.disliked #like-song {
  1747. background-color: $grey !important;
  1748. &:hover {
  1749. background-color: darken($grey, 5%) !important;
  1750. }
  1751. }
  1752. }
  1753. #add-song-to-playlist {
  1754. display: flex;
  1755. flex-direction: column-reverse;
  1756. .control {
  1757. width: fit-content;
  1758. margin-bottom: 0 !important;
  1759. }
  1760. }
  1761. }
  1762. }
  1763. }
  1764. #sidebar-container {
  1765. border-top: 0;
  1766. position: relative;
  1767. height: inherit;
  1768. }
  1769. }
  1770. }
  1771. .footer {
  1772. margin-top: 30px;
  1773. }
  1774. /deep/ .nothing-here-text {
  1775. display: flex;
  1776. align-items: center;
  1777. justify-content: center;
  1778. }
  1779. @media (max-width: 1300px) {
  1780. #station-outer-container {
  1781. padding: 10px;
  1782. height: unset;
  1783. max-width: 700px;
  1784. #station-inner-container {
  1785. flex-direction: column;
  1786. #station-left-column {
  1787. #current-next-row {
  1788. flex-direction: column;
  1789. }
  1790. #video-container {
  1791. min-height: 200px;
  1792. }
  1793. #control-bar-container {
  1794. #duration,
  1795. #volume-control,
  1796. #right-buttons,
  1797. #left-buttons {
  1798. margin-bottom: 5px;
  1799. justify-content: center;
  1800. }
  1801. #duration {
  1802. order: 1;
  1803. }
  1804. #volume-control {
  1805. order: 2;
  1806. max-width: 400px;
  1807. }
  1808. #right-buttons {
  1809. order: 3;
  1810. flex-wrap: wrap;
  1811. #ratings {
  1812. flex-wrap: wrap;
  1813. }
  1814. }
  1815. #left-buttons {
  1816. order: 4;
  1817. flex-wrap: wrap;
  1818. }
  1819. }
  1820. }
  1821. #station-right-column {
  1822. max-width: unset;
  1823. #about-station-container #admin-buttons {
  1824. flex-wrap: wrap;
  1825. }
  1826. #sidebar-container {
  1827. min-height: 350px;
  1828. }
  1829. }
  1830. }
  1831. }
  1832. }
  1833. </style>