gitoria

jukebox

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita8098271a8098271Mission 004: jukebox#21mrea8098271/components/main.hl

21.8 KB

  1. // components/main.hl — THE SHELL: the layouts header with the main menu (the phone's sidebar behind the toggle), the slot every screen renders
  2. // into, and the PLAYER BAR at the bottom. The shell stays when a screen is replaced by a click on a link (hl:web navigates in the page), so the song keeps playing
  3. // while you browse. A screen starts a song with `emit jbPlay(ctx, index, id)`: the context says which list the song was tapped in (`{ kind, sort, minPlays, ... }`,
  4. // lib/rows.hl), the id WHICH SONG (the id decides, the server looks the song up in the list as it is now; the index is only where the screen saw it, counted plays move songs). A screen starts a shuffle with `emit jbShuffle(spec)` (lib/queue.hl: favourites or the list the screen shows); the server then holds the
  5. // shuffled order and the browser asks for 40 songs at a time. The queue of the media player always starts at the song that plays: the bar shows it, the overlay lists the 20 after it.
  6. // THE NOW-PLAYING OVERLAY is the same bar and the same media player, drawn bigger by CSS: a tap on the bar opens it (full screen on the phone, a side panel from 60rem), the
  7. // close button, the Escape key or a swipe down closes it. THE COUNT: a song counts as played after half of its length or 4 minutes of listening (whichever comes first); the shell counts
  8. // the seconds the audio really plays (a one second timer), asks the server once (`jbPlayed`) and the jukebox database adds 1 to its own counter. The files are never written.
  9. // KEYBOARD: NOT HERE. Every key handler of the shell (document listener, body, the app div) made the audio element load its source again on each key press (the song
  10. // restarted): Hybriel gap, repro in reports/JB3b-keyboard-gap.md. The media player's own keys (Space, arrows on its audio element) stay as they are.
  11. // LOCK SCREEN: the browser's media session shows title, artist, album and cover and gives play, pause, previous and next to the lock screen and the headphone keys.
  12. import AppHeader from '../theme/shell/app-header.hl'
  13. import MainMenu from '../theme/shell/main-menu.hl'
  14. import Sidebar from '../theme/shell/app-sidebar.hl'
  15. import MediaPlayer from './media-player/media-player.hl'
  16. import Icon from './icons/icons.hl'
  17. import { now } from 'hl:time'
  18. import { rowsFor, queueFor } from '../lib/rows.hl'
  19. import { countPlay } from '../lib/plays.hl'
  20. import { showOf } from '../lib/dups.hl'
  21. slot = null
  22. menu = [ { label = 'Songs' href = '/' current = false } { label = 'Artists' href = '/artists' } { label = 'Albums' href = '/albums' } { label = 'Search' href = '/search' } ]
  23. // the player: what plays now, and the songs that follow in the list it came from (the first item of the queue is the song that plays)
  24. String nowSrc = ''
  25. String nowTitle = ''
  26. String nowArtist = ''
  27. String nowAlbum = ''
  28. String nowCover = ''
  29. String nowArt = ''
  30. String nowId = ''
  31. String autoPlay = 'false'
  32. Hybrid nowQueue = []
  33. Hybrid nowCtx = {}
  34. Number nowIdx = 0
  35. String overlay = 'false'
  36. String barClass = 'jb-app'
  37. String coverNow = overlay == 'true' ? nowArt : nowCover
  38. Number heard = 0
  39. String countedId = ''
  40. Number swipeY = -1
  41. String ticking = 'false'
  42. Style {
  43. // Keep the quoted class selector and its original specificity.
  44. '.jb-app' { '--jb-bar' = '0rem' }
  45. // Keyframes use the documented quoted animation key.
  46. '@keyframes jb-mount' {
  47. 'from' { opacity = '.999' }
  48. to { opacity = '1' }
  49. }
  50. jbTick {
  51. display = 'block'
  52. height = '0'
  53. animation = 'jb-mount 100ms linear infinite'
  54. }
  55. // Caller page supplies jb-screen through the slot; retain its exact tag selector.
  56. 'jb-screen' {
  57. display = 'flex'
  58. flexDirection = 'column'
  59. height = 'calc(100dvh - var(--layout-header) - var(--jb-bar))'
  60. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  61. paddingTop = '.5rem'
  62. // Keep the quoted child selector into the composed virtual list.
  63. '> virtual-list' {
  64. flex = '1 1 auto'
  65. height = 'auto'
  66. minHeight = '0'
  67. marginInline = '-.6rem'
  68. }
  69. @media {
  70. minWidth = '60rem'
  71. paddingTop = '1rem'
  72. }
  73. }
  74. // Keep the quoted class selector and its original specificity.
  75. '.jb-bar' {
  76. display = 'none'
  77. mediaPlayer {
  78. display = 'contents'
  79. // Keep the quoted selector into the composed media player.
  80. '.mp-cover' {
  81. gridArea = 'cover'
  82. display = 'flex'
  83. alignItems = 'center'
  84. gap = '.6rem'
  85. margin = '0'
  86. minWidth = '0'
  87. paddingInline = 'max(var(--layout-gutter), calc((100% - var(--layout-column)) / 2))'
  88. cursor = 'pointer'
  89. div { minWidth = '0' }
  90. p {
  91. margin = '0'
  92. fontSize = '.8rem'
  93. overflow = 'hidden'
  94. textOverflow = 'ellipsis'
  95. whiteSpace = 'nowrap'
  96. }
  97. img {
  98. width = '2.5rem'
  99. height = '2.5rem'
  100. }
  101. h2 {
  102. margin = '0'
  103. fontSize = '.95rem'
  104. lineHeight = '1.3'
  105. fontWeight = '600'
  106. overflow = 'hidden'
  107. textOverflow = 'ellipsis'
  108. whiteSpace = 'nowrap'
  109. }
  110. }
  111. mpButtons {
  112. display = 'contents'
  113. // Keep the quoted selector into the composed media player.
  114. '.mp-play' {
  115. gridArea = 'buttons'
  116. background = 'transparent'
  117. }
  118. // Keep the quoted selector into the composed media player.
  119. '.mp-back' { display = 'none' }
  120. // Keep the quoted selector into the composed media player.
  121. '.mp-forward' { display = 'none' }
  122. // Keep the quoted selector into the composed media player.
  123. '.mp-mute' { display = 'none' }
  124. // Keep the quoted selector into the composed media player.
  125. '.mp-speed' { display = 'none' }
  126. // Keep the quoted selector into the composed media player.
  127. '.mp-times' { display = 'none' }
  128. }
  129. mpSeek { gridArea = 'seek' }
  130. audio { display = 'none' }
  131. }
  132. // Keep the quoted class selector and its original specificity.
  133. '.jb-close' {
  134. display = 'none'
  135. hover { background = 'var(--color-surface)' }
  136. }
  137. // Keep the quoted class selector and its original specificity.
  138. '.jb-album' { display = 'none' }
  139. // Keep the quoted class selector and its original specificity.
  140. 'button.jb-prev' {
  141. display = 'inline-flex'
  142. alignItems = 'center'
  143. justifyContent = 'center'
  144. minWidth = '2.75rem'
  145. minHeight = '2.75rem'
  146. margin = '0'
  147. padding = '0'
  148. color = 'var(--color-text)'
  149. background = 'transparent'
  150. borderRadius = 'var(--radius-small)'
  151. gridArea = 'prev'
  152. hover { background = 'var(--color-surface)' }
  153. }
  154. // Keep the quoted class selector and its original specificity.
  155. 'button.jb-next' {
  156. display = 'inline-flex'
  157. alignItems = 'center'
  158. justifyContent = 'center'
  159. minWidth = '2.75rem'
  160. minHeight = '2.75rem'
  161. margin = '0'
  162. padding = '0'
  163. color = 'var(--color-text)'
  164. background = 'transparent'
  165. borderRadius = 'var(--radius-small)'
  166. gridArea = 'next'
  167. marginRight = 'max(.25rem, calc((100vw - var(--layout-column)) / 2))'
  168. hover { background = 'var(--color-surface)' }
  169. }
  170. }
  171. // Keep the quoted class selector and its original specificity.
  172. '.jb-app.playing' {
  173. '--jb-bar' = '4.625rem'
  174. // Keep the quoted class selector and its original specificity.
  175. '.jb-bar' {
  176. display = 'grid'
  177. position = 'fixed'
  178. left = '0'
  179. right = '0'
  180. bottom = '0'
  181. zIndex = '15'
  182. height = 'var(--jb-bar)'
  183. background = 'var(--color-background-sunken)'
  184. gridTemplateColumns = 'minmax(0, 1fr) auto auto auto'
  185. gridTemplateRows = '1.375rem 1fr'
  186. gridTemplateAreas = '"seek seek seek seek" "cover prev buttons next"'
  187. alignItems = 'center'
  188. }
  189. @media {
  190. minWidth = '60rem'
  191. '--jb-bar' = '5.125rem'
  192. }
  193. }
  194. // Keep the quoted condition: :not() has no bare form.
  195. '.jb-app:not(.open)' {
  196. // Keep the quoted class selector and its original specificity.
  197. '.jb-bar' {
  198. mediaPlayer {
  199. mpSeek {
  200. height = '1.375rem'
  201. margin = '0'
  202. // Keep the quoted selector into the composed media player.
  203. '.mp-track' {
  204. top = '0'
  205. left = '0'
  206. right = '0'
  207. height = '1.375rem'
  208. borderRadius = '0'
  209. }
  210. // Keep the quoted selector into the composed media player.
  211. '.mp-thumb' { display = 'none' }
  212. }
  213. // Keep the quoted condition: :not() has no bare form.
  214. '> div:not(.mp-cover)' { display = 'none' }
  215. mpButtons {
  216. // Keep the quoted selector into the composed media player.
  217. '.mp-times' {
  218. @media {
  219. minWidth = '60rem'
  220. display = 'inline-flex'
  221. marginLeft = '.5rem'
  222. }
  223. }
  224. }
  225. }
  226. }
  227. }
  228. // Keep the quoted class selector and its original specificity.
  229. '.jb-app.open' {
  230. '--jb-bar' = '0rem'
  231. // Keep the quoted class selector and its original specificity.
  232. '.jb-bar' {
  233. display = 'grid'
  234. position = 'fixed'
  235. top = '0'
  236. left = '0'
  237. right = '0'
  238. bottom = '0'
  239. zIndex = '40'
  240. height = 'auto'
  241. background = 'var(--color-background)'
  242. gridTemplateColumns = '1fr 3rem 3rem 3.5rem 3rem 3rem 1fr'
  243. gridTemplateRows = 'auto auto auto auto auto auto minmax(0, 1fr)'
  244. gridTemplateAreas = 'none'
  245. alignItems = 'center'
  246. justifyItems = 'center'
  247. touchAction = 'none'
  248. paddingBottom = 'env(safe-area-inset-bottom)'
  249. // Keep the quoted class selector and its original specificity.
  250. '.jb-close' {
  251. display = 'inline-flex'
  252. gridColumn = '1 / -1'
  253. gridRow = '1'
  254. justifySelf = 'end'
  255. alignItems = 'center'
  256. justifyContent = 'center'
  257. minWidth = '2.75rem'
  258. minHeight = '2.75rem'
  259. margin = '.25rem .5rem 0'
  260. padding = '0'
  261. color = 'var(--color-text)'
  262. background = 'transparent'
  263. borderRadius = 'var(--radius-small)'
  264. }
  265. mediaPlayer {
  266. // Keep the quoted selector into the composed media player.
  267. '.mp-cover' {
  268. gridArea = 'auto'
  269. gridColumn = '1 / -1'
  270. gridRow = '2'
  271. flexDirection = 'column'
  272. gap = '.6rem'
  273. width = '100%'
  274. paddingInline = '1.5rem'
  275. cursor = 'default'
  276. textAlign = 'center'
  277. p {
  278. fontSize = '1rem'
  279. whiteSpace = 'normal'
  280. textAlign = 'center'
  281. }
  282. img {
  283. width = 'clamp(0px, calc(100dvh - 36rem), min(calc(100vw - 3rem), 32dvh))'
  284. height = 'clamp(0px, calc(100dvh - 36rem), min(calc(100vw - 3rem), 32dvh))'
  285. maxWidth = '100%'
  286. @media {
  287. maxHeight = '41rem'
  288. display = 'none'
  289. }
  290. @media {
  291. minWidth = '60rem'
  292. width = 'clamp(0px, calc(100dvh - 36rem), min(18rem, 32dvh))'
  293. height = 'clamp(0px, calc(100dvh - 36rem), min(18rem, 32dvh))'
  294. }
  295. }
  296. h2 {
  297. fontSize = '1.25rem'
  298. overflow = 'visible'
  299. whiteSpace = 'normal'
  300. textAlign = 'center'
  301. }
  302. }
  303. mpSeek {
  304. gridArea = 'auto'
  305. gridColumn = '1 / -1'
  306. gridRow = '4'
  307. justifySelf = 'stretch'
  308. height = '1.375rem'
  309. marginInline = '1.25rem'
  310. // Keep the quoted selector into the composed media player.
  311. '.mp-track' {
  312. top = '0'
  313. height = '1.375rem'
  314. }
  315. // Keep the quoted selector into the composed media player.
  316. '.mp-thumb' { display = 'none' }
  317. }
  318. mpButtons {
  319. // Keep the quoted selector into the composed media player.
  320. '.mp-back' {
  321. display = 'inline-flex'
  322. gridColumn = '3'
  323. gridRow = '5'
  324. }
  325. // Keep the quoted selector into the composed media player.
  326. '.mp-play' {
  327. gridArea = 'auto'
  328. gridColumn = '4'
  329. gridRow = '5'
  330. background = 'var(--color-surface)'
  331. }
  332. // Keep the quoted selector into the composed media player.
  333. '.mp-forward' {
  334. display = 'inline-flex'
  335. gridColumn = '5'
  336. gridRow = '5'
  337. }
  338. // Keep the quoted selector into the composed media player.
  339. '.mp-times' {
  340. display = 'inline-flex'
  341. gridColumn = '2 / 5'
  342. gridRow = '6'
  343. justifySelf = 'start'
  344. marginLeft = '0'
  345. }
  346. // Keep the quoted selector into the composed media player.
  347. '.mp-mute' {
  348. display = 'inline-flex'
  349. gridColumn = '5'
  350. gridRow = '6'
  351. }
  352. // Keep the quoted selector into the composed media player.
  353. '.mp-speed' {
  354. display = 'inline-flex'
  355. gridColumn = '6'
  356. gridRow = '6'
  357. }
  358. }
  359. // Keep the quoted condition: :not() has no bare form.
  360. '> div:not(.mp-cover)' {
  361. display = 'block'
  362. gridColumn = '1 / -1'
  363. gridRow = '7'
  364. justifySelf = 'stretch'
  365. alignSelf = 'stretch'
  366. minHeight = '0'
  367. overflowY = 'auto'
  368. padding = '0 .75rem .75rem'
  369. touchAction = 'pan-y'
  370. }
  371. // Keep the quoted selector into the composed media player.
  372. '.mp-queue-title' {
  373. margin = '.5rem .25rem .1rem'
  374. fontSize = '.85rem'
  375. letterSpacing = '.04em'
  376. textTransform = 'uppercase'
  377. color = 'var(--color-text-muted)'
  378. }
  379. // Keep the quoted selector into the composed media player.
  380. 'ol.mp-queue' {
  381. // Keep the quoted functional pseudo-class.
  382. 'li:nth-child(n+22)' { display = 'none' }
  383. // Keep the quoted selector into the composed media player.
  384. '.mp-q-title' {
  385. overflow = 'hidden'
  386. textOverflow = 'ellipsis'
  387. whiteSpace = 'nowrap'
  388. overflowWrap = 'normal'
  389. }
  390. }
  391. }
  392. // Keep the quoted class selector and its original specificity.
  393. '.jb-album' {
  394. display = 'block'
  395. gridColumn = '1 / -1'
  396. gridRow = '3'
  397. margin = '.1rem 1.5rem 0'
  398. textAlign = 'center'
  399. color = 'var(--color-text-muted)'
  400. @media {
  401. maxHeight = '41rem'
  402. display = 'none'
  403. }
  404. }
  405. // Keep the quoted class selector and its original specificity.
  406. 'button.jb-prev' {
  407. gridArea = 'auto'
  408. gridColumn = '2'
  409. gridRow = '5'
  410. }
  411. // Keep the quoted class selector and its original specificity.
  412. 'button.jb-next' {
  413. gridArea = 'auto'
  414. gridColumn = '6'
  415. gridRow = '5'
  416. marginRight = '0'
  417. }
  418. @media {
  419. minWidth = '60rem'
  420. top = 'var(--layout-header)'
  421. left = 'auto'
  422. width = '24rem'
  423. zIndex = '15'
  424. }
  425. }
  426. @media {
  427. minWidth = '60rem'
  428. '--jb-bar' = '0rem'
  429. }
  430. // Caller page supplies jb-screen through the slot; retain its exact tag selector.
  431. 'jb-screen' {
  432. @media {
  433. minWidth = '60rem'
  434. marginRight = '24rem'
  435. }
  436. }
  437. }
  438. }
  439. View {
  440. body {
  441. AppHeader { brand = "Jukebox"
  442. MainMenu { items = menu }
  443. }
  444. Sidebar { desktop = "false" MainMenu { items = menu } }
  445. div { class = barClass
  446. slot
  447. jbTick { on animationiteration(e) { emit jbMount(e) } }
  448. div { class = "jb-bar" on click(e) { emit jbBarClick(e) } on pointerdown(e) { emit jbDown(e) } on pointerup(e) { emit jbUp(e) } on pointercancel(e) { emit jbCancel(e) }
  449. button { type = "button" class = "jb-close" title = "Close" 'aria-label' = "Close" Icon { name = "close" size = "1.5em" } on click(e) { emit jbClose(e) } }
  450. MediaPlayer { queueLabel = "Next up" src = nowSrc kind = "audio" title = nowTitle artist = nowArtist cover = coverNow queue = nowQueue onPlay = pickedNext autoPlay = autoPlay }
  451. p { class = "jb-album" nowAlbum }
  452. button { type = "button" class = "jb-prev" title = "Previous song" 'aria-label' = "Previous song" Icon { name = "prevTrack" size = "1.5em" } on click(e) { emit jbPrevClick(e) } }
  453. button { type = "button" class = "jb-next" title = "Next song" 'aria-label' = "Next song" Icon { name = "nextTrack" size = "1.5em" } on click(e) { emit jbNextClick(e) } }
  454. }
  455. }
  456. }
  457. }
  458. // ---- the server's part -------------------------------------------------------------------------------------------------------
  459. // rows of a list for a screen: `{ total, offset, rows }`
  460. on server jbRows(ctx, offset, limit) {
  461. return rowsFor(ctx, offset, limit)
  462. }
  463. // the songs of a list from `index` on, as queue items
  464. on server jbQueue(ctx, index, count, id, step) {
  465. return queueFor(ctx, index, count, id, step)
  466. }
  467. // a new shuffle of a pool (`{ kind: 'favourites', minPlays }` or `{ kind: 'list', ctx }`): its context, with a seed from the clock
  468. on server jbShuffleCtx(spec) {
  469. return { kind = 'shuffle' seed = now() % 2147483000 spec = spec }
  470. }
  471. // the song was listened to long enough: the jukebox database adds 1 to its own counter (the same call as POST /api/played/<id>).
  472. // The open screen is told the new count and writes that row itself.
  473. on server jbPlayed(id) {
  474. c = countPlay(id, now())
  475. if (c != null) { emit client jbPlays(c.id, showOf(c.id, c.filePlays).plays) }
  476. return c
  477. }
  478. // ---- playing -----------------------------------------------------------------------------------------------------------------
  479. setBar = () => {
  480. barClass = 'jb-app' + (nowId != '' ? ' playing' : '') + (overlay == 'true' ? ' open' : '')
  481. }
  482. // the audio element of the media player
  483. audioEl = () => { return document.querySelector('media-player audio') }
  484. // show what plays (a queue item) and start it
  485. showNow = (item) => {
  486. nowSrc = item.src
  487. nowTitle = item.title
  488. nowArtist = item.artist
  489. nowAlbum = item.album
  490. nowCover = item.cover
  491. nowArt = item.art
  492. nowId = item.id
  493. nowIdx = item.idx
  494. heard = 0
  495. countedId = ''
  496. autoPlay = 'true'
  497. setBar()
  498. let ms = window.navigator.mediaSession
  499. if (ms != null) {
  500. ms.metadata = window.Reflect.construct(window.MediaMetadata, [ { title = item.title artist = item.artist album = item.album artwork = [ { src = item.art } ] } ])
  501. }
  502. }
  503. // a queue that starts at the song that plays
  504. fromPlace = (at) => {
  505. out = []
  506. let i = at
  507. while (i < nowQueue.length) {
  508. out.push(nowQueue[i])
  509. i = i + 1
  510. }
  511. return out
  512. }
  513. // the button or row that started a song gives the focus back (the player's own buttons keep it), so Space keeps meaning play / pause
  514. on jbUnfocus() {
  515. f = document.activeElement
  516. if (f != null && f.blur != null && f.closest('media-player') == null) { f.blur() }
  517. return null
  518. }
  519. // a song was tapped in a screen: its list becomes the queue
  520. on jbPlay(ctx, index, id) {
  521. emit jbUnfocus()
  522. items = emit server jbQueue(ctx, index, 40, id)
  523. if (items == null || items.length == 0) { return null }
  524. nowCtx = ctx
  525. nowQueue = items
  526. showNow(items[0])
  527. return null
  528. }
  529. // a shuffle was asked for: a new random order of the pool, played from its start
  530. on jbShuffle(spec) {
  531. emit jbUnfocus()
  532. ctx = emit server jbShuffleCtx(spec)
  533. emit jbPlay(ctx, 0)
  534. return null
  535. }
  536. // the place of a song in the queue, -1 when it is not there
  537. placeOf = (src) => {
  538. let at = -1
  539. let i = 0
  540. while (i < nowQueue.length) {
  541. if (nowQueue[i].src == src) { at = i }
  542. i = i + 1
  543. }
  544. return at
  545. }
  546. // the player picked a queue item (a tap on it, or the end of the song before): it becomes the first of the queue; the queue is refilled when fewer than 25 songs follow
  547. pickedNext = (src) => {
  548. at = placeOf(src)
  549. if (at < 0) { return }
  550. item = nowQueue[at]
  551. nowQueue = fromPlace(at)
  552. showNow(item)
  553. if (nowQueue.length < 25) {
  554. more = emit server jbQueue(nowCtx, item.idx, 40, item.id)
  555. if (more != null && more.length > 0) { nowQueue = more }
  556. }
  557. }
  558. // next song: the second of the queue, or a request when the list has run out of items here
  559. on jbNext() {
  560. if (nowId == '') { return null }
  561. if (nowQueue.length > 1) { pickedNext(nowQueue[1].src) return null }
  562. more = emit server jbQueue(nowCtx, nowIdx + 1, 40, nowId, 1)
  563. if (more != null && more.length > 0) {
  564. nowQueue = more
  565. showNow(more[0])
  566. }
  567. return null
  568. }
  569. // previous song: after 3 seconds into a song the first press starts it again, then the song before it in the list
  570. on jbPrev() {
  571. if (nowId == '') { return null }
  572. let a = audioEl()
  573. if (a != null && a.currentTime > 3) { a.currentTime = 0 return null }
  574. if (nowIdx < 1) { if (a != null) { a.currentTime = 0 } return null }
  575. items = emit server jbQueue(nowCtx, nowIdx - 1, 40, nowId, -1)
  576. if (items != null && items.length > 0) {
  577. nowQueue = items
  578. showNow(items[0])
  579. }
  580. return null
  581. }
  582. // the buttons give the focus back, so Space keeps meaning play / pause
  583. on jbNextClick(e) { e.target.closest('button').blur() emit jbNext() return null }
  584. on jbPrevClick(e) { e.target.closest('button').blur() emit jbPrev() return null }
  585. toggleNow = () => {
  586. let a = audioEl()
  587. if (a == null || nowId == '') { return }
  588. if (a.paused) { a.play() } else { a.pause() }
  589. }
  590. jumpBy = (seconds) => {
  591. let a = audioEl()
  592. if (a == null || nowId == '') { return }
  593. let t = a.currentTime + seconds
  594. if (t < 0) { t = 0 }
  595. if (a.duration > 0 && t > a.duration) { t = a.duration }
  596. a.currentTime = t
  597. }
  598. // ---- the overlay ---------------------------------------------------------------------------------------------------------------
  599. on jbOpen() {
  600. if (nowId == '') { return null }
  601. overlay = 'true'
  602. setBar()
  603. return null
  604. }
  605. on jbClose(e) {
  606. if (e.target != null && e.target.closest != null && e.target.closest('button') != null) { e.target.closest('button').blur() }
  607. overlay = 'false'
  608. setBar()
  609. return null
  610. }
  611. // a tap on the bar (not on a button or the seek line) opens the overlay
  612. on jbBarClick(e) {
  613. if (overlay == 'true') { return null }
  614. if (e.target.closest('button, mp-seek') != null) { return null }
  615. emit jbOpen()
  616. return null
  617. }
  618. // a swipe down over the cover or the title closes it (not over the buttons, the seek line or the queue, which scroll)
  619. on jbDown(e) {
  620. if (overlay != 'true' || e.target.closest('button, mp-seek, ol') != null) { swipeY = -1 return null }
  621. swipeY = e.clientY
  622. return null
  623. }
  624. on jbUp(e) {
  625. if (swipeY >= 0 && e.clientY - swipeY > 80) { overlay = 'false' setBar() }
  626. swipeY = -1
  627. return null
  628. }
  629. on jbCancel(e) { swipeY = -1 return null }
  630. // ---- counting, keys and the lock screen -----------------------------------------------------------------------------------
  631. // every second: the seconds the audio really played; at half the song or 4 minutes the server counts the play, once
  632. on jbTick() {
  633. let a = audioEl()
  634. if (a == null || nowId == '' || a.paused || a.ended) { return null }
  635. heard = heard + 1
  636. let need = 240
  637. if (a.duration > 0 && a.duration / 2 < 240) { need = a.duration / 2 }
  638. if (heard >= need && countedId != nowId) {
  639. countedId = nowId
  640. emit server jbPlayed(nowId)
  641. }
  642. return null
  643. }
  644. // the mount tick (the media player's trick): once the page is live the timer, the keys and the lock screen's buttons are set up
  645. on jbMount(e) {
  646. e.target.style.animationName = 'none'
  647. if (ticking == 'true') { return null }
  648. ticking = 'true'
  649. window.setInterval(() => { emit jbTick() }, 1000)
  650. let ms = window.navigator.mediaSession
  651. if (ms != null) {
  652. ms.setActionHandler('play', () => { toggleNow() })
  653. ms.setActionHandler('pause', () => { toggleNow() })
  654. ms.setActionHandler('previoustrack', () => { emit jbPrev() })
  655. ms.setActionHandler('nexttrack', () => { emit jbNext() })
  656. }
  657. return null
  658. }

