VideoCall
) and audio call (VoiceCall
) are the call modes, and interactive video streaming (Live
) and interactive audio streaming (VoiceChatRoom
) are the live streaming modes.
The live streaming modes allow a maximum of 100,000 concurrent users in each room with smooth mic on/off. Co-anchoring latency is kept below 300 ms and watch latency below 1,000 ms. The live streaming modes are suitable for use cases such as low-latency interactive live streaming, interactive classrooms for up to 100,000 participants, video dating, online education, remote training, and mega-scale conferencing.SimpleDemo
SimpleDemo
.SimpleDemo
successfully, then you know how to install Electron in your project.trtc-electron-sdk
into your projecttrtc-electron-sdk
in your project.npm install trtc-electron-sdk --save
trtc-electron-sdk
instance:import TRTCCloud from 'trtc-electron-sdk';let trtcCloud = new TRTCCloud();
onError
event:// Error events must be listened for and captured, and error messages should be sent to users.let onError = function(err) {console.error(err);}trtcCloud.on('onError',onError);
TRTCParams
Parameter | Field Type | Description | Example |
sdkAppId | Number | 1400000123 | |
userId | String | Can contain only letters (a-z and A-Z), digits (0-9), underscores, and hyphens. We recommend you set it based on your business account system. | test_user_001 |
userSig | String | eJyrVareCeYrSy1SslI... | |
roomId | Number | Numeric room ID. For string-type room ID, use strRoomId in TRTCParams . | 29834 |
import {TRTCParams,TRTCRoleType} from "trtc-electron-sdk/liteav/trtc_define";let param = new TRTCParams();param.sdkAppId = 1400000123;param.roomId = 29834;param.userId = 'test_user_001';param.userSig = 'eJyrVareCeYrSy1SslI...';param.role = TRTCRoleType.TRTCRoleAnchor; // Set the role to "anchor"
userId
cannot be in the same room at the same time as it will cause a conflict.appScene
must be the same on each client. Inconsistent appScene
may cause unexpected problems.setLocalViewFillMode()
to set the display mode of the local video image.TRTCVideoFillMode.TRTCVideoFillMode_Fill
: aspect fill. The image may be scaled up and cropped, but there are no black bars.TRTCVideoFillMode.TRTCVideoFillMode_Fit
: aspect fit. The image may be scaled down to ensure that it’s displayed in its entirety, and there may be black bars.// Sample code: publish the local audio/video streamtrtcCloud.startLocalPreview(view);trtcCloud.startLocalAudio();trtcCloud.setLocalViewFillMode(TRTCVideoFillMode.TRTCVideoFillMode_Fill);// Set local video encoding parameterslet encParam = new TRTCVideoEncParam();encParam.videoResolution = TRTCVideoResolution.TRTCVideoResolution_640_360;encParam.resMode = TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape;encParam.videoFps = 25;encParam.videoBitrate = 600;encParam.enableAdjustRes = true;trtcCloud.setVideoEncoderParam(encParam);
style
: style, which may be smooth or natural. The smooth style features more obvious skin smoothing effect and is suitable for entertainment scenarios.TRTCBeautyStyle.TRTCBeautyStyleSmooth
: smooth, which features more obvious skin smoothing effect and is suitable for showsTRTCBeautyStyle.TRTCBeautyStyleNature
: natural, which retains more facial details and is more naturalbeauty
: strength of the beauty filter. Value range: 0-9. 0
indicates that the filter is disabled. The larger the value, the more obvious the effect.white
: strength of the skin brightening filter. Value range: 0-9. 0
indicates that the filter is disabled. The larger the value, the more obvious the effect.ruddiness
: strength of the rosy skin filter. Value range: 0-9. 0
indicates that the filter is disabled. The larger the value, the more obvious the effect. This parameter is unavailable on Windows currently.// Enable beauty filterstrtcCloud.setBeautyStyle(TRTCBeautyStyle.TRTCBeautyStyleNature, 5, 5, 5);
role
in TRTCParams is set to TRTCRoleType.TRTCRoleAnchor
, the current user is in the role of an anchor.enterRoom( )
, specifying the appScene
parameter, and a room whose ID is the value of the roomId
field in TRTCParams
will be created.TRTCAppScene.TRTCAppSceneLIVE
: the interactive video streaming mode, which features smooth mic on/off and anchor latency below 300 ms. Up to 100,000 users can play the anchor’s video at the same time, with playback latency as low as 1,000 ms. The example in this document uses this mode.TRTCAppScene.TRTCAppSceneVoiceChatRoom
: the interactive audio streaming mode, which features smooth mic on/off and anchor latency below 300 ms. Up to 100,000 users can play the anchor’s audio at the same time, with playback latency as low as 1,000 ms. TRTCAppScene
, see TRTCAppScene.result
is greater than 0, room entry succeeds, and the value indicates the time (ms) room entry takes; if result
is less than 0, room entry fails, and the value is the error code for the failure.let onEnterRoom = function (result) {if (result > 0) {console.log(`onEnterRoom, room entry succeeded and took ${result} seconds`);} else {console.warn(`onEnterRoom: failed to enter room ${result}`);}};trtcCloud.on('onEnterRoom', onEnterRoom);let param = new TRTCParams();param.sdkAppId = 1400000123;param.roomId = 29834;param.userId = 'test_user_001';param.userSig = 'eJyrVareCeYrSy1SslI...';param.role = TRTCRoleType.TRTCRoleAnchor;trtcCloud.enterRoom(param, TRTCAppScene.TRTCAppSceneLIVE);
role
field in TRTCParams to TRTCRoleType.TRTCRoleAudience
to take the role of “audience”.enterRoom()
to enter the room whose ID is the value of the roomId
field in TRTCParams
, specifying appScene
:TRTCAppScene.TRTCAppSceneLIVE
: interactive video streamingTRTCAppScene.TRTCAppSceneVoiceChatRoom
: interactive audio streaminguserId
, call startRemoteView(userId, view) with the anchor’s userId
passed in to play the anchor's video.userId
, find the anchor’s userId
in the onUserVideoAvailable() callback, which you will receive after room entry, and call startRemoteView(userId, view) with the anchor’s userId
passed in to play the anchor’s video.<div id="video-container"></div><script>const videoContainer = document.querySelector('#video-container');const roomId = 29834;// Callback for room entrylet onEnterRoom = function(result) {if (result > 0) {console.log(`onEnterRoom, room entry succeeded and took ${result} seconds`);} else {console.warn(`onEnterRoom: failed to enter room ${result}`);}};// This callback is triggered when the anchor publishes/unpublishes streams from the camera.let onUserVideoAvailable = function(userId, available) {if (available === 1) {let id = `${userId}-${roomId}-${TRTCVideoStreamType.TRTCVideoStreamTypeBig}`;let view = document.getElementById(id);if (!view) {view = document.createElement('div');view.id = id;videoContainer.appendChild(view);}trtcCloud.startRemoteView(userId, view);trtcCloud.setRemoteViewFillMode(userId, TRTCVideoFillMode.TRTCVideoFillMode_Fill);} else {let id = `${userId}-${roomId}-${TRTCVideoStreamType.TRTCVideoStreamTypeBig}`;let view = document.getElementById(id);if (view) {videoContainer.removeChild(view);}}};trtcCloud.on('onEnterRoom', onEnterRoom);trtcCloud.on('onUserVideoAvailable', onUserVideoAvailable);let param = new TRTCParams();param.sdkAppId = 1400000123;param.roomId = roomId;param.userId = 'test_user_001';param.userSig = 'eJyrVareCeYrSy1SslI...';param.role = TRTCRoleType.TRTCRoleAudience; // Set the role to "audience"trtcCloud.enterRoom(param, TRTCAppScene.TRTCAppSceneLIVE);</script>
TRTCRoleType.TRTCRoleAnchor
).// Sample code: start co-anchoringtrtcCloud.switchRole(TRTCRoleType.TRTCRoleAnchor);trtcCloud.startLocalAudio();trtcCloud.startLocalPreview(frontCamera, view);// Sample code: end co-anchoringtrtcCloud.switchRole(TRTCRoleType.TRTCRoleAudience);trtcCloud.stopLocalAudio();trtcCloud.stopLocalPreview()
roomId
and userId
of anchor B in the format of {"roomId": 978,"userId": "userB"}
to the API.connectOtherRoom()
to call anchor B in room “002” successfully, all users in room "001" will receive the onUserVideoAvailable(B, true)
and onUserAudioAvailable(B, true)
callbacks, and all users in room "002" will receive the onUserVideoAvailable(A, true)
and onUserAudioAvailable(A, true)
callbacks.// Sample code: cross-room competitionlet onConnectOtherRoom = function(userId, errCode, errMsg) {if(errCode === 0) {console.log(`Connected to the room of anchor ${userId}`);} else {console.warn(`Failed to connect to the anchor's room: ${errMsg}`);}};const paramJson = '{"roomId": "978","userId": "userB"}';trtcCloud.connectOtherRoom(paramJson);trtcCloud.on('onConnectOtherRoom', onConnectOtherRoom);
// Please wait for the `onExitRoom` callback after calling the room exit API.let onExitRoom = function (reason) {console.log(`onExitRoom, reason: ${reason}`);};trtcCloud.exitRoom();trtcCloud.on('onExitRoom', onExitRoom);
onExitRoom
callback to start other SDKs; otherwise the device busy error may occur.
Was this page helpful?