- commit
- da734abd80fccc801c03244eb1486adaab4313d1
- parent
- fdb99a9db6ba6e229e8b3477bbe836c401a5ef6f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-04-01 07:09
lint
Diffstat
M | www/rtc/rtc.js | 30 | +++++++++++++++++------------- |
1 files changed, 17 insertions, 13 deletions
diff --git a/www/rtc/rtc.js b/www/rtc/rtc.js
@@ -1,3 +1,5 @@ -1 1 /* global patch */ -1 2 /* eslint no-console: "off" */ 1 3 (function() { 2 4 // https://webrtc.github.io/samples/ 3 5 // https://www.html5rocks.com/en/tutorials/webrtc/basics/ @@ -23,7 +25,7 @@ 23 25 var screenHeight = container.clientHeight; 24 26 var width = Math.sqrt(screenWidth * screenHeight / contentRatio / items); 25 27 container.style.setProperty('--video-width', width + 'px');26 -1 }-1 28 }; 27 29 28 30 var getConnection = function(sender) { 29 31 if (sender in cons) { @@ -36,7 +38,7 @@ 36 38 updateIdealColumns(); 37 39 38 40 var con = new RTCPeerConnection({39 -1 iceServers: [{urls: 'stun:stun.l.google.com:19302'}]-1 41 iceServers: [{urls: 'stun:stun.l.google.com:19302'}], 40 42 }); 41 43 con.addEventListener('icecandidate', function(event) { 42 44 patch.post(sender, {'sender': queue, 'data': event.candidate}); @@ -74,7 +76,7 @@ 74 76 if (sender !== queue) { 75 77 var con = getConnection(sender); 76 78 con.createOffer().then(offer => {77 -1 con.setLocalDescription(offer).then(_ => {-1 79 con.setLocalDescription(offer).then(() => { 78 80 patch.post(sender, {'sender': queue, 'data': offer}); 79 81 }); 80 82 }); @@ -83,9 +85,9 @@ 83 85 84 86 var handleOffer = function(sender, offer) { 85 87 var con = getConnection(sender);86 -1 con.setRemoteDescription(offer).then(_ => {-1 88 con.setRemoteDescription(offer).then(() => { 87 89 con.createAnswer().then(answer => {88 -1 con.setLocalDescription(answer).then(_ => {-1 90 con.setLocalDescription(answer).then(() => { 89 91 patch.post(sender, {'sender': queue, 'data': answer}); 90 92 }); 91 93 }); @@ -102,9 +104,9 @@ 102 104 con.addIceCandidate(candidate); 103 105 }; 104 106105 -1 patch.listen(queue, function(data) {106 -1 var sender = data.sender;107 -1 var data = data.data;-1 107 patch.listen(queue, function(event) { -1 108 var sender = event.sender; -1 109 var data = event.data; 108 110 if (sender && data) { 109 111 if (data.type === 'offer') { 110 112 return handleOffer(sender, data); @@ -120,7 +122,7 @@ 120 122 patch.post(room, {type: 'announce', key: queue}); 121 123 122 124 var updateConnections = function() {123 -1 var sender, c;-1 125 var sender; 124 126 var tracks = localVideo.srcObject.getTracks(); 125 127 126 128 for (sender in cons) { @@ -134,11 +136,12 @@ 134 136 con.addTrack(track, localVideo.srcObject); 135 137 }); 136 138 }137 -1 }-1 139 }; 138 140 139 141 var updateStreams = async function(event) { 140 142 var newStream = new MediaStream();141 -1 var kind, getStream;-1 143 var kind; -1 144 var getStream; 142 145 143 146 if (event.target.name === 'audio') { 144 147 kind = 'audio'; @@ -152,10 +155,11 @@ 152 155 } 153 156 154 157 if (event.target.checked) { -1 158 var stream; 155 159 try { 156 160 // try this first thing so it can fail without breaking anything157 -1 var stream = await getStream();158 -1 } catch {-1 161 stream = await getStream(); -1 162 } catch (err) { 159 163 event.target.checked = false; 160 164 return; 161 165 }