Public
Edited
May 26, 2024
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
my_id = await (new Promise(resolve => peer.on('open', id => resolve(id)))) // gets this instance's id
Insert cell
mutable partner_id = ""
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Peer = (await import("https://esm.sh/peerjs")).Peer
Insert cell
peer = new Peer(({
config: {'iceServers': [
{ url: 'stun:stun.l.google.com:19302' },
//{ url: 'turn:homeo@turn.bistri.com:80', credential: 'homeo' }
]} /* Sample servers, please use appropriate ones */
}))
Insert cell
conn = peer.connect(their_id || partner_id)
Insert cell
// Send the data.
internal_1 = conn.send({data: send_data, from: my_id})
Insert cell
internal_2 = {
// Receive the data.
return peer.on('connection', function(conn) {
conn.on('data', function({data, from}){
mutable received_data = data
mutable partner_id = from
});
});
}
Insert cell
internals = {
return {
conn,
internal_1,
internal_2}
}
Insert cell
import {text} from "@jashkenas/inputs"
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