| rpc.onclose = (e) => { | rpc.onclose = (e) => { | ||||
| console.log(username, e) | console.log(username, e) | ||||
| } | } | ||||
| rpc.oniceconnectionstatechange = (e) => { | |||||
| m.redraw() | |||||
| } | |||||
| State.rpcs[username] = rpc | State.rpcs[username] = rpc | ||||
| } | } | ||||
| return State.rpcs[username] | return State.rpcs[username] | ||||
| }, | }, | ||||
| } | } | ||||
| const Media = { | const Media = { | ||||
| constraints: {audio: true, video: {width: {ideal: 320}, facingMode: 'user'}}, | |||||
| turnOn: async () => { | |||||
| const media = await navigator.mediaDevices.getUserMedia(Media.constraints) | |||||
| audioVideo: {audio: true, video: {width: {ideal: 320}, facingMode: 'user'}}, | |||||
| audioOnly: {audio: true, video: false}, | |||||
| turnOn: (constraints) => async () => { | |||||
| const media = await navigator.mediaDevices.getUserMedia(constraints) | |||||
| 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() | ||||
| view() { | view() { | ||||
| if(!State.media[State.username]) { | if(!State.media[State.username]) { | ||||
| return m('.media', | return m('.media', | ||||
| m('button', {onclick: Media.turnOn}, 'turn media on'), | |||||
| m('button', {onclick: Media.turnOn(Media.audioVideo)}, 'turn media on'), | |||||
| m('button', {onclick: Media.turnOn(Media.audioOnly)}, 'turn audio on'), | |||||
| ) | ) | ||||
| } | } | ||||
| else { | else { | ||||
| } | } | ||||
| State.websocket.onclose = (e) => { | State.websocket.onclose = (e) => { | ||||
| State.online.forEach(signalPeerStop) | |||||
| if(!e.wasClean) { | if(!e.wasClean) { | ||||
| setTimeout(connect, 1000, username) | setTimeout(connect, 1000, username) | ||||
| } | } |