index.vue 48 KB

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