window.onload = function() {
'use strict'
var painting;
var context;
var x, i, j;
var y;
var canvas = document.getElementById("canvas");
context = canvas.getContext("2d");
var socket = io.connect("http://localhost:3000");
context.strokeStyle = 'red';
context.lineWidth = 9;
context.strokeRect(420, 200, 400, 200);
canvas.onmousedown = startDraw;
canvas.onmouseup = draw;
socket.on( 'startDraw', function( data ) {
startDraw( data.x, data.y );
});
function startDraw(e) {
'use strict'
painting = true;
x = e.pageX;
y = e.pageY;
}
socket.emit( 'startDraw', { x: x, y: y } );
function draw(r) {
'use strict'
i = r.pageX;
j = r.pageY;
if ( painting == true ) {
context.strokeStyle = 'red';
context.beginPath();
context.moveTo( x, y );
context.lineTo( i, j );
context.stroke();
}
}
function stopDraw() {
'use strict'
painting = false;
}
}
Ошибка
Cannot read property 'pageX' of undefined