| @@ -4,6 +4,10 @@ const streams = {} | |||
| const screen = {} | |||
| function setStream({source, stream}) { | |||
| if(streams[source] && streams[source].id !== stream.id) { | |||
| streams[source].getTracks().forEach(track => track.stop()) | |||
| } | |||
| streams[source] = stream | |||
| m.redraw() | |||
| @@ -68,7 +72,7 @@ async function handlePeerInfo({source: target, value}) { | |||
| const stream = streams[State.username] | |||
| if(stream) { | |||
| stream.getTracks().forEach(track => { | |||
| try {rpc.addTrack(track, stream) } | |||
| try { rpc.addTrack(track, stream) } | |||
| catch { } | |||
| }) | |||
| } | |||
| @@ -38,6 +38,10 @@ const requestStream = async () => { | |||
| ) | |||
| .catch(e => console.log(e)) | |||
| } | |||
| else { | |||
| const stream = new MediaStream() | |||
| signal({kind: 'stream', value: {source: State.username, stream}}) | |||
| } | |||
| } | |||
| const Video = { | |||
| setUp: (username) => ({dom}) => { | |||