Skip to contentSkip to navigationSkip to topbar
On this page

Understanding Video Rooms


(warning)

Warning

This documentation is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2026(link takes you to an external page).

We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide(link takes you to an external page) to assist you in minimizing any service disruption.

This guide introduces the concept of Twilio Video Rooms and helps developers decide which type of Room is most appropriate for their use-case:

  • WebRTC Go Room
  • Peer-to-peer (P2P) Room
  • Group Room

This guide also introduces the different alternatives for creating Rooms as well as their advantages and drawbacks:

  • Rooms created using the REST API
  • Ad-hoc Rooms (client-side Room creation)

Signaling and Media

signaling-and-media page anchor

RTC (Real-Time Communication) services are typically architected in two layers:

  • Signaling Plane : This deals with the control information. The communicating entities typically exchange signaling messages for agreeing on what's to be communicated (e.g. audio, video, etc) and how's to be communicated (e.g. codecs, formats, etc.)
  • Media Plane : It deals with the media information itself. Media packets typically transport encoded and encrypted audio and video bits.

In Twilio Programmable Video, signaling always takes place between clients and the Twilio's cloud, which orchestrates the communication. Media in turn may be mediated by Twilio, but might also be exchanged directly among clients, depending on the type of Video Room.


The notion of a Room is central to Twilio Programmable Video. Intuitively, a Room represents a virtual space where end-users communicate. Technically, a Room is a computing resource that provides Real-time Communications (RTC) services to client applications through a set of APIs. More specifically, a Room provides:

  • A session service: end-users can connect and disconnect from Rooms. When an end-user connects, we say it is a Room Participant.
  • An RTC Service: Participants can communicate audio, video, and other data using WebRTC.

Video Rooms are based on a publish/subscribe model. This means that a Participant can publish media Tracks to the Room. The other Participants can then subscribe to such Tracks to start receiving the media information.

Twilio Programmable Video exposes four types of Rooms with different capabilities: WebRTC Go Rooms, P2P Rooms (Peer-to-Peer ), Group Rooms, and Small Group Rooms.

(warning)

Warning

Small Group Rooms is a legacy Room type and Group Rooms is the recommended Room type for developers creating multi-party applications.

Video WebRTC Go Rooms

video-webrtc-go-rooms page anchor

A WebRTC Go Room (aka "Go Room") can be used for one-on-one video calls. Participant minutes and TURN server usage is FREE. Go Rooms use a peer-to-peer topology and are similar to P2P Rooms. However, the maximum number of participants in a Go Room is two. There can be a maximum of 500 concurrent participants at a time per account; for example, 250 rooms with 2 participants.

In a Peer-to-Peer Room (aka "P2P Room"), Participants exchange media directly so that:

  • Media is encrypted end-to-end (E2E) using WebRTC security protocols.
  • Twilio does not mediate the media exchange, which takes place through direct communication among Participants. The only exception is when media exchange requires TURN(link takes you to an external page) . In that case, a TURN server will blindly relay the encrypted media bits to guarantee connectivity. The TURN server cannot decrypt or manipulate the media.
  • As Twilio does not intercept the media in P2P Rooms, it is not possible to record or transcode the media or make it interoperate with other RTC services.
  • Despite not being in the media path, Twilio manages the signaling path, making it possible for Participants to discover each other and negotiate the communications in agreement with the application and SDK requirements. Hence, signaling connectivity to Twilio's cloud is still necessary.

The following picture illustrates the architecture of a P2P Room.

p2p-rooms-architecture-animation.

As seen above, in a P2P Room clients need to send their media streams once per subscriber. As a result, upstream bandwidth (and typically battery consumption) scales as n-1, where n is the number of Participants. Because of this, P2P Rooms do not scale well with n.

For best video quality, we recommend that P2P rooms have no more than 3 participants in a video call (or 4 participants with low-quality video). For audio-only calls, P2P rooms can have up to 10 participants.

In a Group Room, Participants exchange media through Twilio. In a Group Room:

  • Participants publish media to a Twilio Selective Forwarding Unit (SFU). An SFU is a Media Server that decrypts the media, processes, re-encrypts, and routes the media tracks to the correct destinations.
  • Media is not E2E encrypted, as the SFU keeps media unencrypted in memory to process it.
  • Services such as recordings and public switched telephone network (PSTN) interoperability can be added, as Twilio acts as media middleware.

The following picture illustrates the architecture of a Group Room.

group-rooms-architecture-animation.

As shown above, in a Group Room, clients only need to publish their media tracks once to the SFU, which clones and routes the media to the correct subscribers. Because of this, upstream bandwidth and battery consumption are independent of the number of Participants in the Room.

The following table illustrates the main properties of the different Twilio Rooms:

Go RoomP2P RoomGroup Room
E2E encryptionYesYesNo
Upstream BW scales with1n-1n-1Constant
Downstream BW scales with1n-1n-1n-1
Screensharing supportedYesYesYes
Audio/Video/Data TracksYesYesYes
Max Participants23**50
Rooms REST APIYesYesYes
Ad-hoc RoomsYesYesYes
Participants APIYesYesYes
Published Track APIYesYesYes
Codec PreferencesYesYesYes
VP8 SimulcastNoNoYes
Dominant Speaker DetectionNoNoYes
Network Quality APINoNoYes
Track Subscription APINoNoYes
RecordingsNoNoYes
CompositionsNoNoYes
PSTN InteroperabilityNoNoYes
Track Priority APINoNoYes
Network Bandwidth Profile APINoNoYes

*n denotes the number of Subscribers that, by default, is the same as the number of Participants
**Can support up to 10 audio-only participants, but max 3 participants recommended when video is published


Creating Rooms: REST vs. Ad-hoc

