Open 1 browser tab and paste the following into console
const localConnection = new RTCPeerConnection();
var remoteConnection = new RTCPeerConnection();
localConnection.onicecandidate = (e) => {
console.log(e.candidate);
remoteConnection.addIceCandidate(e.candidate);
};
remoteConnection.onicecandidate = (e) => {
console.log(e.candidate);
localConnection.addIceCandidate(e.candidate);
}
var localChannel = localConnection.createDataChannel('cfChannel', null);
localChannel.onmessage = (e) => {
console.log('++ ' + e.data);
};
remoteConnection.ondatachannel = (e) => {
console.log(e);
e.channel.onmessage = ev => {
console.log('>> ' + ev.data);
e.channel.send(ev.data.toLowerCase());
}
};
localConnection.createOffer().then((desc) => {
console.log(desc);
localConnection.setLocalDescription(desc);
remoteConnection.setRemoteDescription(desc);
remoteConnection.createAnswer().then(remoteDesc => {
console.log(remoteDesc);
remoteConnection.setLocalDescription(remoteDesc);
localConnection.setRemoteDescription(remoteDesc);
});
});
console.log('---');
setTimeout(() => localChannel.send("BLAH BLEEP BLOOP"), 1000);
setTimeout(() => localChannel.send("look at this message sent"), 2000);