← 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.
- Start in this tab.
- Open a second tab with the share link and press Start there too.
- Messages appear in both logs. Type your own below.
This tab
Not connectedKey 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();