Skip to content

Full Example: Shared Drawing ​

The Shared Drawing page puts two users on one canvas. Every stroke travels over a WebRTC data channel, straight from one browser to the other, and is drawn on the other side as it happens. No video is involved: a stroke is a few numbers, so it costs almost no bandwidth and both sides draw at once. It needs a logged-in user. Open it in another browser or device with a second account and invite each other.

Enter your project ID to open the demo.

You need your project ID to open the demo.

The Shared Drawing page of the template: an explanation of the data channel, a Voice checkbox, and the table of users online with an invite button per user

drawing.html before a session: the other users on the page, each with an invite button.

The page during a session: pen colors, Clear and Leave buttons, and the canvas with strokes from both users

Drawing together. Each side draws locally and sends the segment; the other side draws the same segment.

What it demonstrates ​

FeatureHow the page does it
Finding each otherEvery visitor joins the realtime group RTCDraw; getRealtimeUsers() and the USER_JOINED and USER_LEFT notices keep the table of users online.
A connection without mediaconnectRTC() with channels: [{ protocol: 'drawing', ordered: true }] and no media: an ordered, reliable data channel and nothing else. With Voice on, media: { audio: true } adds the microphone; either side may turn it on for itself.
Saying what the call ismeta: { kind: 'drawing' } travels with the invitation, and the callee's dialog says "wants to draw with you" rather than showing a video call. sources tells it whether voice is coming.
Strokes over the channelPointer events draw on the local canvas and send each segment as JSON (from, to, color, width), with positions as fractions of the canvas size. The other side draws the same segment in the message event of the drawing channel, told apart from other channels by label.
ClearA clear message empties both canvases.
Leavinghangup() on either side; the connectionstatechange event returns both pages to the user list and clears the board.

Download ​

The page is part of the full template: skapi-templates.zip. See Full Examples for how to run it.