JSFiddle - React, Tailwind, and code Playground

HTML

Message: <textarea id="message">This is my DataChannel message!</textarea> <br/>
<button onclick="window.sendMessage()"> Send Message </button> <br />
Logs<br />
<div id="div"></div>

<div id="logs"></div>

JavaScript

/* eslint-env browser */

let pc = new RTCPeerConnection()
let log = msg => {
  document.getElementById('logs').innerHTML += msg + '<br>'
}
pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)

let sendChannel = pc.createDataChannel('foo')
sendChannel.onclose = () => log('sendChannel has closed')
sendChannel.onopen = () => log('sendChannel has opened')
sendChannel.onmessage = e => log(`Message from DataChannel '${sendChannel.label}' payload '${e.data}'`)

const answer = `v=0
o=- 521628857 1575883112 IN IP4 0.0.0.0
s=-
t=0 0
a=fingerprint:sha-256 4D:FB:C1:3C:65:CD:81:B3:6C:82:D3:88:49:11:B1:16:DC:65:A5:08:19:64:B5:72:1C:4A:18:40:D0:20:E3:45
a=group:BUNDLE 0
a=ice-lite
m=application 9 DTLS/SCTP 5000
c=IN IP4 0.0.0.0
a=setup:active
a=mid:0
a=sendrecv
a=sctpmap:5000 webrtc-datachannel 1024
a=ice-ufrag:fKVhbscsMWDGAnBg
a=ice-pwd:xGjQkAvKIVkBeVTGWcvCQtnVAeapczwa
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5000 typ host generation 0
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5001 typ host generation 0
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5002 typ host generation 0
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5003 typ host generation 0
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5004 typ host generation 0
a=candidate:foundation 1 udp 2130706431 offline-browser-communication.local 5005 typ host generation 0
a=end-of-candidates
`

pc.onnegotiationneeded = e =>
  pc.createOffer().then(d => {
    d.sdp = d.sdp.replace(/^a=ice-ufrag.*$/m, 'a=ice-ufrag:V6j+')
    d.sdp = d.sdp.replace(/^a=ice-pwd.*$/m, 'a=ice-pwd:OEKutPgoHVk/99FfqPOf444w')
    console.log(d.sdp)
    pc.setLocalDescription(d)
    pc.setRemoteDescription(new RTCSessionDescription({type: "answer",  sdp: answer}))
  }).catch(log)

window.sendMessage = () => {
  let message = document.getElementById('message').value
  if (message === '') {
...