please select
RTC Engine
  • Overview
  • Web
    • Run Sample Demo
    • Integration
    • Basic Features
      • Screen Sharing
      • Live Streaming
      • Media Device
      • Audio Volume
      • Set Encoding Profile
      • Detect Network Quality
      • Detect Capabilities
    • Advance Features
      • Enable AI Denoiser
      • Enable Audio Mixer
      • Enable Watermark
      • Enable Virtual Background
      • Enable Beauty and Effects
      • Data Messages
      • Custom Capturing and Rendering
    • API List
    • Released Notes
    • Supported Platforms
    • Web FAQs
      • Optimize Multi-Person Video Calls
      • Handle Autoplay Restriction
      • Handle Firewall Restriction
      • Others
  • Android
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Newwork Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCStatistics
      • TRTCCloudListener
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Solution
      • Real-Time Chorus (TUIKaraoke)
        • Quick Integration
        • Implementation Steps
        • Song Synchronization
        • Lyric Synchronization
        • Vocal Synchronization
        • Mixing Stream Solution
        • TRTCKaraoke APIs
        • FAQs
    • Release Notes
  • iOS
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
    • Solution
      • Quick Integration
      • Implementation Steps
      • Song Synchronization
      • Lyric Synchronization
      • Vocal Synchronization
      • Mixing Stream Solution
      • TRTCKaraoke APIs
      • FAQs
    • Release Notes
  • macOS
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Sharing Computer Audio
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Hardware Devices
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • TRTCCloud
      • TRTCCloudDelegate
      • TRTCStatistics
      • TXAudioEffectManager
      • TXBeautyManager
      • TXDeviceManager
      • Type Definition
      • Deprecated Interface
      • ErrorCode
      • Release Notes
    • Release Notes
  • Windows
    • Run Sample Code
    • Integration
    • Basic Features
      • Sensing Network Quality
      • Enabling Screen Sharing
      • Setting Video Quality
      • Rotating Videos
    • Advanced Features
      • Testing Hardware Devices
      • Testing Network Quality
      • Custom Capturing and Rendering
      • Custom Audio Capturing and Playback
    • Client APIs
      • Overview
      • ITRTCCloud
      • ITRTCStatistics
      • TRTCCloudCallback
      • ITXAudioEffectManager
      • ITXDeviceManager
      • Type Definition
      • Deprecated Interface
      • Error Codes
    • Release Notes
  • Electron
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Flutter
    • Integration
      • 1.API Examples
      • 2.Importing the SDK
      • 3.Entering a Room
      • 4.Subscribing to Audio/Video Streams
      • 5.Publish Audio/Video Streams
      • 6.Exiting a Room
      • 7.Sensing Network Quality
      • 8.Enabling Screen Sharing
      • 9.Sharing Computer Audio
      • 10.Setting Video Quality
      • 11.Rotating Videos
    • Client APIs
      • Overview
      • Error Codes
  • Unity
    • Integration
      • 1.API Examples
      • 2Importing the SDK
    • Client APIs
      • Overview
      • Error Codes
  • Qt
    • Integration
      • 1.Importing the SDK
  • Overview
    • Overview
  • Concepts
  • Features
  • Performance Statistics
  • Pricing
    • Free Minutes
    • RTC-Engine Monthly Packages
    • Billing Explanation for Subscription Package Duration
    • Pay-as-you-go
      • Billing of Audio and Video Duration
      • Billing of On-Cloud Recording and Recording Delivery
      • Billing of MixTranscoding and Relay to CDN
  • FAQs
    • FAQs for Beginners
    • Migration Guide
      • Twilio Video to Tencent RTC
      • Billing
      • Features
      • UserSig
      • Firewall Restrictions
      • How to Downsize Installation Package
      • TRTCCalling for Web
      • Audio and Video Quality
      • Others
RTC Engine

3.Entering a Room

This document describes how to enter a TRTC room. Only after entering an audio/video room can a user subscribe to the audio/video streams of other users in the room or publish his or her own audio/video streams.

Call Guidelines

Step 1: Import SDK and Configure App Permissions

Please refer to the document Import SDK into the project to complete the SDK import.

Step 2: Create an SDK instance and set an event listener

Invoke various platform initialization interfaces to create the object instance of TRTC.
// Create a TRTCCloud singleton trtcCloud = (await TRTCCloud.sharedInstance())!; // Register TRTC event callback trtcCloud.registerListener(onRtcListener);

Step 3. Listen for SDK events

You can use callback APIs to listen for errors, warnings, traffic statistics, network quality, as well as various audio/video events of the SDK.
// We need to define a method to handle event callbacks, processing appropriately based on the type of the received event. // Taking onError as an example trtcCloud.registerListener(onRtcListener); onRtcListener(type, param) async { if (type == TRTCCloudListener.onError) { if (param['errCode'] == -1308) { MeetingTool.toast('Failed to initiate screen recording', context); } else { showErrordDialog(param['errMsg']); } } }

