freddyaboulton HF staff commited on
Commit
9f9afa9
·
verified ·
1 Parent(s): 39a647b

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +13 -12
index.html CHANGED
@@ -357,19 +357,20 @@
357
  const offer = await peerConnection.createOffer();
358
  await peerConnection.setLocalDescription(offer);
359
 
360
- await new Promise((resolve) => {
361
- if (peerConnection.iceGatheringState === "complete") {
362
- resolve();
363
- } else {
364
- const checkState = () => {
365
- if (peerConnection.iceGatheringState === "complete") {
366
- peerConnection.removeEventListener("icegatheringstatechange", checkState);
367
- resolve();
 
 
 
 
368
  }
369
- };
370
- peerConnection.addEventListener("icegatheringstatechange", checkState);
371
- }
372
- });
373
 
374
  peerConnection.addEventListener('connectionstatechange', () => {
375
  console.log('connectionstatechange', peerConnection.connectionState);
 
357
  const offer = await peerConnection.createOffer();
358
  await peerConnection.setLocalDescription(offer);
359
 
360
+ peerConnection.onicecandidate = ({ candidate }) => {
361
+ if (candidate) {
362
+ console.debug("Sending ICE candidate", candidate);
363
+ fetch('/webrtc/offer', {
364
+ method: 'POST',
365
+ headers: { 'Content-Type': 'application/json' },
366
+ body: JSON.stringify({
367
+ candidate: candidate.toJSON(),
368
+ webrtc_id: webrtc_id,
369
+ type: "ice-candidate",
370
+ })
371
+ })
372
  }
373
+ };
 
 
 
374
 
375
  peerConnection.addEventListener('connectionstatechange', () => {
376
  console.log('connectionstatechange', peerConnection.connectionState);