Docs
Getting started with Trystero
Install the library, join a room, and send a message.
Install
npm i trysteroJoin a room
Use a stable, unique appId for your app and any room ID that
makes sense for your product, such as a document ID, game lobby, or call ID.
import {joinRoom, selfId} from 'trystero'
const room = joinRoom(
{appId: 'com.example.notes'},
'project-42'
)
console.log('my peer id is', selfId)
room.onPeerJoin = peerId => {
console.log(peerId, 'joined')
}
room.onPeerLeave = peerId => {
console.log(peerId, 'left')
}Send your first action
Actions are named peer-to-peer channels. They serialize JSON-like data for you, and can also send binary payloads.
const note = room.makeAction('note')
note.onMessage = ({id, text}, {peerId}) => {
updateNote(id, text, peerId)
}
editor.oninput = () => {
note.send({
id: currentNoteId,
text: editor.value
})
}