Skip to content

Repository files navigation

@webrtc-node/trpc-webrtc-link

A complete tRPC v11 transport for ordered, reliable WebRTC data channels.

It provides a terminating client link and a server handler with:

  • queries, mutations, subscriptions, and cancellation;
  • tRPC transformers, custom error shapes, and typed context;
  • tracked() event IDs with retryLink and reconnect resumption;
  • reusable channel factories, connection state, lifecycle callbacks, and server-requested reconnects;
  • client and server keep-alive;
  • bounded fair backpressure, frame limits, and concurrent-operation limits;
  • browser WebRTC and Node.js WebRTC through @webrtc-node/webrtc.

Applications remain responsible for authenticated SDP/ICE signaling and for creating a fresh data channel when a reconnecting factory is called.

Install

npm install @webrtc-node/trpc-webrtc-link @trpc/client @trpc/server

Node.js WebRTC peers also install:

npm install @webrtc-node/webrtc

Start

Pass the same established channel to createWebRTCLink() on the client and createWebRTCHandler() beside the tRPC router:

const link = createWebRTCLink<AppRouter>({ channel });
const client = createTRPCClient<AppRouter>({ links: [link] });

createWebRTCHandler({
  router: appRouter,
  channel: peerChannel,
  peer: authenticatedPeer,
  createContext: ({ peer }) => ({ userId: peer.userId }),
});

await link.connect();
const greeting = await client.greeting.query();

See the complete package guide, the connection lifecycle guide, the wire protocol reference, and the runnable browser-to-Node example.

Project history is in the changelog. Contributions and security reports use the files under .github.

About

tRPC v11 transport for established WebRTC RTCDataChannels

Resources

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages