index.vue 48 KB

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