freddyaboulton HF Staff commited on
Commit
c270f15
·
verified ·
1 Parent(s): b2bb254

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +15 -14
index.html CHANGED
@@ -372,6 +372,21 @@
372
  }
373
  });
374
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
375
  const dataChannel = peerConnection.createDataChannel('text');
376
  dataChannel.onmessage = (event) => {
377
  const eventJson = JSON.parse(event.data);
@@ -383,20 +398,6 @@
383
  const offer = await peerConnection.createOffer();
384
  await peerConnection.setLocalDescription(offer);
385
 
386
- await new Promise((resolve) => {
387
- if (peerConnection.iceGatheringState === "complete") {
388
- resolve();
389
- } else {
390
- const checkState = () => {
391
- if (peerConnection.iceGatheringState === "complete") {
392
- peerConnection.removeEventListener("icegatheringstatechange", checkState);
393
- resolve();
394
- }
395
- };
396
- peerConnection.addEventListener("icegatheringstatechange", checkState);
397
- }
398
- });
399
-
400
  peerConnection.addEventListener('connectionstatechange', () => {
401
  console.log('connectionstatechange', peerConnection.connectionState);
402
  if (peerConnection.connectionState === 'connected') {
 
372
  }
373
  });
374
 
375
+ peerConnection.onicecandidate = ({ candidate }) => {
376
+ if (candidate) {
377
+ console.debug("Sending ICE candidate", candidate);
378
+ fetch('/webrtc/offer', {
379
+ method: 'POST',
380
+ headers: { 'Content-Type': 'application/json' },
381
+ body: JSON.stringify({
382
+ candidate: candidate.toJSON(),
383
+ webrtc_id: webrtc_id,
384
+ type: "ice-candidate",
385
+ })
386
+ })
387
+ }
388
+ };
389
+
390
  const dataChannel = peerConnection.createDataChannel('text');
391
  dataChannel.onmessage = (event) => {
392
  const eventJson = JSON.parse(event.data);
 
398
  const offer = await peerConnection.createOffer();
399
  await peerConnection.setLocalDescription(offer);
400
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
401
  peerConnection.addEventListener('connectionstatechange', () => {
402
  console.log('connectionstatechange', peerConnection.connectionState);
403
  if (peerConnection.connectionState === 'connected') {