CloudflareCalls

CloudflareCalls

Represents the CloudflareCalls library for managing real-time communications.

Constructor

new CloudflareCalls(config)

Description:
  • Creates an instance of CloudflareCalls.
Source:
Parameters:
Name Type Description
config Object Configuration object.
Properties
Name Type Description
backendUrl string The backend server URL.
websocketUrl string The WebSocket server URL.

Members

QUALITY_PRESETS :Object.<string, QualityPreset>

Source:
Type:

pendingQualitySettings :QualityPreset

Source:
Type:

statsMonitoringState :'stopped'|'monitoring'

Source:
Type:
  • 'stopped' | 'monitoring'

Methods

(async) createRoom(options) → {Promise.<Object>}

Description:
  • Creates a new room with optional metadata.
Source:
Parameters:
Name Type Description
options Object Room creation options
Properties
Name Type Attributes Description
name string <optional>
Room name
metadata Object <optional>
Room metadata
Returns:
Created room information including roomId, name, metadata, etc.
Type
Promise.<Object>

(async) getAvailableDevices() → {Promise.<Object>}

Description:
  • Retrieves the list of available media devices.
Source:
Returns:
An object containing arrays of audio input, video input, and audio output devices.
Type
Promise.<Object>

(async) getConnectionStats() → {Promise.<ConnectionStats>}

Description:
  • Get a snapshot of current connection statistics
Source:
Returns:
Current connection statistics
Type
Promise.<ConnectionStats>

(async) getSessionState() → {Promise.<Object>}

Description:
  • Gets the session state
Source:
Returns:
The session state
Type
Promise.<Object>

(async) getTrackStatus(trackName) → {Promise.<string>}

Description:
  • Gets the track status
Source:
Parameters:
Name Type Description
trackName string The track name
Returns:
The track status
Type
Promise.<string>

(async) getUserInfo(userIdopt) → {Promise.<Object>}

Description:
  • Gets information about a user
Source:
Parameters:
Name Type Attributes Default Description
userId string <optional>
null Optional user ID. If omitted, returns current user's info
Returns:
User information including moderator status
Type
Promise.<Object>

getUserMetadata() → {Object}

Description:
  • Retrieves the current user metadata.
Source:
Returns:
The user metadata.
Type
Object

(async) joinRoom(roomId, metadataopt) → {Promise.<void>}

Description:
  • Joins an existing room.
Source:
Parameters:
Name Type Attributes Default Description
roomId string The ID of the room to join.
metadata Object <optional>
{} Optional metadata for the user.
Returns:
Type
Promise.<void>

(async) leaveRoom() → {Promise.<void>}

Description:
  • Leaves the current room and cleans up connections.
Source:
Returns:
Type
Promise.<void>

(async) listParticipants() → {Promise.<Array.<Object>>}

Description:
  • Lists all participants currently in the room.
Source:
Throws:
If not connected to any room.
Type
Error
Returns:
An array of participant objects.
Type
Promise.<Array.<Object>>

(async) listRooms() → {Promise.<Array>}

Description:
  • Lists all available rooms.
Source:
Returns:
List of rooms
Type
Promise.<Array>

onConnectionStats(callback)

Description:
  • Register a callback to receive connection statistics
Source:
Parameters:
Name Type Description
callback function Function to receive stats updates

onDataMessage(callback)

Description:
  • Registers a callback for incoming data messages.
Source:
Parameters:
Name Type Description
callback function The callback function to handle data messages.

onParticipantJoined(callback)

Description:
  • Registers a callback for participant joined events.
Source:
Parameters:
Name Type Description
callback function The callback function to handle participant joins.

onParticipantLeft(callback)

Description:
  • Registers a callback for participant left events.
Source:
Parameters:
Name Type Description
callback function The callback function to handle participant departures.

onRemoteTrack(callback)

Description:
  • Registers a callback for remote track events.
Source:
Parameters:
Name Type Description
callback function The callback function to handle remote tracks.

onRemoteTrackUnpublished(callback)

Description:
  • Registers a callback for remote track unpublished events.
Source:
Parameters:
Name Type Description
callback function The callback function to handle track unpublished events.

onRoomMetadataUpdated(callback)

Description:
  • Register callback for room metadata updates
Source:
Parameters:
Name Type Description
callback function Callback function

onTrackStatusChanged(callback)

Description:
  • Registers a callback for track status changed events.
Source:
Parameters:
Name Type Description
callback function The callback function to handle track status changes.

onWebSocketMessage(callback) → {function}

Description:
  • Registers a callback for WebSocket messages
