| @@ -63,6 +63,9 @@ const getOrCreateRpc = (username) => { | |||
| rpc.onclose = (e) => { | |||
| console.log(username, e) | |||
| } | |||
| rpc.oniceconnectionstatechange = (e) => { | |||
| m.redraw() | |||
| } | |||
| State.rpcs[username] = rpc | |||
| } | |||
| return State.rpcs[username] | |||
| @@ -146,9 +149,10 @@ const Video = { | |||
| }, | |||
| } | |||
| 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 | |||
| wire({kind: 'peerInfo', value: {type: 'request'}}) | |||
| m.redraw() | |||
| @@ -160,7 +164,8 @@ const Media = { | |||
| view() { | |||
| if(!State.media[State.username]) { | |||
| 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 { | |||
| @@ -269,6 +274,7 @@ const connect = (username) => { | |||
| } | |||
| State.websocket.onclose = (e) => { | |||
| State.online.forEach(signalPeerStop) | |||
| if(!e.wasClean) { | |||
| setTimeout(connect, 1000, username) | |||
| } | |||