github.com/pion/webrtc/v3@v3.2.24/examples/ice-tcp/index.html (about)

     1  <html>
     2    <!--
     3  		SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     4  		SPDX-License-Identifier: MIT
     5  	-->
     6    <head>
     7      <title>ice-tcp</title>
     8    </head>
     9  
    10    <body>
    11      <h1>ICE TCP</h1>
    12  
    13      <h3> ICE Connection States </h3>
    14      <div id="iceConnectionStates"></div> <br />
    15  
    16      <h3> Inbound DataChannel Messages </h3>
    17      <div id="inboundDataChannelMessages"></div>
    18    </body>
    19  
    20    <script>
    21      let pc = new RTCPeerConnection()
    22      let dc = pc.createDataChannel('data')
    23  
    24      dc.onmessage = event => {
    25        let el = document.createElement('p')
    26        el.appendChild(document.createTextNode(event.data))
    27  
    28        document.getElementById('inboundDataChannelMessages').appendChild(el);
    29      }
    30  
    31      pc.oniceconnectionstatechange = () => {
    32        let el = document.createElement('p')
    33        el.appendChild(document.createTextNode(pc.iceConnectionState))
    34  
    35        document.getElementById('iceConnectionStates').appendChild(el);
    36      }
    37  
    38      pc.createOffer()
    39        .then(offer => {
    40          pc.setLocalDescription(offer)
    41  
    42          return fetch(`/doSignaling`, {
    43            method: 'post',
    44            headers: {
    45              'Accept': 'application/json, text/plain, */*',
    46              'Content-Type': 'application/json'
    47            },
    48            body: JSON.stringify(offer)
    49          })
    50        })
    51        .then(res => res.json())
    52        .then(res => {
    53          pc.setRemoteDescription(res)
    54        })
    55        .catch(alert)
    56    </script>
    57  </html>