diff options
author | dakkar <dakkar@thenautilus.net> | 2020-07-25 11:31:23 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2020-07-25 11:56:19 +0000 |
commit | c6ab41dc8c9816a2a457f61b5d90d2436dfbb471 (patch) | |
tree | c34b53e7d2dd8f151ad2b638b194a816b427c24d /index.html | |
parent | maybe new deps? mah (diff) | |
download | rtwatch-c6ab41dc8c9816a2a457f61b5d90d2436dfbb471.tar.gz rtwatch-c6ab41dc8c9816a2a457f61b5d90d2436dfbb471.tar.bz2 rtwatch-c6ab41dc8c9816a2a457f61b5d90d2436dfbb471.zip |
changes from another guy
https://github.com/ahamlinman/rtwatch/commit/eb91a43eeccc5959ea981dbc6eef10978d5179fb
Diffstat (limited to 'index.html')
-rw-r--r-- | index.html | 45 |
1 files changed, 23 insertions, 22 deletions
@@ -15,8 +15,10 @@ </div> <script> - let conn = new WebSocket('wss://' + window.location.host + window.location.pathname + '/ws/') + let pc = new RTCPeerConnection() + pc.addTransceiver('video', {direction: 'recvonly'}); + pc.addTransceiver('audio', {direction: 'recvonly'}); window.seekClick = () => { conn.send(JSON.stringify({event: 'seek', data: document.getElementById('seekTime').value})) @@ -30,26 +32,19 @@ pc.ontrack = function (event) { if (event.track.kind === 'audio') { - //return + return } var el = document.getElementById('video1') - el.srcObject = event.streams[0] - el.autoplay = true - el.controls = true + el.srcObject = event.streams[0]; + el.autoplay = true; + el.controls = true; } - conn.onopen = () => { - navigator.mediaDevices.getUserMedia({video: true, audio: true}).then(g => { - for (const track of g.getTracks()) { - pc.addTrack(track,g); - } + let conn = new WebSocket('wss://' + window.location.host + window.location.pathname + '/ws/') + window.conn = conn - pc.createOffer({offerToReceiveVideo: true, offerToReceiveAudio: true}).then(offer => { - return pc.setLocalDescription(offer); - }).then(() => { - conn.send(JSON.stringify({event: 'offer', data: JSON.stringify(pc.localDescription)})) - }) - }).catch(e => { console.log(`failed getUserMedia: ${e}`) }); + conn.onopen = () => { + console.log('Connection opened') } conn.onclose = evt => { @@ -63,15 +58,21 @@ } switch (msg.event) { - case 'answer': - answer = JSON.parse(msg.data) - if (!answer) { - return console.log('failed to parse answer') + case 'offer': + offer = JSON.parse(msg.data) + if (!offer) { + return console.log('failed to parse offer') } - pc.setRemoteDescription(answer) + console.log('Received offer', offer); + (async () => { + pc.setRemoteDescription(offer); + const answer = await pc.createAnswer(); + await pc.setLocalDescription(answer); + console.log('Sending answer', answer); + conn.send(JSON.stringify({event: 'answer', data: JSON.stringify(answer)})); + })(); } } - window.conn = conn </script> </body> </html> |