Public
Edited
Apr 8
1 star
Insert cell
# WebRTC Demo for FAIR (Remote)
Insert cell
chatLog
Insert cell
viewof chatBox = Inputs.text({ label: "Enter message:", submit: true })
Insert cell
{
if (chatBox) {
remoteConnection.dataChannel.send(chatBox);
mutable chatLog += `${chatBox}\n`;
}
}
Insert cell
viewof offer = Inputs.textarea({label: "Offer SDP Object:"})
Insert cell
configuration = {
return {
iceServers: [
// { urls: "turn:freestun.net:3478", username: "free", credential: "free" },
{ urls: "stun:stun.l.google.com:19302" },
{
urls: "turn:turn.speed.cloudflare.com:50000",
username:
"73a69c5847f725b6f7f76802a817f16c47e1da1080c3957d1f4781ee54997021404551406a0ad0509ad3b481492f57063adb364fcb8d8d81bba95d05ec966ebf",
credential:
"aba9b169546eb6dcc7bfb1cdf34544cf95b5161d602e3b5fa7c8342b2e9802fb"
}
]
};
}
Insert cell
remoteConnection = new RTCPeerConnection(configuration)
Insert cell
{
remoteConnection.addEventListener("iceconnectionstatechange", () => {
console.log("ICE connection state:", remoteConnection.iceConnectionState);
});

remoteConnection.addEventListener("icegatheringstatechange", () => {
console.log("ICE gathering state:", remoteConnection.iceGatheringState);
});

remoteConnection.addEventListener("icecandidateerror", (event) => {
console.error("ICE candidate error:", event);
});
}
Insert cell
JSON.parse(JSON.stringify(remoteConnection.localDescription))
Insert cell
remoteConnection.onicecandidate = (e) => console.log("New ICE Candidate found. Current SDP:\n", remoteConnection.localDescription)
Insert cell
remoteConnection.ondatachannel = (e) => {
remoteConnection.dataChannel = e.channel
remoteConnection.dataChannel.onopen = (e) => {
console.log("Connection Open")
}
remoteConnection.dataChannel.onmessage = (msg) => {
mutable chatLog += `${msg.data}\n`
}
}
Insert cell
{
if (offer && !remoteConnection.remoteDescription) {
await remoteConnection.setRemoteDescription(JSON.parse(offer));
console.log("Offer set");
const answer = await remoteConnection.createAnswer();
remoteConnection.setLocalDescription(answer);
console.log("Answer set");
}
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more