Join Tencent RTC at NAB Show 2024 in Las Vegas!
Learn more 
Only  $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Only $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Grab It Now 
Join Tencent RTC at NAB Show 2024 in Las Vegas!
Learn more 
Only  $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Only $9.9! Get 50,000 minutes with our Starter Plan, perfect for your MVP project.
Grab It Now 
RTC Engine
Overview
  • Web
    • Demo Quick Run
    • SDK Quick Start
    • 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
      • SEI Message
      • Custom Capturing and Rendering
      • Web Beautification Effects
    • Best Practices
      • Optimize Multi-Person Video Calls
      • Handle Autoplay Restriction
      • Handle Firewall Restriction
    • API List
    • Released Notes
    • Supported Platforms
    • Web FAQs
  • Android
    • 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.Setting Video Quality
      • 10.Rotating Videos
    • 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
    • Release Notes
  • iOS
    • 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.Setting Video Quality
      • 10.Rotating Videos
    • 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
  • macOS
    • 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
    • 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 C++
    • 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.Setting Video Quality
      • 10.Rotating Videos
    • 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
  • Pricing
    • RTC-Engine Packages
    • Billing of On-Cloud Recording
    • Billing of MixTranscoding and Relay to CDN
    • Billing Explanation for Subscription Package Duration
    • Billing of Monitoring Dashboard
    • Free Minutes
    • Pay-As-You-Go
  • Concepts
  • Features
  • Performance Statistics
  • 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

SDK Quick Start

This tutorial mainly introduces how to implement a basic audio and video call.

Install

# Install by npm
npm install trtc-sdk-v5 --save

# Install by yarn
yarn add trtc-sdk-v5
Download manually:
1. Download trtc.js.
2. Copy trtc.js to your project.
3. Import trtc.js by script
<script src="trtc.js"></script>

API Overview

TRTC is the main entry for TRTC SDK, providing APIs such as create trtc instance(TRTC.create), TRTC.getCameraList, TRTC.getMicrophoneList, TRTC.isSupported.
trtc instance, provides the core capability for real-time audio and video calls.
Enter room trtc.enterRoom
Exit room trtc.exitRoom
Turn on/off microphone trtc.startLocalAudio/trtc.stopLocalAudio
Play/stop remote audio trtc.muteRemoteAudio

API Lifecycle





Usage

Create a TRTC Instance

Call the TRTC.create() method to create the trtc instance.
import TRTC from 'trtc-sdk-v5';

const trtc = TRTC.create();

Enter the Room

Call the trtc.enterRoom() method to enter the room. Usually called in the click callback of the Start Call button.

Key parameters:
scene: Set to 'rtc'. Another kind of scene is live, which can be referred to Live Streaming.
sdkAppId: The sdkAppId of the audio and video application you created in TRTC Console.
userId: User ID specified by you.
userSig: User signature, refer to UserSig.
roomId: Room ID specified by you, usually a unique room ID.
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);
}

Turn on/off Microphone

Call trtc.startLocalAudio() to turn on the microphone and publish it to the room.
await trtc.startLocalAudio();
Call trtc.stopLocalAudio to turn off the microphone and unpublish it.
await trtc.stopLocalAudio();

Turn on/off Camera

Call trtc.startLocalVideo() to turn on the camera and publish it to the room.
// To preview the camera image, you need to place an HTMLElement in the DOM,
// which can be a div tag, assuming its id is local-video.
const view = 'local-video';
await trtc.startLocalVideo({ view });
Call trtc.stopLocalVideoto turn off the camera and unpublish it.
await trtc.stopLocalVideo();

Play Remote Audio

By default, the SDK will automatically play remote audio, and you do not need to call any API to play remote audio.
Autoplay Policy Restriction
If the user has not interacted with the page before entering the room, automatic audio playback may fail due to Autoplay Policy Restriction. Refer to Handle Autoplay Restriction.
If you do not want the SDK to automatically play audio, you can try this.
trtc.on(TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event => {
// Call this api when you need to play remote audio.
trtc.muteRemoteAudio(event.userId, false);
// Stop remote audio
trtc.muteRemoteAudio(event.userId, true);
})
// Setting autoReceiveAudio = false to turn off automatic audio playback.
await trtc.enterRoom({ ..., autoReceiveAudio: false });


Play Remote Video

1. Listen for the TRTC.EVENT.REMOTE_VIDEO_AVAILABLE event before entering the room to receive all remote user video publishing events.
2. Call trtc.startRemoteVideo() to play the remote video stream when you receive the event.
trtc.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
// To play the video image, you need to place an HTMLElement in the DOM,
// which can be a div tag, assuming its id is `${userId}_${streamType}`
const view = `${userId}_${streamType}`;
trtc.startRemoteVideo({ userId, streamType, view });
});

Exit the Room

Call trtc.exitRoom() to exit the room and end the audio and video call.
await trtc.exitRoom();
// After the exit is successful, you can call the trtc.destroy method to
// destroy the instance and release related resources in a timely manner
// if you do not need to use the trtc instance later.
// The destroyed trtc instance cannot be used again and a new instance needs to be created.
trtc.destroy();
Handling being kicked out

In addition to actively exiting the room, users may also be kicked out of the room for the following reasons.
1. kick: Two users with the same userId enter the same room, and the user who entered the room first will be kicked out. It is not allowed, which may cause abnormal audio and video calls between the two parties, so you should avoid this happening.
2. banned: A user is kicked out of a TRTC room through the server's RemoveUser | RemoveUserByStrRoomId interface. The user will receive a kicked event, and the reason is banned.
3. room-disband: A TRTC room is dissolved through the server's DismissRoom | DismissRoomByStrRoomId interface. After the room is dissolved, all users in the room will receive a kicked event, and the reason is room-disband.
At this time, the SDK will throw the KICKED_OUT event.
trtc.on(TRTC.EVENT.KICKED_OUT, error => {
console.error(`kicked out, reason:${error.reason}, message:${error.message}`);
});

Contact Us

If you encounter any problems during the implementation process, please feel free to create an issue on GitHub issue, and we will deal with it as soon as possible.