Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Canvas whiteboard

Initialize a whiteboard with a canvas element's id.
You should define the same inner canvas width/height for connected whiteboards. Use the options or the canvas element attributes.

Usage

<canvas id="canvas-1" width="1920" height="1080"></canvas>
// Handle drawings
function bufferHandler(buffer, options) {
    console.log(buffer.length, options);
}

const whiteboard = new Whiteboard('canvas-1', bufferHandler, options);

To create a whiteboard without drawing enabled, define bufferHandler as null.

Default options

API

new Whiteboard(canvasId, bufferHandler, options)

Returns a new whiteboard object. Invokes .init() and optionally .bindMouseHandlers().

  • canvasId (string) id of canvas element in the DOM
  • bufferHandler (function) optional handler function to enable and capture drawings
  • options (object) available options for the new whiteboard instance
    {
        strokeStyle
        globalAlpha
        lineWidth
        lineCap
        lineJoin
        globalCompositeOperation
        timeout
        width
        height
        offsetX
        offsetY
    }

.bufferHandler(buffer, options)

  • buffer (array) filled with arrays of x,y coordinates relative to the inner canvas [[0,0],[20,10],[40,20]...]
  • options (object) some options of the source whiteboard
    {
        strokeStyle
        globalAlpha
        lineWidth
        lineCap
        lineJoin
        globalCompositeOperation
        timeout
        width
        height
    }

.draw(buffer, options)

Draw the buffer to the whiteboard.

  • buffer (array) arrays of x,y coordinates relative to the inner canvas [[0,0],[20,10],[40,20]...]
  • options (object) available options to override when drawing the buffer to the whiteboard
    {
        strokeStyle
        globalAlpha
        lineWidth
        lineCap
        lineJoin
        globalCompositeOperation
        timeout
        offsetX
        offsetY
    }

.clean()

Clean the whiteboard.

.bindMouseHandlers()

Bind mouse event handlers to the canvas. (onmousedown, onmousemove, onmouseup, onmouseout)

.unbindMouseHandlers()

Remove mouse event handlers from the canvas.

.bindTouchHandlers()

Bind touch event handlers to the canvas. (touchstart, touchmove, touchend, touchcancel)

.unbindTouchHandlers()

Remove touch event handlers from the canvas.

Network transport test

You need crossbar installed.

Initialize crossbar service with the default template from the root folder and start the router.

cd canvas-whiteboard
crossbar init
crossbar start

Open instances of crossbar.html in multiple browsers.

TODO

  • filter out middle points from buffer before sending it to handler
  • v2: only send starting coordinate + deltas of next positions
  • v2: buffer all drawings separately with unique timeouts
  • v2: multi touch drawing support

About

A canvas based whiteboard which can share drawings with other whiteboards.

Topics

Resources

Stars

5 stars

Watchers

3 watching

Forks

Contributors

Languages