No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

streams.js 3.2KB

hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 4 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
hace 5 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const Toggle = {
  2. view({attrs: {label, value}}) {
  3. const onclick = () => {
  4. StreamContainer[value] = !StreamContainer[value]
  5. requestStream()
  6. }
  7. const checked = StreamContainer[value]
  8. return m('label.styled',
  9. m('input[type=checkbox]', {checked, onclick}),
  10. label,
  11. )
  12. }
  13. }
  14. const VideoConfig = {
  15. get video() {
  16. return StreamContainer.videoOn
  17. && State.online.length < 10
  18. && params.get('v') !== '0'
  19. && {width: {ideal: 320}, facingMode: 'user', frameRate: 26}
  20. },
  21. get audio() {
  22. return StreamContainer.audioOn
  23. && params.get('a') !== '0'
  24. },
  25. view() {
  26. return [
  27. m(Toggle, {label: 'video', value: 'videoOn'}),
  28. m(Toggle, {label: 'audio', value: 'audioOn'}),
  29. ]
  30. }
  31. }
  32. const requestStream = async () => {
  33. if(StreamContainer.videoOn || StreamContainer.audioOn) {
  34. await navigator.mediaDevices
  35. .getUserMedia(VideoConfig)
  36. .then(stream =>
  37. signal({kind: 'stream', value: {source: State.username, stream}})
  38. )
  39. .catch(e => console.log(e))
  40. }
  41. }
  42. const Video = {
  43. setUp: (username) => ({dom}) => {
  44. if(username === State.username) {
  45. dom.muted = true
  46. requestStream()
  47. }
  48. },
  49. view({attrs: {username}}) {
  50. const styleOuter = {
  51. position: 'relative',
  52. display: 'block',
  53. color: 'white',
  54. overflow: 'hidden',
  55. }
  56. const styleMeta = {
  57. position: 'absolute',
  58. display: 'flex',
  59. alignItems: 'center',
  60. justifyContent: 'center',
  61. height: '100%',
  62. width: '100%',
  63. fontFamily: 'monospace',
  64. fontSize: 'xxx-large',
  65. }
  66. const styleVideo = {
  67. objectFit: Settings.get('blackBars') ? 'contain' : 'cover',
  68. width: '100%',
  69. height: '100%',
  70. transform: username === State.username ? 'scaleX(-1)' : 'scaleX(1)',
  71. }
  72. return m('.video-container', {style: styleOuter},
  73. m('.video-info', {style: styleMeta},
  74. m('.username', username),
  75. ),
  76. m('video[playsinline][autoplay]', {
  77. style: styleVideo,
  78. srcObject: streams[username],
  79. oncreate: this.setUp(username),
  80. }),
  81. )
  82. },
  83. }
  84. const StreamContainer = {
  85. videoOn: true,
  86. audioOn: true,
  87. view() {
  88. const dims = [
  89. Math.floor((1 + Math.sqrt(4 * State.online.length - 3)) / 2),
  90. Math.ceil(Math.sqrt(State.online.length)),
  91. ].map(n => Array(n || 1).fill('1fr').join(' '))
  92. if(innerHeight > innerWidth) dims.reverse()
  93. const style = {
  94. backgroundColor: 'black',
  95. overflow: 'hidden',
  96. display: 'grid',
  97. gridTemplateRows: dims[0],
  98. gridTemplateColumns: dims[1],
  99. }
  100. return m('.videos', {style},
  101. State.online.map(username => m(Video, {key: username, username}))
  102. )
  103. },
  104. }
  105. addEventListener('load', () => {
  106. Headers.push([VideoConfig])
  107. Apps.push([StreamContainer, {key: 'stream-container'}])
  108. })