xxxxxxxxxx
49
// This is a test of the p5LiveMedia webrtc library and associated service.
// Open this sketch up 2 times to send video back and forth
let myVideo;
let otherVideos = [];
function setup() {
createCanvas(400, 400);
//this establishes our p5 library media
// and then we create the gotStream function
myVideo = createCapture(VIDEO,
function(stream) {
let p5l = new p5LiveMedia(this, "CAPTURE", stream, "myroom123");
p5l.on('stream', gotStream);
}
);
myVideo.muted = true;
myVideo.hide();
}
function draw() {
background(220);
stroke(255);
if (myVideo != null) {
image(myVideo,0,0,width/2,height);
text("My Video", 10, 10);
}
ellipse(mouseX,mouseY,10,10);
//in the beginning there may be no one else with me, so only draw when someone else is there
for (let i =0; i <otherVideos.length; i++){
push();
translate(width/2, 0);
rotate(i*2 *PI /otherVideos.lenghth);
let vid = otherVideos[i];
image(vid, i*50, 0, 50, 50);
pop();
}
}
// We got a new stream!
function gotStream(stream, id) {
// This is just like a video/stream from createCapture(VIDEO)
otherVideos.push(stream);
//otherVideo.id and id are the same and unique identifiers
otherVideos.hide();
}