RelayrtcDocs
Get started
Documentation
Backend integration

Webhooks

Register a receiver, verify signed requests and handle retries without duplicate work.

On this page

Webhooks notify your backend about resource events. Create an endpoint in the relevant project environment, subscribe to the events your application needs, and verify every delivered request before processing it.

Provide a receiver URL

Use a server key with webhooks:write and the quickstart's relay.ts:

TypeScript
import { relay } from './relay.js'
 
export async function registerReceiver() {
  return relay.webhooks.create({
    url: 'https://app.example.com/webhooks/relayrtc',
    eventTypes: ['room.ended', 'participant.joined'],
  })
}

Save the returned signingSecret in backend secret storage. Creation and rotation reveal it; ordinary endpoint reads do not. The receiver URL is your HTTP endpoint, not the signaling service or an SDK-generated address.

Use a publicly reachable HTTPS receiver. Delivery rejects private/internal destinations, including localhost. For local development, route a public tunnel to your receiver. Self-hosted operators must configure webhook delivery, including the signing-encryption key; registration alone does not start an unconfigured delivery worker.

Verify before parsing

This handler uses standard Request and Response objects. Adapt it to your backend's HTTP routing. Supply enqueueOnce from your persistence layer: it must atomically insert the event ID and a durable job, treating an existing event as successful duplicate delivery.

TypeScript
import { verifyWebhookRequest } from '@relayrtc/node'
 
type EnqueueOnce = (eventId: string, event: unknown) => Promise<void>
 
export async function receiveWebhook(request: Request, enqueueOnce: EnqueueOnce) {
  const secret = process.env.RELAYRTC_WEBHOOK_SECRET
  if (!secret) return new Response('Receiver is not configured', { status: 503 })
 
  const rawBody = new Uint8Array(await request.arrayBuffer())
  if (!verifyWebhookRequest(secret, rawBody, request.headers)) {
    return new Response('Invalid signature', { status: 401 })
  }
 
  let event: unknown
  try { event = JSON.parse(new TextDecoder().decode(rawBody)) }
  catch { return new Response('Invalid JSON', { status: 400 }) }
 
  if (typeof event !== 'object' || event === null || !('id' in event) || typeof event.id !== 'string') {
    return new Response('Missing event identity', { status: 400 })
  }
 
  try { await enqueueOnce(event.id, event) }
  catch { return new Response('Receiver is temporarily unavailable', { status: 503 }) }
  return new Response(null, { status: 204 })
}

Configure an appropriate request-size limit in your HTTP framework or reverse proxy. Keep the raw body intact: parsing JSON and serializing it again changes the signed bytes. The verifier checks the delivery headers and timestamp with a default tolerance of 300 seconds. Keep the receiver's clock synchronized.

Validate the event type and payload needed by each job before applying application changes. The generic receiver above verifies and queues the event; it does not implement application-specific side effects.

Delivery policy

Delivery can occur more than once. Each run permits up to eight attempts within seven days. Network errors, HTTP 408, 425, 429 and 5xx responses are retryable. Other unsuccessful HTTP responses stop the run.

The configured retry delays are 5 seconds, 30 seconds, 2 minutes, 10 minutes, 30 minutes, 1 hour and 6 hours, with additional jitter. Keep the receiver quick by queueing longer work. Do not assume arrival order; reconcile current resource state when an event alone is insufficient.

Completed delivery logs are retained for 30 days after the latest outcome. Use delivery inspection to diagnose receiver errors.

Explicit replay

Replay requires an enabled endpoint and a terminal delivery. Fetch the current delivery, then supply its replay count to avoid racing another replay:

TypeScript
import { relay } from './relay.js'
 
export async function replayDelivery(endpointId: string, deliveryId: string) {
  const delivery = await relay.webhooks.deliveries.get(endpointId, deliveryId)
  return relay.webhooks.deliveries.replay(endpointId, deliveryId, {
    expectedReplayCount: delivery.replayCount,
  })
}

Replay starts a new run while preserving the event and delivery identities. There are at most 100 explicit replays per delivery. The current endpoint URL and signing secret are used for replay; automatic retries retain the URL selected for their run. Your deduplication policy must remain valid for both.

Secret rotation

Rotation replaces the endpoint secret immediately. Coordinate the receiver update and inspect any failed deliveries. Signatures made with the previous secret cannot be verified with the new one.

See signature verification for exact headers and the signing format.

Event types and payloads

Use the event catalog for room, participant, quality and streaming families. Subscribe to specific events and reconcile resource state after recovery. Check that the deployed server emits the event and that any SDK constants you import exist in your installed version.

For streaming workflows, source, broadcast, destination, recording and viewer readiness are distinct concepts. A source event is not proof that every output or viewer is receiving media. Link processing to the identifiers and lifecycle described by that event's resource reference.