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. });
  650. this.socket.on("event:users.updated", users => {
  651. this.updateUsers(users);
  652. });
  653. this.socket.on("event:userCount.updated", userCount => {
  654. this.updateUserCount(userCount);
  655. });
  656. this.socket.on("event:queueLockToggled", locked => {
  657. this.station.locked = locked;
  658. });
  659. this.socket.on("event:user.favoritedStation", stationId => {
  660. if (stationId === this.station._id)
  661. this.updateIfStationIsFavorited({ isFavorited: true });
  662. });
  663. this.socket.on("event:user.unfavoritedStation", stationId => {
  664. if (stationId === this.station._id)
  665. this.updateIfStationIsFavorited({ isFavorited: false });
  666. });
  667. });
  668. if (JSON.parse(localStorage.getItem("muted"))) {
  669. this.muted = true;
  670. this.player.setVolume(0);
  671. this.volumeSliderValue = 0 * 100;
  672. } else {
  673. let volume = parseFloat(localStorage.getItem("volume"));
  674. volume =
  675. typeof volume === "number" && !Number.isNaN(volume)
  676. ? volume
  677. : 20;
  678. localStorage.setItem("volume", volume);
  679. this.volumeSliderValue = volume * 100;
  680. }
  681. },
  682. beforeDestroy() {
  683. /** Reset Songslist */
  684. this.updateSongsList([]);
  685. const shortcutNames = [
  686. "station.pauseResume",
  687. "station.skipStation",
  688. "station.lowerVolumeLarge",
  689. "station.lowerVolumeSmall",
  690. "station.increaseVolumeLarge",
  691. "station.increaseVolumeSmall",
  692. "station.toggleDebug"
  693. ];
  694. shortcutNames.forEach(shortcutName => {
  695. keyboardShortcuts.unregisterShortcut(shortcutName);
  696. });
  697. },
  698. methods: {
  699. isOwnerOnly() {
  700. return this.loggedIn && this.userId === this.station.owner;
  701. },
  702. isAdminOnly() {
  703. return this.loggedIn && this.role === "admin";
  704. },
  705. isOwnerOrAdmin() {
  706. return this.isOwnerOnly() || this.isAdminOnly();
  707. },
  708. openSettings() {
  709. this.openModal({
  710. sector: "station",
  711. modal: "editStation"
  712. });
  713. },
  714. removeFromQueue(songId) {
  715. window.socket.emit(
  716. "stations.removeFromQueue",
  717. this.station._id,
  718. songId,
  719. res => {
  720. if (res.status === "success") {
  721. new Toast({
  722. content:
  723. "Successfully removed song from the queue.",
  724. timeout: 4000
  725. });
  726. } else new Toast({ content: res.message, timeout: 8000 });
  727. }
  728. );
  729. },
  730. youtubeReady() {
  731. if (!this.player) {
  732. this.player = new window.YT.Player("stationPlayer", {
  733. height: 270,
  734. width: 480,
  735. videoId: this.currentSong.songId,
  736. host: "https://www.youtube-nocookie.com",
  737. startSeconds:
  738. this.getTimeElapsed() / 1000 +
  739. this.currentSong.skipDuration,
  740. playerVars: {
  741. controls: 0,
  742. iv_load_policy: 3,
  743. rel: 0,
  744. showinfo: 0,
  745. disablekb: 1
  746. },
  747. events: {
  748. onReady: () => {
  749. this.playerReady = true;
  750. let volume = parseInt(
  751. localStorage.getItem("volume")
  752. );
  753. volume = typeof volume === "number" ? volume : 20;
  754. this.player.setVolume(volume);
  755. if (volume > 0) {
  756. this.player.unMute();
  757. }
  758. if (this.muted) this.player.mute();
  759. this.playVideo();
  760. },
  761. onError: err => {
  762. console.log("iframe error", err);
  763. if (this.loggedIn) {
  764. new Toast({
  765. content:
  766. "Error with YouTube Embed, voted to skip the current song.",
  767. timeout: 8000
  768. });
  769. this.voteSkipStation();
  770. } else {
  771. new Toast({
  772. content: "Error with YouTube Embed",
  773. timeout: 8000
  774. });
  775. }
  776. },
  777. onStateChange: event => {
  778. if (
  779. event.data === window.YT.PlayerState.PLAYING &&
  780. this.videoLoading === true
  781. ) {
  782. this.videoLoading = false;
  783. this.player.seekTo(
  784. this.getTimeElapsed() / 1000 +
  785. this.currentSong.skipDuration,
  786. true
  787. );
  788. if (this.localPaused || this.stationPaused)
  789. this.player.pauseVideo();
  790. } else if (
  791. event.data === window.YT.PlayerState.PLAYING &&
  792. (this.localPaused || this.stationPaused)
  793. ) {
  794. this.player.seekTo(
  795. this.timeBeforePause / 1000,
  796. true
  797. );
  798. this.player.pauseVideo();
  799. } else if (
  800. event.data === window.YT.PlayerState.PLAYING &&
  801. this.seeking === true
  802. ) {
  803. this.seeking = false;
  804. }
  805. if (
  806. event.data === window.YT.PlayerState.PAUSED &&
  807. !this.localPaused &&
  808. !this.stationPaused &&
  809. !this.noSong &&
  810. this.player.getDuration() / 1000 <
  811. this.currentSong.duration
  812. ) {
  813. this.player.seekTo(
  814. this.getTimeElapsed() / 1000 +
  815. this.currentSong.skipDuration,
  816. true
  817. );
  818. this.player.playVideo();
  819. }
  820. }
  821. }
  822. });
  823. }
  824. },
  825. getTimeElapsed() {
  826. if (this.currentSong) {
  827. let { timePaused } = this;
  828. if (this.stationPaused)
  829. timePaused += Date.currently() - this.pausedAt;
  830. return Date.currently() - this.startedAt - timePaused;
  831. }
  832. return 0;
  833. },
  834. playVideo() {
  835. if (this.playerReady) {
  836. this.videoLoading = true;
  837. this.player.loadVideoById(
  838. this.currentSong.songId,
  839. this.getTimeElapsed() / 1000 + this.currentSong.skipDuration
  840. );
  841. if (window.stationInterval !== 0)
  842. clearInterval(window.stationInterval);
  843. window.stationInterval = setInterval(() => {
  844. this.resizeSeekerbar();
  845. this.calculateTimeElapsed();
  846. }, 150);
  847. }
  848. },
  849. resizeSeekerbar() {
  850. if (!this.stationPaused) {
  851. document.getElementById(
  852. "seeker-bar"
  853. ).style.width = `${parseFloat(
  854. (this.getTimeElapsed() / 1000 / this.currentSong.duration) *
  855. 100
  856. )}%`;
  857. }
  858. },
  859. calculateTimeElapsed() {
  860. if (
  861. this.playerReady &&
  862. this.currentSong &&
  863. this.player.getPlayerState() === -1
  864. ) {
  865. if (this.attemptsToPlayVideo >= 5) {
  866. if (
  867. Date.now() - this.lastTimeRequestedIfCanAutoplay >
  868. 2000
  869. ) {
  870. this.lastTimeRequestedIfCanAutoplay = Date.now();
  871. window.canAutoplay.video().then(({ result }) => {
  872. if (result) {
  873. this.attemptsToPlayVideo = 0;
  874. this.canAutoplay = true;
  875. } else {
  876. this.canAutoplay = false;
  877. }
  878. });
  879. }
  880. } else {
  881. this.player.playVideo();
  882. this.attemptsToPlayVideo += 1;
  883. }
  884. }
  885. if (!this.stationPaused && !this.localPaused) {
  886. const timeElapsed = this.getTimeElapsed();
  887. const currentPlayerTime =
  888. Math.max(
  889. this.player.getCurrentTime() -
  890. this.currentSong.skipDuration,
  891. 0
  892. ) * 1000;
  893. const difference = timeElapsed - currentPlayerTime;
  894. // console.log(difference);
  895. let playbackRate = 1;
  896. if (difference < -2000) {
  897. if (!this.seeking) {
  898. this.seeking = true;
  899. this.player.seekTo(
  900. this.getTimeElapsed() / 1000 +
  901. this.currentSong.skipDuration
  902. );
  903. }
  904. } else if (difference < -200) {
  905. // console.log("Difference0.8");
  906. playbackRate = 0.8;
  907. } else if (difference < -50) {
  908. // console.log("Difference0.9");
  909. playbackRate = 0.9;
  910. } else if (difference < -25) {
  911. // console.log("Difference0.99");
  912. playbackRate = 0.95;
  913. } else if (difference > 2000) {
  914. if (!this.seeking) {
  915. this.seeking = true;
  916. this.player.seekTo(
  917. this.getTimeElapsed() / 1000 +
  918. this.currentSong.skipDuration
  919. );
  920. }
  921. } else if (difference > 200) {
  922. // console.log("Difference1.2");
  923. playbackRate = 1.2;
  924. } else if (difference > 50) {
  925. // console.log("Difference1.1");
  926. playbackRate = 1.1;
  927. } else if (difference > 25) {
  928. // console.log("Difference1.01");
  929. playbackRate = 1.05;
  930. } else if (this.player.getPlaybackRate !== 1.0) {
  931. // console.log("NDifference1.0");
  932. this.player.setPlaybackRate(1.0);
  933. }
  934. if (this.playbackRate !== playbackRate) {
  935. this.player.setPlaybackRate(playbackRate);
  936. this.playbackRate = playbackRate;
  937. }
  938. }
  939. /* if (this.currentTime !== undefined && this.paused) {
  940. this.timePaused += Date.currently() - this.currentTime;
  941. this.currentTime = undefined;
  942. } */
  943. let { timePaused } = this;
  944. if (this.stationPaused)
  945. timePaused += Date.currently() - this.pausedAt;
  946. const duration =
  947. (Date.currently() - this.startedAt - timePaused) / 1000;
  948. const songDuration = this.currentSong.duration;
  949. if (songDuration <= duration) this.player.pauseVideo();
  950. if (!this.stationPaused && duration <= songDuration)
  951. this.timeElapsed = utils.formatTime(duration);
  952. },
  953. toggleLock() {
  954. window.socket.emit("stations.toggleLock", this.station._id, res => {
  955. if (res.status === "success") {
  956. new Toast({
  957. content: "Successfully toggled the queue lock.",
  958. timeout: 4000
  959. });
  960. } else new Toast({ content: res.message, timeout: 8000 });
  961. });
  962. },
  963. changeVolume() {
  964. const volume = this.volumeSliderValue;
  965. localStorage.setItem("volume", volume / 100);
  966. if (this.playerReady) {
  967. this.player.setVolume(volume / 100);
  968. if (volume > 0) {
  969. this.player.unMute();
  970. localStorage.setItem("muted", false);
  971. this.muted = false;
  972. }
  973. }
  974. },
  975. resumeLocalStation() {
  976. this.updateLocalPaused(false);
  977. if (!this.stationPaused) this.resumeLocalPlayer();
  978. },
  979. pauseLocalStation() {
  980. this.updateLocalPaused(true);
  981. this.pauseLocalPlayer();
  982. },
  983. resumeLocalPlayer() {
  984. if (!this.noSong) {
  985. if (this.playerReady) {
  986. this.player.seekTo(
  987. this.getTimeElapsed() / 1000 +
  988. this.currentSong.skipDuration
  989. );
  990. this.player.playVideo();
  991. }
  992. }
  993. },
  994. pauseLocalPlayer() {
  995. if (!this.noSong) {
  996. this.timeBeforePause = this.getTimeElapsed();
  997. if (this.playerReady) this.player.pauseVideo();
  998. }
  999. },
  1000. skipStation() {
  1001. this.socket.emit("stations.forceSkip", this.station._id, data => {
  1002. if (data.status !== "success")
  1003. new Toast({
  1004. content: `Error: ${data.message}`,
  1005. timeout: 8000
  1006. });
  1007. else
  1008. new Toast({
  1009. content:
  1010. "Successfully skipped the station's current song.",
  1011. timeout: 4000
  1012. });
  1013. });
  1014. },
  1015. voteSkipStation() {
  1016. this.socket.emit("stations.voteSkip", this.station._id, data => {
  1017. if (data.status !== "success")
  1018. new Toast({
  1019. content: `Error: ${data.message}`,
  1020. timeout: 8000
  1021. });
  1022. else
  1023. new Toast({
  1024. content: "Successfully voted to skip the current song.",
  1025. timeout: 4000
  1026. });
  1027. });
  1028. },
  1029. resumeStation() {
  1030. this.socket.emit("stations.resume", this.station._id, data => {
  1031. if (data.status !== "success")
  1032. new Toast({
  1033. content: `Error: ${data.message}`,
  1034. timeout: 8000
  1035. });
  1036. else
  1037. new Toast({
  1038. content: "Successfully resumed the station.",
  1039. timeout: 4000
  1040. });
  1041. });
  1042. },
  1043. pauseStation() {
  1044. this.socket.emit("stations.pause", this.station._id, data => {
  1045. if (data.status !== "success")
  1046. new Toast({
  1047. content: `Error: ${data.message}`,
  1048. timeout: 8000
  1049. });
  1050. else
  1051. new Toast({
  1052. content: "Successfully paused the station.",
  1053. timeout: 4000
  1054. });
  1055. });
  1056. },
  1057. toggleMute() {
  1058. if (this.playerReady) {
  1059. const previousVolume = parseFloat(
  1060. localStorage.getItem("volume")
  1061. );
  1062. const volume =
  1063. this.player.getVolume() * 100 <= 0 ? previousVolume : 0;
  1064. this.muted = !this.muted;
  1065. localStorage.setItem("muted", this.muted);
  1066. this.volumeSliderValue = volume * 100;
  1067. this.player.setVolume(volume);
  1068. if (!this.muted) localStorage.setItem("volume", volume);
  1069. }
  1070. },
  1071. increaseVolume() {
  1072. if (this.playerReady) {
  1073. const previousVolume = parseInt(localStorage.getItem("volume"));
  1074. let volume = previousVolume + 5;
  1075. if (previousVolume === 0) {
  1076. this.muted = false;
  1077. localStorage.setItem("muted", false);
  1078. }
  1079. if (volume > 100) volume = 100;
  1080. this.volumeSliderValue = volume * 100;
  1081. this.player.setVolume(volume);
  1082. localStorage.setItem("volume", volume);
  1083. }
  1084. },
  1085. toggleLike() {
  1086. if (this.liked)
  1087. this.socket.emit(
  1088. "songs.unlike",
  1089. this.currentSong.songId,
  1090. data => {
  1091. if (data.status !== "success")
  1092. new Toast({
  1093. content: `Error: ${data.message}`,
  1094. timeout: 8000
  1095. });
  1096. }
  1097. );
  1098. else
  1099. this.socket.emit(
  1100. "songs.like",
  1101. this.currentSong.songId,
  1102. data => {
  1103. if (data.status !== "success")
  1104. new Toast({
  1105. content: `Error: ${data.message}`,
  1106. timeout: 8000
  1107. });
  1108. }
  1109. );
  1110. },
  1111. toggleDislike() {
  1112. if (this.disliked)
  1113. return this.socket.emit(
  1114. "songs.undislike",
  1115. this.currentSong.songId,
  1116. data => {
  1117. if (data.status !== "success")
  1118. new Toast({
  1119. content: `Error: ${data.message}`,
  1120. timeout: 8000
  1121. });
  1122. }
  1123. );
  1124. return this.socket.emit(
  1125. "songs.dislike",
  1126. this.currentSong.songId,
  1127. data => {
  1128. if (data.status !== "success")
  1129. new Toast({
  1130. content: `Error: ${data.message}`,
  1131. timeout: 8000
  1132. });
  1133. }
  1134. );
  1135. },
  1136. addFirstPrivatePlaylistSongToQueue() {
  1137. let isInQueue = false;
  1138. if (
  1139. this.station.type === "community" &&
  1140. this.station.partyMode === true
  1141. ) {
  1142. this.songsList.forEach(queueSong => {
  1143. if (queueSong.requestedBy === this.userId) isInQueue = true;
  1144. });
  1145. if (!isInQueue && this.privatePlaylistQueueSelected) {
  1146. this.socket.emit(
  1147. "playlists.getFirstSong",
  1148. this.privatePlaylistQueueSelected,
  1149. data => {
  1150. if (data.status === "success") {
  1151. if (data.song) {
  1152. if (data.song.duration < 15 * 60) {
  1153. this.automaticallyRequestedSongId =
  1154. data.song.songId;
  1155. this.socket.emit(
  1156. "stations.addToQueue",
  1157. this.station._id,
  1158. data.song.songId,
  1159. data2 => {
  1160. if (data2.status === "success")
  1161. this.socket.emit(
  1162. "playlists.moveSongToBottom",
  1163. this
  1164. .privatePlaylistQueueSelected,
  1165. data.song.songId
  1166. );
  1167. }
  1168. );
  1169. } else {
  1170. new Toast({
  1171. content: `Top song in playlist was too long to be added.`,
  1172. timeout: 3000
  1173. });
  1174. this.socket.emit(
  1175. "playlists.moveSongToBottom",
  1176. this.privatePlaylistQueueSelected,
  1177. data.song.songId,
  1178. data3 => {
  1179. if (data3.status === "success")
  1180. setTimeout(
  1181. () =>
  1182. this.addFirstPrivatePlaylistSongToQueue(),
  1183. 3000
  1184. );
  1185. }
  1186. );
  1187. }
  1188. } else
  1189. new Toast({
  1190. content: `Selected playlist has no songs.`,
  1191. timeout: 4000
  1192. });
  1193. }
  1194. }
  1195. );
  1196. }
  1197. }
  1198. },
  1199. togglePlayerDebugBox() {
  1200. this.$refs.playerDebugBox.toggleBox();
  1201. },
  1202. resetPlayerDebugBox() {
  1203. this.$refs.playerDebugBox.resetBox();
  1204. },
  1205. join() {
  1206. this.socket.emit("stations.join", this.stationName, res => {
  1207. if (res.status === "success") {
  1208. setTimeout(() => {
  1209. this.loading = false;
  1210. }, 1000); // prevents popping in of youtube embed etc.
  1211. const {
  1212. _id,
  1213. displayName,
  1214. description,
  1215. privacy,
  1216. locked,
  1217. partyMode,
  1218. owner,
  1219. privatePlaylist,
  1220. type,
  1221. genres,
  1222. blacklistedGenres,
  1223. isFavorited,
  1224. theme
  1225. } = res.data;
  1226. this.joinStation({
  1227. _id,
  1228. name: this.stationName,
  1229. displayName,
  1230. description,
  1231. privacy,
  1232. locked,
  1233. partyMode,
  1234. owner,
  1235. privatePlaylist,
  1236. type,
  1237. genres,
  1238. blacklistedGenres,
  1239. isFavorited,
  1240. theme
  1241. });
  1242. if (this.station.theme === "blue") {
  1243. this.theme = "rgb(2, 166, 242)";
  1244. } else if (this.station.theme === "purple") {
  1245. this.theme = "rgb(143, 40, 140)";
  1246. } else if (this.station.theme === "teal") {
  1247. this.theme = "rgb(0, 209, 178)";
  1248. } else if (this.station.theme === "orange") {
  1249. this.theme = "rgb(255, 94, 0)";
  1250. }
  1251. const currentSong = res.data.currentSong
  1252. ? res.data.currentSong
  1253. : {};
  1254. if (currentSong.artists)
  1255. currentSong.artists = currentSong.artists.join(", ");
  1256. if (currentSong && !currentSong.thumbnail)
  1257. currentSong.ytThumbnail = `https://img.youtube.com/vi/${currentSong.songId}/mqdefault.jpg`;
  1258. this.updateCurrentSong(currentSong);
  1259. this.startedAt = res.data.startedAt;
  1260. this.updateStationPaused(res.data.paused);
  1261. this.timePaused = res.data.timePaused;
  1262. this.updateUserCount(res.data.userCount);
  1263. this.updateUsers(res.data.users);
  1264. this.pausedAt = res.data.pausedAt;
  1265. if (res.data.currentSong) {
  1266. this.updateNoSong(false);
  1267. this.youtubeReady();
  1268. this.playVideo();
  1269. this.socket.emit(
  1270. "songs.getOwnSongRatings",
  1271. res.data.currentSong.songId,
  1272. data => {
  1273. if (this.currentSong.songId === data.songId) {
  1274. this.liked = data.liked;
  1275. this.disliked = data.disliked;
  1276. }
  1277. }
  1278. );
  1279. } else {
  1280. if (this.playerReady) this.player.pauseVideo();
  1281. this.updateNoSong(true);
  1282. }
  1283. if (type === "community" && partyMode === true) {
  1284. this.socket.emit("stations.getQueue", _id, res => {
  1285. if (res.status === "success") {
  1286. this.updateSongsList(res.queue);
  1287. }
  1288. });
  1289. }
  1290. if (this.isOwnerOrAdmin()) {
  1291. keyboardShortcuts.registerShortcut(
  1292. "station.pauseResume",
  1293. {
  1294. keyCode: 32,
  1295. shift: false,
  1296. ctrl: true,
  1297. preventDefault: true,
  1298. handler: () => {
  1299. if (this.stationPaused)
  1300. this.resumeStation();
  1301. else this.pauseStation();
  1302. }
  1303. }
  1304. );
  1305. keyboardShortcuts.registerShortcut(
  1306. "station.skipStation",
  1307. {
  1308. keyCode: 39,
  1309. shift: false,
  1310. ctrl: true,
  1311. preventDefault: true,
  1312. handler: () => {
  1313. this.skipStation();
  1314. }
  1315. }
  1316. );
  1317. }
  1318. keyboardShortcuts.registerShortcut(
  1319. "station.lowerVolumeLarge",
  1320. {
  1321. keyCode: 40,
  1322. shift: false,
  1323. ctrl: true,
  1324. preventDefault: true,
  1325. handler: () => {
  1326. this.volumeSliderValue -= 1000;
  1327. this.changeVolume();
  1328. }
  1329. }
  1330. );
  1331. keyboardShortcuts.registerShortcut(
  1332. "station.lowerVolumeSmall",
  1333. {
  1334. keyCode: 40,
  1335. shift: true,
  1336. ctrl: true,
  1337. preventDefault: true,
  1338. handler: () => {
  1339. this.volumeSliderValue -= 100;
  1340. this.changeVolume();
  1341. }
  1342. }
  1343. );
  1344. keyboardShortcuts.registerShortcut(
  1345. "station.increaseVolumeLarge",
  1346. {
  1347. keyCode: 38,
  1348. shift: false,
  1349. ctrl: true,
  1350. preventDefault: true,
  1351. handler: () => {
  1352. this.volumeSliderValue += 1000;
  1353. this.changeVolume();
  1354. }
  1355. }
  1356. );
  1357. keyboardShortcuts.registerShortcut(
  1358. "station.increaseVolumeSmall",
  1359. {
  1360. keyCode: 38,
  1361. shift: true,
  1362. ctrl: true,
  1363. preventDefault: true,
  1364. handler: () => {
  1365. this.volumeSliderValue += 100;
  1366. this.changeVolume();
  1367. }
  1368. }
  1369. );
  1370. keyboardShortcuts.registerShortcut("station.toggleDebug", {
  1371. keyCode: 68,
  1372. shift: false,
  1373. ctrl: true,
  1374. preventDefault: true,
  1375. handler: () => {
  1376. this.togglePlayerDebugBox();
  1377. }
  1378. });
  1379. // UNIX client time before ping
  1380. const beforePing = Date.now();
  1381. this.socket.emit("apis.ping", pong => {
  1382. // UNIX client time after ping
  1383. const afterPing = Date.now();
  1384. // Average time in MS it took between the server responding and the client receiving
  1385. const connectionLatency = (afterPing - beforePing) / 2;
  1386. console.log(connectionLatency, beforePing - afterPing);
  1387. // UNIX server time
  1388. const serverDate = pong.date;
  1389. // Difference between the server UNIX time and the client UNIX time after ping, with the connectionLatency added to the server UNIX time
  1390. const difference =
  1391. serverDate + connectionLatency - afterPing;
  1392. console.log("Difference: ", difference);
  1393. if (difference > 3000 || difference < -3000) {
  1394. console.log(
  1395. "System time difference is bigger than 3 seconds."
  1396. );
  1397. }
  1398. this.systemDifference = difference;
  1399. });
  1400. } else {
  1401. this.loading = false;
  1402. this.exists = false;
  1403. }
  1404. });
  1405. },
  1406. favoriteStation() {
  1407. this.socket.emit(
  1408. "stations.favoriteStation",
  1409. this.station._id,
  1410. res => {
  1411. if (res.status === "success") {
  1412. new Toast({
  1413. content: "Successfully favorited station.",
  1414. timeout: 4000
  1415. });
  1416. } else new Toast({ content: res.message, timeout: 8000 });
  1417. }
  1418. );
  1419. },
  1420. unfavoriteStation() {
  1421. this.socket.emit(
  1422. "stations.unfavoriteStation",
  1423. this.station._id,
  1424. res => {
  1425. if (res.status === "success") {
  1426. new Toast({
  1427. content: "Successfully unfavorited station.",
  1428. timeout: 4000
  1429. });
  1430. } else new Toast({ content: res.message, timeout: 8000 });
  1431. }
  1432. );
  1433. },
  1434. editSong(song) {
  1435. this.editingSongId = song._id;
  1436. this.openModal({ sector: "station", modal: "editSong" });
  1437. },
  1438. ...mapActions("modalVisibility", ["openModal"]),
  1439. ...mapActions("station", [
  1440. "joinStation",
  1441. "updateUserCount",
  1442. "updateUsers",
  1443. "updateCurrentSong",
  1444. "updatePreviousSong",
  1445. "updateSongsList",
  1446. "updateStationPaused",
  1447. "updateLocalPaused",
  1448. "updateNoSong",
  1449. "updateIfStationIsFavorited"
  1450. ]),
  1451. ...mapActions("modals/editSong", ["stopVideo"])
  1452. }
  1453. };
  1454. </script>
  1455. <style lang="scss" scoped>
  1456. @import "../../styles/global.scss";
  1457. #page-loader-container {
  1458. height: inherit;
  1459. #page-loader-content {
  1460. height: inherit;
  1461. position: absolute;
  1462. max-width: 100%;
  1463. width: 1800px;
  1464. transform: translateX(-50%);
  1465. left: 50%;
  1466. }
  1467. #page-loader-layout {
  1468. height: inherit;
  1469. width: 100%;
  1470. }
  1471. }
  1472. #mobile-progress-animation {
  1473. width: 50px;
  1474. animation: rotate 0.8s infinite linear;
  1475. border: 8px solid $primary-color;
  1476. border-right-color: transparent;
  1477. border-radius: 50%;
  1478. height: 50px;
  1479. position: absolute;
  1480. top: 50%;
  1481. left: 50%;
  1482. display: none;
  1483. }
  1484. @keyframes rotate {
  1485. 0% {
  1486. transform: rotate(0deg);
  1487. }
  1488. 100% {
  1489. transform: rotate(360deg);
  1490. }
  1491. }
  1492. .nav,
  1493. .button.is-primary {
  1494. background-color: var(--station-theme) !important;
  1495. }
  1496. .button.is-primary:hover,
  1497. .button.is-primary:focus {
  1498. filter: brightness(90%);
  1499. }
  1500. #player-debug-box {
  1501. .box-body {
  1502. flex-direction: column;
  1503. b {
  1504. color: #000;
  1505. }
  1506. }
  1507. }
  1508. .night-mode {
  1509. #currently-playing-container,
  1510. #about-station-container,
  1511. #control-bar-container,
  1512. .player-container {
  1513. background-color: $night-mode-bg-secondary !important;
  1514. }
  1515. #video-container,
  1516. #control-bar-container,
  1517. .quadrant:not(#sidebar-container),
  1518. .player-container {
  1519. border: 0 !important;
  1520. }
  1521. #seeker-bar-container {
  1522. background-color: $night-mode-bg-secondary !important;
  1523. }
  1524. #dropdown-toggle {
  1525. background-color: $dark-grey-2 !important;
  1526. border: 0;
  1527. i {
  1528. color: #fff;
  1529. }
  1530. }
  1531. }
  1532. #station-outer-container {
  1533. margin: 0 auto;
  1534. padding: 20px 40px;
  1535. height: 100%;
  1536. width: 100%;
  1537. max-width: 1800px;
  1538. display: flex;
  1539. #station-inner-container {
  1540. height: 100%;
  1541. width: 100%;
  1542. min-height: calc(100vh - 428px);
  1543. display: flex;
  1544. flex-direction: row;
  1545. flex-wrap: wrap;
  1546. .row {
  1547. display: flex;
  1548. flex-direction: row;
  1549. max-width: 100%;
  1550. }
  1551. .column {
  1552. display: flex;
  1553. flex-direction: column;
  1554. }
  1555. .quadrant {
  1556. border-radius: 5px;
  1557. margin: 10px;
  1558. flex-grow: 1;
  1559. }
  1560. .quadrant:not(#sidebar-container) {
  1561. background-color: #fff;
  1562. border: 1px solid $light-grey-2;
  1563. }
  1564. #station-left-column {
  1565. padding: 0;
  1566. }
  1567. #station-right-column {
  1568. max-width: 650px;
  1569. padding: 0;
  1570. }
  1571. #about-station-container {
  1572. padding: 20px;
  1573. display: flex;
  1574. flex-direction: column;
  1575. flex-grow: unset;
  1576. #station-info {
  1577. #station-name {
  1578. flex-direction: row !important;
  1579. h1 {
  1580. margin: 0;
  1581. font-size: 36px;
  1582. line-height: 0.8;
  1583. }
  1584. i {
  1585. margin-left: 10px;
  1586. font-size: 30px;
  1587. color: $yellow;
  1588. }
  1589. }
  1590. p {
  1591. max-width: 700px;
  1592. margin-bottom: 10px;
  1593. }
  1594. }
  1595. #admin-buttons {
  1596. display: flex;
  1597. .button {
  1598. margin: 3px;
  1599. }
  1600. }
  1601. }
  1602. #current-next-row {
  1603. display: flex;
  1604. flex-direction: row;
  1605. #currently-playing-container,
  1606. #next-up-container {
  1607. overflow: hidden;
  1608. flex-basis: 50%;
  1609. .nothing-here-text {
  1610. height: 100%;
  1611. }
  1612. }
  1613. }
  1614. .player-container {
  1615. height: inherit;
  1616. background-color: #fff;
  1617. display: flex;
  1618. flex-direction: column;
  1619. border: 1px solid $light-grey-2;
  1620. border-radius: 5px;
  1621. overflow: hidden;
  1622. flex-grow: 1;
  1623. &.nothing-here-text {
  1624. margin: 10px;
  1625. }
  1626. #video-container {
  1627. width: 100%;
  1628. height: 100%;
  1629. .player-cannot-autoplay {
  1630. position: relative;
  1631. width: 100%;
  1632. height: 100%;
  1633. bottom: calc(100% + 5px);
  1634. background: var(--station-theme);
  1635. display: flex;
  1636. align-items: center;
  1637. justify-content: center;
  1638. p {
  1639. color: $white;
  1640. font-size: 26px;
  1641. text-align: center;
  1642. }
  1643. }
  1644. }
  1645. #seeker-bar-container {
  1646. background-color: #fff;
  1647. position: relative;
  1648. height: 7px;
  1649. display: block;
  1650. width: 100%;
  1651. overflow: hidden;
  1652. #seeker-bar {
  1653. background-color: var(--station-theme);
  1654. top: 0;
  1655. left: 0;
  1656. bottom: 0;
  1657. position: absolute;
  1658. }
  1659. }
  1660. #control-bar-container {
  1661. display: flex;
  1662. justify-content: space-around;
  1663. padding: 10px 0;
  1664. width: 100%;
  1665. background: #fff;
  1666. flex-direction: column;
  1667. flex-flow: wrap;
  1668. .button:not(#dropdown-toggle) {
  1669. width: 75px;
  1670. }
  1671. #left-buttons,
  1672. #right-buttons {
  1673. margin: 3px;
  1674. }
  1675. #left-buttons {
  1676. display: flex;
  1677. .button:not(:first-of-type) {
  1678. margin-left: 5px;
  1679. }
  1680. }
  1681. #duration {
  1682. margin: 3px;
  1683. display: flex;
  1684. align-items: center;
  1685. p {
  1686. font-size: 22px;
  1687. /** prevents duration width slightly varying and shifting other controls slightly */
  1688. width: 150px;
  1689. text-align: center;
  1690. }
  1691. }
  1692. #volume-control {
  1693. margin: 3px;
  1694. margin-top: 0;
  1695. display: flex;
  1696. align-items: center;
  1697. cursor: pointer;
  1698. .volume-slider {
  1699. width: 100%;
  1700. padding: 0 15px;
  1701. background: transparent;
  1702. min-width: 100px;
  1703. }
  1704. input[type="range"] {
  1705. -webkit-appearance: none;
  1706. margin: 7.3px 0;
  1707. }
  1708. input[type="range"]:focus {
  1709. outline: none;
  1710. }
  1711. input[type="range"]::-webkit-slider-runnable-track {
  1712. width: 100%;
  1713. height: 5.2px;
  1714. cursor: pointer;
  1715. box-shadow: 0;
  1716. background: $light-grey-2;
  1717. border-radius: 0;
  1718. border: 0;
  1719. }
  1720. input[type="range"]::-webkit-slider-thumb {
  1721. box-shadow: 0;
  1722. border: 0;
  1723. height: 19px;
  1724. width: 19px;
  1725. border-radius: 15px;
  1726. background: var(--station-theme);
  1727. cursor: pointer;
  1728. -webkit-appearance: none;
  1729. margin-top: -6.5px;
  1730. }
  1731. input[type="range"]::-moz-range-track {
  1732. width: 100%;
  1733. height: 5.2px;
  1734. cursor: pointer;
  1735. box-shadow: 0;
  1736. background: $light-grey-2;
  1737. border-radius: 0;
  1738. border: 0;
  1739. }
  1740. input[type="range"]::-moz-range-thumb {
  1741. box-shadow: 0;
  1742. border: 0;
  1743. height: 19px;
  1744. width: 19px;
  1745. border-radius: 15px;
  1746. background: var(--station-theme);
  1747. cursor: pointer;
  1748. -webkit-appearance: none;
  1749. margin-top: -6.5px;
  1750. }
  1751. input[type="range"]::-ms-track {
  1752. width: 100%;
  1753. height: 5.2px;
  1754. cursor: pointer;
  1755. box-shadow: 0;
  1756. background: $light-grey-2;
  1757. border-radius: 1.3px;
  1758. }
  1759. input[type="range"]::-ms-fill-lower {
  1760. background: $light-grey-2;
  1761. border: 0;
  1762. border-radius: 0;
  1763. box-shadow: 0;
  1764. }
  1765. input[type="range"]::-ms-fill-upper {
  1766. background: $light-grey-2;
  1767. border: 0;
  1768. border-radius: 0;
  1769. box-shadow: 0;
  1770. }
  1771. input[type="range"]::-ms-thumb {
  1772. box-shadow: 0;
  1773. border: 0;
  1774. height: 15px;
  1775. width: 15px;
  1776. border-radius: 15px;
  1777. background: var(--station-theme);
  1778. cursor: pointer;
  1779. -webkit-appearance: none;
  1780. margin-top: 1.5px;
  1781. }
  1782. }
  1783. #right-buttons {
  1784. display: flex;
  1785. #dropdown-toggle {
  1786. width: 35px;
  1787. }
  1788. #dislike-song,
  1789. #add-song-to-playlist .button:not(#dropdown-toggle) {
  1790. margin-left: 5px;
  1791. }
  1792. #ratings {
  1793. display: flex;
  1794. #like-song:hover,
  1795. #like-song.liked {
  1796. background-color: darken($green, 5%) !important;
  1797. }
  1798. #dislike-song:hover,
  1799. #dislike-song.disliked {
  1800. background-color: darken($red, 5%) !important;
  1801. }
  1802. &.liked #dislike-song,
  1803. &.disliked #like-song {
  1804. background-color: $grey !important;
  1805. &:hover {
  1806. background-color: darken($grey, 5%) !important;
  1807. }
  1808. }
  1809. }
  1810. #add-song-to-playlist {
  1811. display: flex;
  1812. flex-direction: column-reverse;
  1813. .control {
  1814. width: fit-content;
  1815. margin-bottom: 0 !important;
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. #sidebar-container {
  1822. border-top: 0;
  1823. position: relative;
  1824. height: inherit;
  1825. }
  1826. }
  1827. }
  1828. .footer {
  1829. margin-top: 30px;
  1830. }
  1831. /deep/ .nothing-here-text {
  1832. display: flex;
  1833. align-items: center;
  1834. justify-content: center;
  1835. }
  1836. @media (max-width: 950px) {
  1837. #mobile-progress-animation {
  1838. display: block;
  1839. }
  1840. #page-loader-container {
  1841. display: none;
  1842. }
  1843. #station-outer-container {
  1844. padding: 10px;
  1845. height: unset;
  1846. max-width: 700px;
  1847. #station-inner-container {
  1848. flex-direction: column;
  1849. #station-left-column {
  1850. #current-next-row {
  1851. flex-direction: column;
  1852. }
  1853. #control-bar-container {
  1854. #duration,
  1855. #volume-control,
  1856. #right-buttons,
  1857. #left-buttons {
  1858. margin-bottom: 5px;
  1859. justify-content: center;
  1860. }
  1861. #duration {
  1862. order: 1;
  1863. }
  1864. #volume-control {
  1865. order: 2;
  1866. max-width: 400px;
  1867. }
  1868. #right-buttons {
  1869. order: 3;
  1870. flex-wrap: wrap;
  1871. #ratings {
  1872. flex-wrap: wrap;
  1873. }
  1874. }
  1875. #left-buttons {
  1876. order: 4;
  1877. flex-wrap: wrap;
  1878. }
  1879. }
  1880. }
  1881. #station-right-column {
  1882. max-width: unset;
  1883. #about-station-container #admin-buttons {
  1884. flex-wrap: wrap;
  1885. }
  1886. #sidebar-container {
  1887. min-height: 350px;
  1888. }
  1889. }
  1890. }
  1891. }
  1892. }
  1893. </style>