Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

52 lines
1.8KB

  1. const VolumeMap = {
  2. isOn: false,
  3. size: 320,
  4. positions: new Map(),
  5. toggle() {
  6. VolumeMap.isOn = !VolumeMap.isOn
  7. },
  8. onremove() {
  9. VolumeMap.positions.clear()
  10. },
  11. getDot(username) {
  12. if(VolumeMap.positions.has(username)) {
  13. return VolumeMap.positions.get(username)
  14. }
  15. return [VolumeMap.size / 2, VolumeMap.size / 2]
  16. },
  17. moveNotify({layerX, layerY}) {
  18. wire({kind: 'volumeMapMove', value: [layerX, layerY]})
  19. },
  20. moveDot({detail: {source, value}}) {
  21. VolumeMap.positions.set(source, value)
  22. const [x0, y0] = VolumeMap.getDot(State.username);
  23. for(const video of document.querySelectorAll('video:not(.self')) {
  24. const [x1, y1] = VolumeMap.getDot(video.username)
  25. const dist1 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2))
  26. const dist2 = VolumeMap.size / Math.pow(dist1, 1.5) - 0.2
  27. const dist3 = Math.max(Math.min(dist2, 1), 0)
  28. video.style.opacity = dist3
  29. video.volume = dist3
  30. video.muted = !dist3 // iPhone does not allow graded volume
  31. }
  32. },
  33. view() {
  34. const style = {
  35. 'z-index': '999',
  36. 'background-color': 'rgba(65, 105, 225, 0.8)',
  37. 'font-family': 'monospace',
  38. 'position': 'fixed',
  39. 'height': VolumeMap.size + 'px',
  40. 'width': VolumeMap.size + 'px',
  41. }
  42. return m('svg', {onclick: VolumeMap.moveNotify, style},
  43. m('style', 'text { pointer-events: none }'),
  44. State.online.map(username => {
  45. const [x, y] = VolumeMap.getDot(username)
  46. return m('text', {x, y, fill: 'white'}, `・${username}`)
  47. })
  48. )
  49. },
  50. }
  51. addEventListener('volumeMapMove', VolumeMap.moveDot)