creating-rooms-rest-vs-ad-hoc page anchor

There are two alternatives for creating Rooms: The Rooms REST API and Ad-hoc Rooms

Developers can create Rooms by POSTing an HTTP message to Twilio. The Rooms REST API documentation provides reference information as well as examples on how this can be done for all Room types. Creating Rooms through the REST API should only be done when the additional flexibility the API provides is needed; otherwise, using Ad-hoc Rooms will help your application scale more effectively. For more information, see the Guide to Scaling Applications.

Rooms created using the REST API comply with the following:

  • First join timeout: the first Participant must join within a specific amount of time, otherwise the Room is destroyed. By default, the first join timeout is 5 minutes, and this can be configured via the REST API when creating the Room (with the unused room timeout parameter).
  • Last leave timeout: the amount of time before the Room is destroyed after the last Participant leaves. The default value for this is 5 minutes, and this can be configured via the REST API when creating the Room (with the empty room timeout parameter).
  • Max Participant duration: a Participant can be connected to the Room up to 24 hours. After that time the Participant is disconnected.
  • Max Room duration: a Room may exist up to 24 hours from creation time. After that time the Room is destroyed and all Participants get disconnected.

Rooms can also be created just-in-time when the first Participant connects. When a Room is created that way, we say it is an ad-hoc Room. This is the recommended way of creating rooms, because Ad-hoc Rooms allow you to create many Rooms in a short period of time, and they allow you to create a Room without having to make a REST API call. You can scale with REST API Room creation, but you will have a limitation around burst creation of Rooms. For more information on this, see the Guide to Scaling Applications.

In order to use ad-hoc Rooms, developers must enable Client-side Room Creation in the Twilio Console Room Settings(link takes you to an external page):

Client side room creation in Twilio Console.

Ad-hoc rooms will be configured based on the Room settings you have configured in the Twilio Console. Before enabling Client-side Room Creation, you should verify that the additional settings in the Console accurately represent the settings for the Rooms that you would like to create. For example, you should make sure that Room Type represents the type of Room you would like all ad-hoc Rooms to be; when an ad-hoc room is created, it follows the configuration settings in the Twilio Console(link takes you to an external page).

Make sure to press Save when you are doing making changes to the configuration in the Twilio Console.

Once that's done, a Room with the specified type will be created as soon as a Participant SDK connects. For example, the following code snippet illustrates how to do this in JavaScript:

1
connect('$TOKEN', {name: 'myFancyRoomName' }).then(room => {
2
console.log(`Successfully joined a Room: ${room}`);
3
room.on('participantConnected', participant => {
4
console.log(`A remote Participant connected: ${participant}`);
5
});
6
}, error => {
7
console.error(`Unable to connect to Room: ${error.message}`);
8
});

Notice that a Room name must be specified. Names of active Rooms must be unique. Subsequent Participants connecting with that name will join that Room instead of creating a new one.

Ad-hoc Rooms comply with the following:

  • First join timeout: none, as the Room is created when the first participant connects.
  • Last leave timeout: the Room is destroyed immediately after the last Participant leaves.
  • Max Participant duration: a Participant can be connected to the Room up to 24 hours. After that time the Participant is disconnected.
  • Max Room duration: a Room may exist up to 24 hours from creation time. After that time the Room is destroyed and all participants get Disconnected.

Comparing REST vs. Ad-hoc Rooms

comparing-rest-vs-ad-hoc-rooms page anchor

The following table illustrates the main differences between Ad-hoc Rooms and Rooms created using the REST API:

REST RoomsAd-hoc Rooms
Room creation methodPOST requestSDK connect primitive
Room creation timeWhen POST is receivedWhen first participant connects
First join timeoutConfigurable, 5 minutes by defaultNA
Last leave timeoutConfigurable, 5 minutes by default0
Max Participant duration24 hours24 hours
Max Room Duration24 hours24 hours

Audio-Only Group Room Configuration

audio-only-group-room-configuration page anchor

There are some call and conference use cases where video is not required at all. For these audio-only use cases, a Group Room can be configured for audio only such that a lower price is applied to the Participant Minutes. To configure a Group Room for audio only, set the AudioOnly field to true when creating the Room via the REST API. Alternatively enable the Audio Only setting in the Twilio Console Room Settings(link takes you to an external page), which will default all created Rooms to audio-only.

When a Group Room is configured for audio-only, data tracks can still be published, however an attempt to publish a video track will result in a client error.


Small vs. Regular Group Rooms

small-vs-regular-group-rooms page anchor
(warning)

Warning

Small Group Rooms is a legacy Room type and Group Rooms is the recommended Room type for developers creating multi-party applications.

Small Group Rooms behaves functionally the same as Group Rooms with the exception that Small Group Rooms is limited to a maximum of 4 participants. The price for Group Room participant minutes is the same as Small Group Room participant minutes.


WebRTC Go Rooms or P2P Rooms or Group Rooms: Which Room Should I Use?

webrtc-go-rooms-or-p2p-rooms-or-group-rooms-which-room-should-i-use page anchor
  • In general, Group Rooms provide the most functionality and flexibility. They support multi-party calls of more than 2 participants, recordings, PSTN dial-in/dial-out, and additional quality controls.
  • If your use case is 2-3 participants, you do not need recordings or PSTN support, and you need end-to-end encryption of the media for compliance reasons, then P2P Rooms will work well for you.
  • WebRTC Go Rooms are designed for developers looking to launch their application as quickly as possible with minimal cost. These Rooms are functionally similar to P2P Rooms. However, there is a maximum of 2 participants in a single Room at one time and a scale limit of 500 participants in WebRTC Go Rooms at any instant in time.

Want to get started with Rooms? The following links may help you:

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.