index.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <html>
  2. <!--
  3. SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  4. SPDX-License-Identifier: MIT
  5. -->
  6. <head>
  7. <title>ice-single-port</title>
  8. </head>
  9. <body>
  10. <h3> ICE Selected Pairs </h3>
  11. <div id="iceSelectedPairs"></div> <br />
  12. </body>
  13. <script>
  14. let createPeerConnection = () => {
  15. let pc = new RTCPeerConnection()
  16. let dc = pc.createDataChannel('data')
  17. dc.onopen = () => {
  18. let el = document.createElement('template')
  19. let selectedPair = pc.sctp.transport.iceTransport.getSelectedCandidatePair()
  20. el.innerHTML = `<div>
  21. <ul>
  22. <li> <i> Local</i> - ${selectedPair.local.candidate}</li>
  23. <li> <i> Remote</i> - ${selectedPair.remote.candidate} </li>
  24. </ul>
  25. </div>`
  26. document.getElementById('iceSelectedPairs').appendChild(el.content.firstChild);
  27. }
  28. pc.createOffer()
  29. .then(offer => {
  30. pc.setLocalDescription(offer)
  31. return fetch(`/doSignaling`, {
  32. method: 'post',
  33. headers: {
  34. 'Accept': 'application/json, text/plain, */*',
  35. 'Content-Type': 'application/json'
  36. },
  37. body: JSON.stringify(offer)
  38. })
  39. })
  40. .then(res => res.json())
  41. .then(res => pc.setRemoteDescription(res))
  42. .catch(alert)
  43. }
  44. for (i = 0; i < 10; i++) {
  45. createPeerConnection()
  46. }
  47. </script>
  48. </html>