Step 4: Prepare the TRTCParams for entering the room

When calling the enterRoom interface, two key parameters need to be filled, namely TRTCParams and the application scene. A detailed introduction is as follows:

Parameter one: scene

This parameter refers to the specific application scene, whether it be video calls, interactive video broadcasting, audio calls, or interactive audio broadcasting:
Scenario Type

Scenario Introduction

TRTC_APP_SCENE_VIDEOCALL

Within the context of video calling, 720p and 1080p high-definition image quality is supported. A single room can accommodate up to 300 simultaneous online users, with a maximum of 50 users speaking at the same time.

TRTC_APP_SCENE_LIVE

In the context of interactive video broadcasting, the mic can be smoothly turned on/off without switching latency, with host latency as low as 300 milliseconds. Supports live streaming for hundreds of thousands of concurrent viewers, with playback delay reduced to 1000 milliseconds.
Note: In this scenario, you need to specify the current user's role using the 'role' field in TRTCParams.

TRTC_APP_SCENE_AUDIOCALL

In the audio call context, it supports 48 kHz duplex audio calls. A single room accommodates up to 300 concurrent online users, with a maximum of 50 people speaking at once.

TRTC_APP_SCENE_VOICE_CHATROOM

In the context of interactive audio live streaming, microphones can be switched on and off smoothly without delay. The host experiences a low latency of fewer than 300 milliseconds. It accommodates hundreds of thousands concurrent viewer users, with the broadcast delay reduced to 1000 milliseconds.
Note: In this scenario, you need to specify the current user's role using the 'role' field in TRTCParams.


Parameter 2: TRTCParams

TRTCParams is composed of numerous parameters, but typically, your attention could be principally directed towards filling out the following parameters:
Parameter name

Field Description

Supplementary Information

Data Type

Example

sdkAppId

Application ID

You can locate the SDKAppID within the Tencent Real-Time Communication console, if not present, click on the "Create Application" button to institute a new application.

Number

1400000123

userId

User ID

It can contain only letters, digits, underscores, and hyphens. In TRTC, a user cannot use the same user ID to enter the same room on two different devices at the same time.

String

"denny" or "123321"

userSig

The authentication ticket needed to enter a room

You can calculate userSig using the SDKAppID and userId. Please refer to Calculating and Using UserSig for the calculation method.

String

eJyrVareCeYrSy1SslI...

roomId

Room ID

Numeric type 'Room ID'. Be aware, if you wish to utilize a character sequence as the Room ID, please resort to the strRoomId field, rather than the roomId field, as strRoomId and roomId should not be used interchangeably.

Number

29834

strRoomId

Room ID

Room ID of string type. Note that `strRoomId` and `roomId` shouldn't be used interchangeably, as to the TRTC backend service, "123" and 123 are not the same room.

String

"29834"

role

Roles

Divided into "Anchor" and "Audience" roles, this field only needs to be specified when the TRTCAppScene is designated as TRTCAppSceneLIVE or TRTCAppSceneVoiceChatRoom, these two live streaming scenarios.

Enumeration

TRTCRoleAnchor or TRTCRoleAudience

Note:
TRTC does not support the simultaneous entry of the same userId on two different devices. Doing so could lead to interference.
Each endpoint in the application scenario, appScene, must be unified to prevent unpredictable issues from cropping up.

Step 5: Enter the room (enterRoom)

After preparing the two parameters from Step 4 (application scenario and TRTCParams), you can call the enterRoom function to enter the room.
enterRoom() async { try { userInfo['userSig'] = await GenerateTestUserSig.genTestSig(userInfo['userId']); meetModel.setUserInfo(userInfo); } catch (err) { userInfo['userSig'] = ''; print(err); }
// If your scenario is "interactive video live broadcast", please set the scene to TRTC_APP_SCENE_LIVE, and set the appropriate value for the role field in TRTCParams. await trtcCloud.enterRoom( TRTCParams( sdkAppId: GenerateTestUserSig.sdkAppId, userId: userInfo['userId'], userSig: userInfo['userSig'], role: TRTCCloudDef.TRTCRoleAnchor, roomId: meetId!), TRTCCloudDef.TRTC_APP_SCENE_LIVE); }
Event Callback If room entry is successful, SDK will return the onEnterRoom(result) event where result is a positive number, indicating the time consumed to join the room in milliseconds (ms). If room entry fails, SDK will also call back the onEnterRoom(result) event, but the parameter result will be a negative number, representing the error code of room entry failure.
//Listen for SDK's onEnterRoom event to check if room entry is successful or not
onRtcListener(type, param) async {
if (type == TRTCCloudListener.onEnterRoom) { if (param > 0) { MeetingTool.toast('Enter room success', context); } }
}