Browse Source

Place media selector in correct place

master
Roderic Day 5 years ago
parent
commit
257fcbbce1
1 changed files with 28 additions and 28 deletions
  1. +28
    -28
      pico.js

+ 28
- 28
pico.js View File

} }
return State.rpcs[username] return State.rpcs[username]
} }
const getSelectedMedia = async () => {
const stream = new MediaStream()
const addTrack = stream.addTrack.bind(stream)

const muted = document.querySelector('#mute-check').checked
if(!muted) {
const audio = Media.audioDefaults
await navigator.mediaDevices.getUserMedia({audio})
.then(s => s.getAudioTracks().forEach(addTrack))
.catch(e => console.error(e))
}

const source = document.querySelector('#media-source').value
if(source === 'camera') {
const video = {width: {ideal: 320}, facingMode: 'user', frameRate: 26}
await navigator.mediaDevices.getUserMedia({video})
.then(s => s.getVideoTracks().forEach(addTrack))
.catch(e => console.error(e))
}
if(source === 'screen' && navigator.mediaDevices.getDisplayMedia) {
await navigator.mediaDevices.getDisplayMedia()
.then(s => s.getVideoTracks().forEach(addTrack))
.catch(e => console.error(e))
}

return stream
}
const onPeerInfo = async ({detail: message}) => { const onPeerInfo = async ({detail: message}) => {
const rpc = getOrCreateRpc(message.source) const rpc = getOrCreateRpc(message.source)
if(rpc && message.value.type === 'request') { if(rpc && message.value.type === 'request') {
noiseSuppresion: true, noiseSuppresion: true,
echoCancellation: true, echoCancellation: true,
}, },
getSelectedMedia: async () => {
const stream = new MediaStream()
const addTrack = stream.addTrack.bind(stream)

const muted = document.querySelector('#mute-check').checked
if(!muted) {
const audio = Media.audioDefaults
await navigator.mediaDevices.getUserMedia({audio})
.then(s => s.getAudioTracks().forEach(addTrack))
.catch(e => console.error(e))
}

const source = document.querySelector('#media-source').value
if(source === 'camera') {
const video = {width: {ideal: 320}, facingMode: 'user', frameRate: 26}
await navigator.mediaDevices.getUserMedia({video})
.then(s => s.getVideoTracks().forEach(addTrack))
.catch(e => console.error(e))
}
if(source === 'screen' && navigator.mediaDevices.getDisplayMedia) {
await navigator.mediaDevices.getDisplayMedia()
.then(s => s.getVideoTracks().forEach(addTrack))
.catch(e => console.error(e))
}

return stream
},
turnOn: async () => { turnOn: async () => {
const media = await Media.getSelectedMedia()
const media = await getSelectedMedia()
State.media[State.username] = media State.media[State.username] = media
wire({kind: 'peerInfo', value: {type: 'request'}}) wire({kind: 'peerInfo', value: {type: 'request'}})
m.redraw() m.redraw()

Loading…
Cancel
Save