index.vue 53 KB

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