← All demos

Auto connect

The smallest useful SDK example: one autoConnect() call joins a room, announces this tab, and opens a peer-to-peer data channel with every other tab in the same room.

  1. Start in this tab.
  2. Open a second tab with the share link and press Start there too.
  3. Messages appear in both logs. Type your own below.

This tab

Not connected
Key SDK calls in this demo
const sdk = new VDONinjaSDK();
sdk.addEventListener('dataChannelOpen', () => sdk.sendData({ hello: 'world' }));
sdk.addEventListener('dataReceived', (e) => console.log(e.detail.data, e.detail.uuid));

// Connect, join the room, announce, and view every other peer in it
const ctl = await sdk.autoConnect({ room });

sdk.sendData({ text: 'hi' });   // to every connected peer

ctl.stop();                     // stop auto-viewing new peers
sdk.disconnect();