please select

Web

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.



SDK Usage Overview

1. Call the TRTC.create() method to create the trtc object.
2. Call the trtc.enterRoom() method to enter the room, then other users will receive the TRTC.EVENT.REMOTE_USER_ENTER event.
3. After entering the room, you can turn on the camera and microphone and publish them to the room.
Call the TRTC.startLocalVideo() method to turn on the camera and publish it to the room.
Call the TRTC.startLocalAudio() method to turn on the microphone and publish it to the room.
4. When a remote user publishes audio and video, the SDK will automatically play the remote audio by default. You need to play the remote video by:
Listen for the TRTC.EVENT.REMOTE_VIDEO_AVAILABLE event before entering the room to receive all remote user video publishing events.
In the event callback function, call the trtc.startRemoteVideo() method to play the remote video.




Step 1. Creating a TRTC object

TRTC class, whose instance represents a local client. The object methods of TRTC provide functions such as joining a call room, previewing a local camera, publishing a local camera and microphone, and playing remote audio and video.
Create a TRTC object through the TRTC.create() method
const trtc = TRTC.create();
Note:
If you use the Vue3 framework, it is necessary to use markRaw to mark the trtc instance in order to avoid the conversion of trtc into the Proxy object by Vue, which may cause some unexpected problems.
import { markRaw } from 'vue';
const trtc = markRaw(TRTC.create());

Step 2. Entering the room

Call the trtc.enterRoom() method to enter the room. Usually called in the click callback of the Start Call button. Key parameters:
Name
Description
Type
Example
sdkAppId
The sdkAppId of the audio and video application you created on Tencent Cloud.
number
1400000123
userId
It is recommended to limit the length to 32 bytes, and only allow uppercase and lowercase English letters (a-zA-Z), numbers (0-9), underscores, and hyphens.
string
"mike"
userSig
User signature, refer to UserSig.
string
eJyrVareCeYrSy1SslI...
roomId
Numeric type roomId. The value must be an integer between 1 and 4294967294.
If you need to use a string type roomId, please use the strRoomId parameter. One of roomId and strRoomId must be passed in. If both are passed in, the roomId will be selected first.
number
29834
strRoomId
String type roomId. The length is limited to 64 bytes, and only supports the following characters:
Uppercase and lowercase English letters (a-zA-Z)
Numbers (0-9)
Space ! # $ % & ( ) + - : ; < = . > ? @ [ ] ^ _ { } |
Note: It is recommended to use a numeric type roomId. The string type room id "123" is not the same room as the numeric type room id 123.
string
"29834"
scene
rtc:Real-time call scene.
live:Interactive live streaming scene
string
'rtc' or 'live'
role
User role, only works for live scene
anchor
audience The audience role does not have the permission to publish local audio and video, only the permission to watch remote streams.
If the audience wants to interact with the anchor by connecting to the microphone, please switch the role to the anchor through trtc.switchRole() before publishing local audio and video.
string
'anchor' or 'audience'
For more detailed parameter descriptions, refer to the interface document trtc.enterRoom().
try {
await trtc.enterRoom({ roomId: 8888, scene:'rtc', sdkAppId, userId, userSig });
console.log('Entered the room successfully');
} catch (error) {
console.error('Failed to enter the room ' + error);
}