index.vue 53 KB

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