index.vue 49 KB

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