github.com/pion/webrtc/v4@v4.0.1/examples/data-channels/README.md (about)

     1  # data-channels
     2  data-channels is a Pion WebRTC application that shows how you can send/recv DataChannel messages from a web browser
     3  
     4  ## Instructions
     5  ### Download data-channels
     6  ```
     7  go install github.com/pion/webrtc/v4/examples/data-channels@latest
     8  ```
     9  
    10  ### Open data-channels example page
    11  [jsfiddle.net](https://jsfiddle.net/e41tgovp/)
    12  
    13  ### Run data-channels, with your browsers SessionDescription as stdin
    14  In the jsfiddle the top textarea is your browser's session description, press `Copy browser SDP to clipboard` or copy the base64 string manually and:
    15  #### Linux/macOS
    16  Run `echo $BROWSER_SDP | data-channels`
    17  #### Windows
    18  1. Paste the SessionDescription into a file.
    19  1. Run `data-channels < my_file`
    20  
    21  ### Input data-channels's SessionDescription into your browser
    22  Copy the text that `data-channels` just emitted and copy into second text area
    23  
    24  ### Hit 'Start Session' in jsfiddle
    25  Under Start Session you should see 'Checking' as it starts connecting. If everything worked you should see `New DataChannel foo 1`
    26  
    27  Now you can put whatever you want in the `Message` textarea, and when you hit `Send Message` it should appear in your terminal!
    28  
    29  Pion WebRTC will send random messages every 5 seconds that will appear in your browser.
    30  
    31  Congrats, you have used Pion WebRTC! Now start building something cool
    32  
    33  ## Architecture
    34  
    35  ```mermaid
    36  flowchart TB
    37      Browser--Copy Offer from TextArea-->Pion
    38      Pion--Copy Text Print to Console-->Browser
    39      subgraph Pion[Go Peer]
    40          p1[Create PeerConnection]
    41          p2[OnConnectionState Handler]
    42          p3[Print Connection State]
    43          p2-->p3
    44          p4[OnDataChannel Handler]
    45          p5[OnDataChannel Open]
    46          p6[Send Random Message every 5 seconds to DataChannel]
    47          p4-->p5-->p6
    48          p7[OnDataChannel Message]
    49          p8[Log Incoming Message to Console]
    50          p4-->p7-->p8
    51          p9[Read Session Description from Standard Input]
    52          p10[SetRemoteDescription with Session Description from Standard Input]
    53          p11[Create Answer]
    54          p12[Block until ICE Gathering is Complete]
    55          p13[Print Answer with ICE Candidatens included to Standard Output]
    56      end
    57      subgraph Browser[Browser Peer]
    58          b1[Create PeerConnection]
    59          b2[Create DataChannel 'foo']
    60          b3[OnDataChannel Message]
    61          b4[Log Incoming Message to Console]
    62          b3-->b4
    63          b5[Create Offer]
    64          b6[SetLocalDescription with Offer]
    65          b7[Print Offer with ICE Candidates included]
    66  
    67      end
    68  ```