Source:
Parameters:
Name Type Description
callback function Function to call when WebSocket messages are received
Returns:
Function to unregister the callback
Type
function

(async) previewMedia(params, previewElementopt) → {Promise.<MediaStream>}

Description:
  • Previews media streams with specified device IDs.
Source:
Parameters:
Name Type Attributes Default Description
params Object Parameters for media preview.
Properties
Name Type Attributes Description
audioDeviceId string <optional>
The ID of the audio input device to use.
videoDeviceId string <optional>
The ID of the video input device to use.
previewElement HTMLMediaElement <optional>
null The media element to display the preview.
Throws:
If there is an issue accessing the media devices.
Type
Error
Returns:
The media stream being previewed.
Type
Promise.<MediaStream>

(async) publishTracks() → {Promise.<void>}

Description:
  • Publishes the local media tracks to the room.
Source:
Throws:
If there is no local media stream to publish.
Type
Error
Returns:
Type
Promise.<void>

(async) selectAudioInputDevice(deviceId) → {Promise.<void>}

Description:
  • Selects a specific audio input device.
Source:
Parameters:
Name Type Description
deviceId string The ID of the audio input device to select.
Returns:
Type
Promise.<void>

(async) selectAudioOutputDevice(deviceId) → {Promise.<void>}

Description:
  • Selects a specific audio output device.
Source:
Parameters:
Name Type Description
deviceId string The ID of the audio output device to select.
Returns:
Type
Promise.<void>

(async) selectVideoInputDevice(deviceId) → {Promise.<void>}

Description:
  • Selects a specific video input device.
Source:
Parameters:
Name Type Description
deviceId string The ID of the video input device to select.
Returns:
Type
Promise.<void>

(async) sendDataToAll(data) → {void}

Description:
  • Send a data message to all participants in the room via WebSocket.
Source:
Parameters:
Name Type Description
data Object The JSON object to send.
Returns:
Type
void

setDebugMode(enabled)

Description:
  • Enable or disable debug logging
Source:
Parameters:
Name Type Description
enabled boolean Whether to enable debug logging

setMediaQuality(quality)

Description:
  • Sets the media quality for audio and video tracks
Source:
Parameters:
Name Type Description
quality string | QualityPreset Either a preset name ('high', 'medium', 'low') or a custom quality object
Properties
Name Type Attributes Description
video VideoQualitySettings <optional>
Video quality settings
audio AudioQualitySettings <optional>
Audio quality settings
Throws:
If preset name is invalid
Type
Error

setToken(token)

Description:
  • Sets the user token for server requests. This should be a JWT token, and will be delivered in Authorization headers (HTTP) and to authenticate websocket join requests.
Source:
Parameters:
Name Type Description
token String The metadata to associate with the user.

setUserMetadata(metadata)

Description:
  • Sets the user metadata and updates it on the server.
Source:
Parameters:
Name Type Description
metadata Object The metadata to associate with the user.

(async) shareScreen() → {Promise.<void>}

Description:
  • Starts screen sharing.
Source:
Returns:
Type
Promise.<void>

startStatsMonitoring(intervalopt)

Description:
  • Start monitoring connection statistics
Source:
Parameters:
Name Type Attributes Default Description
interval number <optional>
1000 How often to gather stats in milliseconds

stopStatsMonitoring()

Description:
  • Stop monitoring connection statistics
Source:

toggleMedia(options) → {void}

Description:
  • Toggles the enabled state of video and/or audio tracks.
Source:
Parameters:
Name Type Description
options Object Options to toggle media tracks.
Properties
Name Type Attributes Default Description
video boolean <optional>
null Whether to toggle video tracks.
audio boolean <optional>
null Whether to toggle audio tracks.
Returns:
Type
void

(async) unpublishAllTracks(trackKind, forceopt) → {Promise.<void>}

Description:
  • Unpublishes all currently published tracks (with filters for type)
Source:
Parameters:
Name Type Attributes Default Description
trackKind string The kind of track to unpublish ('audio' or 'video').
force boolean <optional>
false If true, forces track closure without renegotiation.
Returns:
Type
Promise.<void>

(async) updatePublishedTracks() → {Promise.<void>}

Description:
  • Updates the published media tracks.
Source:
Throws:
If the PeerConnection is not established.
Type
Error
Returns:
Type
Promise.<void>

(async) updateRoomMetadata(updates) → {Promise.<Object>}

Description:
  • Updates room metadata.
Source:
Parameters:
Name Type Description
updates Object Metadata updates
Properties
Name Type Attributes Description
name string <optional>
New room name
metadata Object <optional>
New room metadata
Returns:
Updated room information
Type
Promise.<Object>