Published unlisted
Edited
Jan 10, 2021
Insert cell
md`# Peer js`
Insert cell
//SimplePeer = require("https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js")
Insert cell
peerjs = require("https://cdnjs.cloudflare.com/ajax/libs/peerjs/1.3.1/peerjs.min.js")
Insert cell
{
let p3 = new Peer({ initiator: true });
}
Insert cell
new Peer()
Insert cell
p1 = new Peer({ initiator: false })
Insert cell
p2 = new Peer()
Insert cell
{
p2.on('connection', function(conn) {
conn.on('data', function(data) {
console.log('peer2 got ', data);
});
});
}
Insert cell
{
var conn = p1.connect(p2.id);
conn.on('open', function() {
conn.send('hi heres some data');
});
}
Insert cell
video = {
let v = DOM.element("video");
v.setAttribute("playsinline", "");
v.setAttribute("autoplay", "");
return v;
}
Insert cell
{
// peer2 answer for call
p2.on("call", function(call) {
call.on("stream", function(remotestream) {
video.srcObject = remotestream;
});
});
}
Insert cell
{
let getUserMedia = navigator.mediaDevices.getUserMedia;
(async () => {
let stream = await getUserMedia({ video: true, audio: true });
console.log("got permisssion for stream", stream);
//p1.call(p2.id, stream);
})();
}
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