The web is the network

Trystero makes browsers discover each other and communicate directly. No accounts. No deploying infrastructure. Just import and connect.

Get the code
npm i trystero

Connect in a few lines

Import, join a room, and start communicating. Peers find each other automatically.

// Import Trystero
import {joinRoom} from 'trystero'

// Join a room with your app ID and a room ID
const room = joinRoom(
  {appId: 'my-app'},
  'room-id'
)

let peerCount = 0

// Handle when a peer joins
room.onPeerJoin(peerId => {
  console.log(`${peerId} joined!`)
  peerCount++
})

Easy

Trystero abstracts away all the complexity of WebRTC and peer discovery. Send files, video streams, and any other data with a clean and easy API.

Encrypted

All data sent between peers is end-to-end encrypted. No intermediary can read your users’ messages. You can opt into more advanced identity verification features too.

Super flexible

Peers discover each other through decentralized infrastructure like Nostr, MQTT, BitTorrent, and more. You can also run your own relay if you’re into that kind of thing.

Send anything, to anyone

Actions are typed channels. Create as many as you need. Send strings, objects, binary data like files, or audio/video streams.

// Create an action to send and receive cursor positions
const [sendCursor, getCursor] = room.makeAction('cursor')

// Send the cursor position to peers when the mouse moves
document.onmousemove = e =>
  sendCursor({x: e.clientX, y: e.clientY})

// Receive the cursor position from other peers
getCursor((pos, peerId) => movePeerCursor(peerId, pos))

Build apps with audio and video

Stream audio and video directly between browsers. Build presence indicators, voice chat, or collaborative editing.

// Grab the user's camera stream
const stream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true
})

// Send the stream to peers in the room
room.addStream(stream)

// Send the stream to peers who join later
room.onPeerJoin(peerId =>
  room.addStream(selfStream, peerId)
)

// Handle streams from other peers
room.onPeerStream((stream, peerId) =>
  // Connect the stream to a video element
  videoElements[peerId].srcObject = stream
)

Start building

Trystero is open source, works on every browser and device, and is ready to use in any JavaScript project.