Branches

Latest commits

  • a8098271Mission 004: jukebox#21mre
  • df8f5205Records: jukebox#19-21, #11 closedmre
  • b7a4e692Records: hybriel#298mre
  • 9bcbb017Records: day38b waits for day39 fixmre
  • f80504e1Records: day38b repro sentmre
  • 8048258bRecords: day38b jb3 regression, L1 Chromes stoppedmre
  • 68aace7fRecords: mission 003 day38bmre
  • d105d8a9Records: mpackdb integrity check cleanmre
  • 6e980c53Records: mpackdb rule refinementmre
  • 6d335ac4Records: storage copy rulingmre
  • 7eb2898dRecords: mpackdb second-opener rule until day38mre
  • b011f98eRecords: style form live on day35mre
  • 60d90cb2Records: L1 woken for the restartmre
  • 75ae544fRecords: restart waits for the connection to closemre
  • e0b75951Records: L1 merged and pushed, restart waits for an open connectionmre
  • f2b5db98styles: format styles with nested rules and bare queriesmre
  • f036bab4search: format styles with nested rules and bare queriesmre
  • ef9a9d4asongs: format styles with nested rules and bare queriesmre
  • f22f9aacmain: format styles with nested rules and bare queriesmre
  • f56cd7c7Sync icons from 8176eb1 and verify mixed component sourcesmre