|
|
|
|
|
|
|
|
|
|
|
const isLandscape = screen.width > screen.height |
|
|
const State = { |
|
|
const State = { |
|
|
username: null, |
|
|
username: null, |
|
|
websocket: null, |
|
|
websocket: null, |
|
|
|
|
|
|
|
|
const S = `0${dt.getSeconds()}`.slice(-2) |
|
|
const S = `0${dt.getSeconds()}`.slice(-2) |
|
|
return `${H}:${M}:${S}` |
|
|
return `${H}:${M}:${S}` |
|
|
} |
|
|
} |
|
|
|
|
|
const hotKey = (e) => { |
|
|
|
|
|
// if isDesktop, Enter posts, unless Shift+Enter |
|
|
|
|
|
// use isLandscape as proxy for isDesktop |
|
|
|
|
|
if(e.key === 'Enter' && isLandscape && !e.shiftKey) { |
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
Chat.sendPost() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
const Video = { |
|
|
const Video = { |
|
|
appendStream: ({username, stream}) => ({dom}) => { |
|
|
appendStream: ({username, stream}) => ({dom}) => { |
|
|
dom.autoplay = true |
|
|
dom.autoplay = true |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
} |
|
|
} |
|
|
const Chat = { |
|
|
const Chat = { |
|
|
sendPost: (e) => { |
|
|
|
|
|
e.preventDefault() |
|
|
|
|
|
const field = e.target.text |
|
|
|
|
|
if(field.value) { |
|
|
|
|
|
wire({kind: 'post', value: field.value}) |
|
|
|
|
|
field.value = '' |
|
|
|
|
|
|
|
|
sendPost: () => { |
|
|
|
|
|
if(textbox.value) { |
|
|
|
|
|
wire({kind: 'post', value: textbox.value}) |
|
|
|
|
|
textbox.value = '' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
view() { |
|
|
view() { |
|
|
|
|
|
|
|
|
m('.text', post.value), |
|
|
m('.text', post.value), |
|
|
)), |
|
|
)), |
|
|
), |
|
|
), |
|
|
m('form.actions', {onsubmit: Chat.sendPost}, |
|
|
|
|
|
m('input', {oncreate: autoFocus, name: 'text', autocomplete: 'off'}), |
|
|
|
|
|
m('button', 'Send'), |
|
|
|
|
|
|
|
|
m('.actions', |
|
|
|
|
|
m('textarea#textbox', {oncreate: autoFocus, onkeydown: hotKey}), |
|
|
|
|
|
m('button', {onclick: Chat.sendPost}, 'Send'), |
|
|
), |
|
|
), |
|
|
m('.online', |
|
|
m('.online', |
|
|
m('button', {onclick: Login.sendLogout}, 'Logout'), |
|
|
m('button', {onclick: Login.sendLogout}, 'Logout'), |