RelayrtcDocs
Get started
Documentation
Build calls

Audio-only rooms and participant roles

Grant speakers microphone authority while listeners receive audio without capture permission.

On this page

Use the ordinary room model for audio-only calls. Your backend controls publishing authority through participant token permissions; there is no separate audio-only room flag.

How audio-only rooms work

Issue all participants tokens without video:publish or screen:publish. Speakers receive audio:publish; listeners only need room:join to receive published audio. Hiding camera buttons matches the interface to the room policy, but the token enforces it.

A listener token does not prevent receiving video if another participant is allowed to publish it. Apply the audio-only policy to every token issuer for the room.

Requirements

Create a room and use a server key with tokens:create. Authenticate callers, check room membership and derive their speaker/listener role from trusted application data. Speakers need microphone permission and HTTPS or localhost. Listeners need no microphone permission if your UI does not start capture.

Choose participant permissions

Application roleToken permissions
Listenerroom:join
Speakerroom:join, audio:publish

These are application roles, not token fields. Add messages:send or metadata:update only where the application needs them. Previously issued tokens keep their authority; changing the token issuer does not revoke old tokens.

Issue tokens on your backend

This helper uses the quickstart's relay.ts. Call it only after authorizing the requested role on your backend.

TypeScript
import { relay } from './relay.js'
 
export async function issueAudioToken(roomId: string, name: string, role: 'speaker' | 'listener') {
  return relay.tokens.create(roomId, {
    participantName: name,
    ttlSeconds: 3600,
    permissions: role === 'speaker' ? ['room:join', 'audio:publish'] : ['room:join'],
  })
}

Return the appropriate caller's token, not the management key. Do not let request parameters grant the caller a speaker role without authorization.

Join with the browser SDK

Joining does not start capture. Speakers explicitly call room.microphone.enable() from their microphone button; listeners skip that action. Both roles attach received microphone tracks to audio elements. See the browser lifecycle reference.

Build the React audio interface

Render this component inside the provider and room from the quickstart. canSpeak reflects the server-authorized role; it controls visibility rather than granting permission.

React
'use client'
 
import { useState } from 'react'
import { useLocalParticipant, useMediaTrack, useRoom, useTracks } from '@relayrtc/react'
import type { RoomRemoteTrack } from '@relayrtc/react'
 
function RemoteAudio({ track }: { track: RoomRemoteTrack }) {
  const media = useMediaTrack(track)
  return <div>
    <audio ref={media.ref} autoPlay />
    {media.state === 'blocked' && (
      <button onClick={() => void media.play().catch(() => undefined)}>Play audio</button>
    )}
    {media.state === 'failed' && <p role="alert">{media.error?.message}</p>}
  </div>
}
 
export function AudioRoom({ canSpeak }: { canSpeak: boolean }) {
  const local = useLocalParticipant()
  const { connectionState } = useRoom()
  const tracks = useTracks({ types: ['audio'] })
  const [error, setError] = useState<string | null>(null)
 
  async function enable() {
    if (!local) return
    setError(null)
    try { await local.microphone.enable({ echoCancellation: true, noiseSuppression: true }) }
    catch (cause) { setError(cause instanceof Error ? cause.message : 'Microphone could not start') }
  }
 
  return <section>
    {canSpeak && <button disabled={!local || connectionState !== 'connected'}
      onClick={() => void enable()}>Enable microphone</button>}
    {error && <p role="alert">{error}</p>}
    {tracks.map(track => <RemoteAudio key={track.id} track={track} />)}
  </section>
}

The playback button handles browser autoplay restrictions. Add mute/unmute controls using microphone controls; use disable() when you want to release capture.

Role changes and moderation

Creating another token creates another participant identity; it does not edit permissions on an existing connection. Use a controlled leave/rejoin flow when changing an ordinary participant's role this way. Issuing a listener token does not remove a connected speaker's publishing permission.

Keep administrative removal and room-ending actions behind backend moderator authorization. Publishing microphone audio does not grant moderation authority.

Live guest grants

Streaming guests use a separate run-scoped authority and lifecycle. Their moderation and rejoin behavior must not be assumed to apply to ordinary room tokens. See guests and co-hosting and its matching-build requirements.

Audio-only receiving preference

setQuality('audio-only') is a receiving preference for one video subscription. It does not change publishing authority or enforce an audio-only room. Use token permissions for policy and quality preferences for subscriber bandwidth decisions.

Check your implementation

Confirm that listeners hear audio without granting microphone access, cannot publish even through direct SDK calls, and cannot publish video or screens. Test the same restrictions on every join and renewal endpoint, and show useful feedback for denied capture or blocked playback.