function broadcastEvents(evt, args) { // convert args to array args = args ? Array.prototype.slice.call(args) : []; console.log(evt, args); args.unshift(evt); console.log(args); var audience = broadcast.audience; for (var audId in audience) audience[audId].emit.apply(audience[audId], args); } socket.onEvent = function (evt, func) { socket.on(evt, function () { // If func return true, broadcast it if (func.apply(this, arguments)) broadcastEvents(evt, arguments); }); }; socket.onEvent('draw circle’, function (x, y, color, width) { canvas.drawing = { type: 'circle’, color: color, width: width, points: [{x: x, y: y}] }; return true; });
作者
作者其它话题