aboutsummaryrefslogtreecommitdiff
path: root/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'index.html')
-rw-r--r--index.html45
1 files changed, 23 insertions, 22 deletions
diff --git a/index.html b/index.html
index fc641bf..9f88bb2 100644
--- a/index.html
+++ b/index.html
@@ -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>