Browse Source

Place video options elsewhere

master
Roderic Day 5 years ago
parent
commit
7ed1a8d9e5
2 changed files with 33 additions and 23 deletions
  1. +1
    -1
      pico.css
  2. +32
    -22
      pico.js

+ 1
- 1
pico.css View File

position: absolute; position: absolute;
z-index: 999; z-index: 999;
} }
.video-meta label {
.video-option {
display: block; display: block;
} }
.video-container video { .video-container video {

+ 32
- 22
pico.js View File

} }
const VideoOptions = { const VideoOptions = {
available: ['mirror', 'square'], available: ['mirror', 'square'],
getFor: (username) => {
if(!State.options[username]) {
State.options[username] = new Set(VideoOptions.available)
}
return State.options[username]
},
getClassListFor: (username) => {
return [...VideoOptions.getFor(username)].join(' ')
},
toggle: (options, string) => () => options.has(string) toggle: (options, string) => () => options.has(string)
? options.delete(string) ? options.delete(string)
: options.add(string), : options.add(string),
view: ({attrs}) => VideoOptions.available.map((string) =>
m('label',
m('input', {
type: 'checkbox',
checked: attrs.options.has(string),
onchange: VideoOptions.toggle(attrs.options, string),
}),
string,
)),
view({attrs: {username}}) {
const options = VideoOptions.getFor(username)
return VideoOptions.available.map((string) =>
m('label.video-option',
m('input', {
type: 'checkbox',
checked: options.has(string),
onchange: VideoOptions.toggle(options, string),
}),
string,
)
)
}
} }
const Video = { const Video = {
keepRatio: {observe: () => {}}, keepRatio: {observe: () => {}},
dom.ondblclick = toggleFullscreen(dom) dom.ondblclick = toggleFullscreen(dom)
}, },
view({attrs}) { view({attrs}) {
if(!State.options[attrs.username]) {
State.options[attrs.username] = new Set(VideoOptions.available)
}
const options = State.options[attrs.username]
const classList = [...options].join(' ')

const classList = VideoOptions.getClassListFor(attrs.username)
const rpc = State.rpcs[attrs.username] || {iceConnectionState: null} const rpc = State.rpcs[attrs.username] || {iceConnectionState: null}
return m('.video-container', {class: classList, oncreate: ({dom}) => Video.keepRatio.observe(dom)}, return m('.video-container', {class: classList, oncreate: ({dom}) => Video.keepRatio.observe(dom)},
m('details.video-meta',
m('summary',
m('span.video-source', attrs.username),
m('.video-state', rpc.iceConnectionState),
),
m(VideoOptions, {options}),
m('.video-meta',
m('span.video-source', attrs.username),
m('.video-state', rpc.iceConnectionState),
), ),
m('video', {playsinline: true, oncreate: Video.appendStream(attrs)}), m('video', {playsinline: true, oncreate: Video.appendStream(attrs)}),
) )
), ),
m('.online', m('.online',
m('button', {onclick: Login.sendLogout}, 'Logout'), m('button', {onclick: Login.sendLogout}, 'Logout'),
m('ul.user-list', State.online.map(username => m('li', username))),
m('.user-list', State.online.map(username =>
m('details',
m('summary', username),
m(VideoOptions, {username}),
),
)),
), ),
m(Media), m(Media),
) )

Loading…
Cancel
Save