Cloudflare Calls Backend Server (Express)

A reference implementation of a backend (in Express) for CloudflareCalls.js

ICEServers

ICEServers | Get ICE Servers

Generates TURN credentials and returns the iceServers configuration.

get
/api/ice-servers

Success 200

Field Type Description
iceServers Object

iceServers configuration.

Error 4xx

Name Description
500

Failed to generate ICE servers.

Participants

Participants | Get Participant Tracks

Retrieves a list of tracks for a specific participant in a room.

get
/api/rooms/:roomId/participant/:sessionId/tracks

Parameter

Field Type Description
roomId String

The ID of the room.

sessionId String

The session ID of the participant.

Success 200

Field Type Description
publishedTracks Object

Array of published track names.

Error 4xx

Name Description
404

Room or Participant not found.

Participants | Get Participants

Retrieves a list of all participants in a specified room along with their published tracks.

get
/api/rooms/:roomId/participants

Parameter

Field Type Description
roomId String

The ID of the room.

Success 200

Field Type Description
participants Object

An object containing an array of participants.

Error 4xx

Name Description
404

Room or Participant not found.

Rooms

Rooms | Create a new room

post
/api/rooms

Success 200

Field Type Description
roomId String

The unique ID of the created room.

404

Name Description
NotFound

Room not found.

Rooms | Inspect all rooms (development only)

Retrieve all rooms and their participants (development mode only).

get
/inspect-rooms

Success 200

Field Type Description
rooms Object

Object containing all rooms and participants.

Rooms | Join a room

post
/api/rooms/:roomId/join

Parameter

Field Type Description
roomId String

The ID of the room to join.

Request Body

Field Type Description
userId String

The user's unique identifier.

Success 200

Field Type Description
sessionId String

The session ID of the participant.

otherSessions Array

List of other participants in the room.

404

Name Description
NotFound

Room not found.

500

Name Description
ServerError

Failed to create Calls session.

Sessions

Sessions | Get Session State

Retrieves the current state of a session from Cloudflare Calls API.

get
/api/rooms/:roomId/sessions/:sessionId/state

Parameter

Field Type Description
roomId String

The ID of the room.

sessionId String

The session ID to query.

Success 200

Field Type Description
response Object

Session state from Cloudflare Calls API.

  tracks Array

List of tracks in the session.

  tracks.location String

Track location ('local' or 'remote').

  tracks.mid String

Media ID of the track.

  tracks.trackName String

Name/ID of the track.

  tracks.status String

Track status ('active', 'inactive', or 'waiting').

403

Name Description
Forbidden

Invalid or missing authentication token.

500

Name Description
SessionStateError

Failed to retrieve session state.

Sessions | Manage Data Channels

Manage data channel subscriptions

post
/api/rooms/:roomId/sessions/:sessionId/datachannels/new

Parameter

Field Type Description
roomId String

Room identifier

sessionId String

Session identifier

Request Body

Field Type Description
dataChannels Array

Array of data channel names

Success 200

Field Type Description
response Object

Response from Cloudflare Calls API.

Error 4xx

Name Description
404

Room or Participant not found.

400

Error from Cloudflare Calls API.

Sessions | Publish Tracks

post
/api/rooms/:roomId/sessions/:sessionId/publish

Parameter

Field Type Description
roomId String

The ID of the room.

sessionId String

The session ID of the participant.

Request Body

Field Type Description
offer Object

The SDP offer.

tracks Array

Array of track objects.

Success 200

Field Type Description
data Object

Response from Cloudflare Calls API.

404

Name Description
NotFound

Session not found in this room.

Sessions | Pull remote tracks

post
/api/rooms/:roomId/sessions/:sessionId/pull

Parameter

Field Type Description
roomId String

The ID of the room.

sessionId String

The session ID of the participant.

Request Body

Field Type Description
remoteSessionId String

The session ID of the remote participant.

trackName String

The exact name of the track to pull.

Success 200

Field Type Description
data Object

Response from Cloudflare Calls API.

404

Name Description
NotFound

Room or Session not found.

Sessions | Renegotiate Session

Renegotiate an existing session with new SDP offer

put
/api/rooms/:roomId/sessions/:sessionId/renegotiate

Parameter

Field Type Description
roomId String

Room identifier

sessionId String

Session identifier

Request Body

Field Type Description
sessionDescription Object

WebRTC session description

  sdp String

SDP offer

  type String

Type of SDP message

Success 200

Field Type Description
data Object

Response from Cloudflare Calls API

Sessions | Unpublish Track

post
/api/rooms/:roomId/sessions/:sessionId/unpublish

Header

Field Type Description
Authorization String

Bearer token

Parameter

Field Type Description
roomId String

The ID of the room

sessionId String

The session ID of the track owner

403

Name Description
Forbidden

User is not authorized to force unpublish others' tracks

Sessions | Update Track Status

Updates the enabled/disabled status of a track

post
/api/rooms/:roomId/sessions/:sessionId/track-status

Parameter

Field Type Description
roomId String

The ID of the room

sessionId String

The session ID

Request Body

Field Type Description
trackId String

The track ID

kind String

The track kind ('audio' or 'video')

enabled Boolean

Whether the track should be enabled

force optional Boolean

Whether to force the status change

Success 200

Field Type Description
result Object

Operation result

403

Name Description
Forbidden

Not authorized to update track status

Users

Users | Get User Info

Get information about a user. Returns full info for own user, limited info for others.

get
/api/users/:userId

Header

Field Type Description
Authorization String

Bearer token required

Parameter

Field Type Description
userId String

User ID or 'me' for current user

Success 200

Field Type Description
userId String

User's unique identifier

username String

User's display name

isModerator optional Boolean

Whether user is moderator (only included for own user)

role optional String

User's role (only included for own user)

403

Name Description
Forbidden

Invalid or missing token

404

Name Description
NotFound

User not found

Users | Get User Info

Get information about a user. Returns full info for own user, limited info for others.

get
/api/users/:userId

Header

Field Type Description
Authorization String

Bearer token required

Parameter

Field Type Description
userId String

User ID or 'me' for current user

Success 200

Field Type Description
userId String

User's unique identifier

username String

User's display name

isModerator optional Boolean

Whether user is moderator (only included for own user)

role optional String

User's role (only included for own user)

403

Name Description
Forbidden

Invalid or missing token

404

Name Description
NotFound

User not found

Generated with apidoc 1.2.0 - Tue May 06 2025 16:35:22 GMT+0000 (Coordinated Universal Time)