import TRTCCloud from 'trtc-electron-sdk';const rtcCloud = new TRTCCloud();
function onError(errCode, errMsg) {// For information on the error codes, see https://www.tencentcloud.com/document/product/647/35124#error-codesconsole.log(errCode, errMsg);}function onWarning(warningCode, warningMsg) {// For information on the warning codes, see https://www.tencentcloud.com/document/product/647/35124#warning-codesconsole.log(warningCode, warningMsg);}rtcCloud.on('onError', onError);rtcCloud.on('onWarning', onWarning);
TRTCParams
enterRoom
API, you need to enter two key parameters: TRTCParams
and TRTCAppScene
.TRTCAppSceneVideoCall
(video call) or TRTCAppSceneAudioCall
(audio call). This mode is suitable for one-to-one audio/video calls or online meetings for up to 300 attendees.TRTCAppSceneLIVE
(video live streaming) or TRTCAppSceneVoiceChatRoom
(audio live streaming). This mode is suitable for live streaming to up to 100,000 users. Make sure you specify the role field (valid values: anchor, audience) in TRTCParams
if you use this mode.TRTCParams
consists of many fields; however, you usually only need to pay attention to how to set the following fields:Parameter | Description | Remarks | Data Type | Sample Value |
SDKAppID | Application ID | You can view your application ID in the TRTC console. If you don’t have an application yet, click Create application to create one. | 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 | String | eJyrVareCeYrSy1SslI... | |
roomId | Room ID | Numeric room ID. If you want to use string-type room IDs, specify strRoomId. Do not use strRoomId and roomId at the same time. | Number | 29834 |
strRoomId | Room ID | String-type room ID. Do not use strRoomId and roomId at the same time. "123" and 123 are considered different rooms by the TRTC backend. | String | "29834" |
role | Role | There are two roles: anchor and audience. This field is required only when TRTCAppScene is set to the TRTCAppSceneLIVE or TRTCAppSceneVoiceChatRoom live streaming scenarios. | Enumeration | TRTCRoleAnchor or TRTCRoleAudience |
userId
to enter the same room on two different devices at the same time; otherwise, there will be a conflict.appScene
must be the same on each client. Inconsistent appScene
may cause unexpected problems.enterRoom
)TRTCAppScene
and TRTCParams
as described in step 4, you can call the enterRoom
API to enter the room.import { TRTCParams, TRTCRoleType, TRTCAppScene } from 'trtc-electron-sdk';const param = new TRTCParams();param.sdkAppId = 1400000123;param.userId = "denny";param.roomId = 123321;param.userSig = "xxx";param.role = TRTCRoleType.TRTCRoleAnchor;// If your scenario is live streaming, set the application scenario to `TRTC_APP_SCENE_LIVE`rtcCloud.enterRoom(param, TRTCAppScene.TRTCAppSceneLIVE);
onEnterRoom(result)
event, and the value of result
will be greater than 0, indicating the time in milliseconds taken to enter the room.onEnterRoom(result)
event, but the value of result
will be a negative number, indicating the error code for the room entry failure.function onEnterRoom(result) {// For details about `onEnterRoom`, see https://web.sdk.qcloud.com/trtc/electron/doc/en/trtc_electron_sdk/TRTCCallback.html#event:onEnterRoomif (result > 0) {console.log('Enter room succeed');} else {// For room entry error codes, see https://www.tencentcloud.com/document/product/647/35124console.log('Enter room failed');}}rtcCloud.on('onEnterRoom', onEnterRoom);
Was this page helpful?