<commit_before>/* eslint-env browser */

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

let sendChannel = pc.createDataChannel('foo')
sendChannel.onclose = () => console.log('sendChannel has closed')
sendChannel.onopen = () => console.log('sendChannel has opened')
sendChannel.onmessage = e => console.log(`sendChannel got ${e.data}`)

pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)

pc.onnegotiationneeded = e =>
  pc.createOffer({ }).then(d => {
    document.getElementById('localSessionDescription').value = btoa(d.sdp)<commit_msg>Update data-channels example to put messages in DOM instead of console<commit_after>/* eslint-env browser */

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

let sendChannel = pc.createDataChannel('foo')
sendChannel.onclose = () => console.log('sendChannel has closed')
sendChannel.onopen = () => console.log('sendChannel has opened')
sendChannel.onmessage = e => log(`sendChannel got '${e.data}'`)

pc.oniceconnectionstatechange = e => log(pc.iceConnectionState)

pc.onnegotiationneeded = e =>
  pc.createOffer({ }).then(d => {
    document.getElementById('localSessionDescription').value = btoa(d.sdp)
{'fraction_non_alphanumeric': 0.1582622187742436, 'fraction_numerical': 0.0, 'mean_word_length': 5.482412060301508, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7575043', 'n_tokens_mistral': 392, 'n_tokens_neox': 386, 'n_words': 85}