xxxxxxxxxx
var socket = io.connect(":30000?sketch=1373146");
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
socket.on('iamdrawing', someoneIsDrawing); //when "iamdrawing" messages is received from server, set "someoneIsDrawing" function to be called
socket.on('hello!', someoneJoined); //when "hello!" messages is received from server, set "someoneJoined" function to be called
socket.emit('hello!'); //let's send a message to anyone in the room
}
function draw() {
noStroke();
fill(30,30,30,90);
var radius = Math.abs(mouseX-pmouseX)/3+Math.abs(mouseY-pmouseY)/3;
ellipse(mouseX, mouseY, radius, radius);
socket.emit('iamdrawing',mouseX, mouseY,radius);
}
function someoneIsDrawing(x,y,r){ //this function will be called to draw a red ellipse for guest user
noStroke();
fill(255,0,0,90);
ellipse(x,y, r, r);
}
function someoneJoined(){ //this function will be called to notify users when a new user joins
print('New user joined!');
}
var socket = io.connect($OP.getEchoServerURL(1373146));
Learn more See an example