Upgrading to 0.27
Version 0.27 introduces self-certifying user identities, multi-tab
presence, signed per-user and shared state, the roles() and
scale() plugins, and a unified subscription API across all
signaling strategies.
Wire compatibility
0.27 uses a new authenticated wire protocol (DTLS-bound ECDSA P-256 handshakes, signed state records, and v3 action frames) and is not wire-compatible with 0.26.x or earlier peers. Upgrade all browser and server peers sharing a room together.
Summary of breaking changes
- Property assignments become
on*()methods. Replaceroom.onPeerJoin = fnwithroom.onUserJoin(({userId}) => …)(orroom.onPeerJoin(({peerId, userId}) => …)), which returns an unsubscribe function. - Callbacks pass context objects. Presence and media
listeners receive
{userId, peerId, …}rather than a positionalpeerIdstring. -
selfIdexport replaced byawait room.getSelf(). Keys are generated lazily via Web Crypto without module-load side effects. -
onJoinErrorreplaced byroom.onError().joinRoom(config, roomId)takes two arguments and emits typederr.codeevents. -
room.getPeers()returns metadata objects, androom.getUsers()lists unique users.getPeers()maps eachpeerIdto{userId, connection, direct, hops, roles}. - Action callbacks move to methods. Attach handlers with
action.onMessage(fn),onRequest(fn),onReceive(fn), andonReceiveProgress(fn)instead of config callbacks or property assignment.
1. Joining rooms, presence, and errors
Migrate participant tracking from onPeerJoin /
onPeerLeave to onUserJoin /
onUserLeave to deduplicate multiple open tabs per user, and
move join error handling to room.onError().
Before (≤ 0.26.x)
import {joinRoom, selfId} from 'trystero'
const room = joinRoom({appId: 'example.com/my-app'}, 'lobby', {
onJoinError: err => console.error(err)
})
console.log('My ID:', selfId)
room.onPeerJoin = peerId => console.log(`${peerId} joined`)
room.onPeerLeave = peerId => console.log(`${peerId} left`)After (0.27.0)
import {joinRoom} from 'trystero'
const room = joinRoom({appId: 'example.com/my-app'}, 'lobby')
const {userId, peerId} = await room.getSelf()
room.onError(err => console.error(err.code, err.message))
const offJoin = room.onUserJoin(({userId}) => console.log(`${userId} joined`))
room.onUserLeave(({userId}) => console.log(`${userId} left`))- Duplicate
joinRoom()calls for an active(appId, roomId)now throw instead of returning the existing instance. Callawait room.leave()before rejoining. - Explicit replay on subscribe.
onUserJoin,onPeerJoin,onPeerStream,onRoleChange, andstate.onChangeemit only new events by default. Pass{replay: true}to replay existing entries immediately when subscribing late. - Custom
config.peerIdremoved. BecausepeerIdanduserIdderive from ECDSA public keys, arbitrary caller-chosen IDs are no longer accepted. Configure persistence or custom key material viaconfig.identity.
2. Actions
makeAction(namespace, config?) now takes declarative options
only ({kind, roles}), with listeners registered via
.on*(fn) methods.
Before
// Tuple API (<= 0.24) or config callbacks (0.25–0.26)
const move = room.makeAction('move', {
onMessage: (data, {peerId, metadata}) => handleMove(peerId, data)
})
move.send({x: 10, y: 20}, {target: targetPeerId})After
const move = room.makeAction('move')
const unsub = move.onMessage((data, {userId, peerId, metadata, roles}) => {
handleMove(userId, data)
})
// target accepts a userId (delivered to all their tabs), peerId, or array
await move.send({x: 10, y: 20}, {target: targetUserId})- Single active
onRequestandonReceive. Registering a second handler without unsubscribing the previous one throws an error. - Targeted
send()validation.send(data, {target})rejects if any target is not connected, while broadcastsend(data)still resolves in an empty room. - Typed
ActionError.kind. Rejectedsend()andrequest()promises exposeerr.kind('timeout' | 'disconnected' | 'aborted' | 'rejected'), and errors thrown insideonRequestpropagate their message to the caller. - Zero-copy binary streaming. Buffers larger than 16 KiB
stream directly from the provided
ArrayBufferor typed array; do not mutate the buffer untilawait action.send(buf)settles.
3. Audio and video
Media APIs operate on MediaStream instances.
onPeerStream passes
(stream, {userId, peerId, metadata}), and
addStream() and replaceTrack() return
Promise<void>. addTrack,
removeTrack, onPeerTrack, and the
metadata argument on replaceTrack have been
removed; mutate tracks on your MediaStream and call
await room.addStream(stream, {metadata}) again to
sync changes.
Before
room.onPeerStream = (stream, peerId, metadata) => {
attachVideo(stream, peerId, metadata)
}
await Promise.all(room.addStream(stream))After
room.onPeerStream((stream, {userId, metadata}) => {
attachVideo(stream, userId, metadata)
})
await room.addStream(stream)4. Inspecting participants
Before
const peers = room.getPeers() // {[peerId]: RTCPeerConnection}
const count = Object.keys(peers).length
const pc = peers[peerId]After
// Participant roster keyed by userId
const users = room.getUsers() // {[userId]: {peerIds, roles}}
// Per-tab connection records across direct and multi-hop peers
const peers = room.getPeers() // {[peerId]: {userId, connection, direct, hops, roles}}
const pc = peers[peerId]?.connection // RTCPeerConnection | null5. Replacing onPeerHandshake
onPeerHandshake and handshakeTimeoutMs were
removed because single-hop admission callbacks cannot run across multi-hop
scale() topologies and relied on
unverified signaling IDs. Use the dedicated 0.27 APIs instead:
| Previous pattern | 0.27 replacement |
|---|---|
| Verifying peer identity | Automatic DTLS-bound userId and peerId verification (Identity) |
| Capping a 2- or 4-player lobby | joinRoom({appId, maxUsers: 2}, roomId) + room.onError ('room-full') |
| Exchanging display names, profiles, or client versions | room.makeUserState('profile', …), synced before onUserJoin fires |
| Host authority, allowlists, kicking, and banning | use: [roles(…)] with grantRole(), gated state/actions, and room.ban() |
| Rejecting oversized or unwanted binary transfers | action.onReceive(({byteLength, metadata, userId}) => …) |
6. Packaging and relay helpers
- Removed legacy subpaths and IPFS. Deprecated
trystero/<strategy>subpaths, prebuiltdist/trystero-*.min.jsfiles, and@trystero-p2p/ipfshave been removed. Importtrystero(Nostr default) or@trystero-p2p/<strategy>. TypeScript 5.0+ is required for TypeScript projects. - Unified
setRelayConnectivity(mode).relayConfig.manualReconnection,pauseRelayReconnection(), andresumeRelayReconnection()are replaced bysetRelayConnectivity('offline' | 'online' | 'auto'). -
@trystero-p2p/ws-relayserver.wsis now an optional peer dependency needed only on Node when importing@trystero-p2p/ws-relay/server. Passing<= 0formaxMessagesPerSecondormaxBurstMessagesthrows (passInfinityto disable rate limits).