tencent cloud

实时音视频

动态与公告
产品动态
产品近期公告
关于 TRTC Live 正式上线的公告
关于TRTC Conference 正式版上线的公告
Conference 商业化版本即将推出
关于多人音视频 Conference 开启内测公告
关于音视频通话 Call 正式版上线的公告
关于腾讯云音视频终端 SDK 播放升级及新增授权校验的公告
关于 TRTC 应用订阅套餐服务上线的相关说明
产品简介
产品概述
基本概念
产品功能
产品优势
应用场景
性能数据
购买指南
计费概述
免费时长说明
月订阅
现收现付
TRTC 逾期与暂停政策
常见问题解答
退款说明
新手指引
Demo 体验
视频通话 SDK
组件介绍
开通服务
跑通 Demo
快速接入
离线唤醒
会话聊天
云端录制
AI 降噪
界面定制
Chat 集成通话能力
更多特性
无 UI 集成
服务端 API
客户端 API
解决方案
错误码表
发布日志
常见问题
视频会议 SDK
组件介绍(TUIRoomKit)
开通服务(TUIRoomKit)
跑通 Demo(TUIRoomKit)
快速接入(TUIRoomKit)
屏幕共享(TUIRoomKit)
预定会议(TUIRoomKit)
会中呼叫(TUIRoomKit)
界面定制(TUIRoomKit)
虚拟背景(TUIRoomKit)
会议控制(TUIRoomKit)
云端录制(TUIRoomKit)
AI 降噪(TUIRoomKit)
会中聊天(TUIRoomKit)
机器人推流(TUIRoomKit)
更多特性(TUIRoomKit)
客户端 API(TUIRoomKit)
服务端 API(TUIRoomKit)
常见问题(TUIRoomKit)
错误码 (TUIRoomKit)
SDK更新日志(TUIRoomKit)
直播与语聊 SDK
Live 视频直播计费说明
组件介绍
开通服务(TUILiveKit)
跑通 Demo
无 UI 集成
UI 自定义
直播监播
视频直播
语聊房
高级功能
客户端 API
服务端 API
错误码
发布日志
常见问题
RTC Engine
开通服务
SDK 下载
API-Example
接入指引
API-参考手册
高级功能
AI 集成
概述
MCP 配置
Skills 配置
集成指南
常见问题
RTC RESTFUL API
History
Introduction
API Category
Room Management APIs
Stream mixing and relay APIs
On-cloud recording APIs
Data Monitoring APIs
Pull stream Relay Related interface
Web Record APIs
AI Service APIs
Cloud Slicing APIs
Cloud Moderation APIs
Making API Requests
Call Quality Monitoring APIs
Usage Statistics APIs
Data Types
Appendix
Error Codes
控制台指南
应用管理
套餐包管理
用量统计
监控仪表盘
开发辅助
解决方案
实时合唱
常见问题
迁移指南
计费相关
功能相关
UserSig 相关
应对防火墙限制相关
缩减安装包体积相关
Andriod 与 iOS 相关
Web 端相关
Flutter 相关
Electron 相关
TRTCCalling Web 相关
音视频质量相关
其他问题
旧版文档
RTC RoomEngine SDK(旧)
集成 TUIRoom (Web)
集成 TUIRoom (Android)
集成 TUIRoom (iOS)
集成 TUIRoom (Flutter)
集成 TUIRoom (Electron)
TUIRoom API 查询
实现云端录制与回放(旧)
监控仪表盘计费(旧)
协议与策略
安全合规认证
安全白皮书
信息安全说明
服务等级协议
苹果隐私策略:PrivacyInfo.xcprivacy
TRTC 政策
隐私协议
数据处理和安全协议
词汇表
文档实时音视频常见问题迁移指南Agora 到 Tencent RTC 迁移指南

Agora 到 Tencent RTC 迁移指南

PDF
聚焦模式
字号
最后更新时间: 2025-07-09 16:16:24
欢迎阅读 Tencent RTC Engine SDK 迁移指南。本文旨在协助开发者将基于 Agora Video SDK 的实施方案高效迁移到 Tencent RTC Engine SDK。我们将通过提供详细的 Tencent RTC Engine 应用部署指南, 以及基础 RTC 功能/ API 的代码对比, 帮助您实现快速且无缝的迁移。
如果您计划为新项目接入 Tencent RTC Engine SDK, 我们建议您从 跑通 Demo集成指南 开始学习;如果您想了解 Tencent RTC Engine 的更多信息, 我们建议您访问 产品概述

创建 Tencent RTC Engine 应用程序

要访问 Tencent RTC Engine 服务,需要一个 Tencent RTC Engine 应用程序及其凭据。您可以按照以下步骤在 Tencent RTC 控制台中创建新的 Tencent RTC Engine 应用程序:
1. 注册或登录您的 Tencent RTC 账号,并登录到 Tencent RTC 控制台
2. 点击 Create Application
3. 在创建弹窗中,输入您的应用程序名称,选择 RTC Engine,点击 Create



应用程序创建后,可在 Basic Information 获取以下凭证:
SDKAppID:这是自动生成的 ID,用于唯一标识您的 Tencent RTC 应用程序。
SDKSecretKey:用于生成安全签名的关键参数之一 UserSig,用于保障 Tencent RTC 服务的安全访问。该凭证及 UserSig 计算方式请参见 UserSig




安装 Tencent RTC Engine SDK

Tencent RTC Engine SDK 已支持多种主流平台,提供全面的跨平台兼容性,涵盖 Web、桌面、移动端。您可以通过以下方式安装适合您当前实现的 Tencent RTC Engine SDK:
Web
Flutter
React Native
使用 npm 安装:
1. 在你的 Web 项目中安装 trtc-sdk-v5
npm install trtc-sdk-v5 --save
2. 在脚本中导入模块:
import TRTC from 'trtc-sdk-v5'
使用 HTML 安装 <script>
GitHub 下载 SDK 文件trtc.js,并在您的网页中添加以下代码:
<script src="/your_path/trtc.js"></script>
在 Flutter 项目中安装 tencent_rtc_sdk
flutter pub add tencent_rtc_sdk
1. 在 React Native 项目中安装 trtc-react-native
npm install trtc-react-native --save
# or
yarn add trtc-react-native
2. 在脚本中导入模块:
import TRTCCloud, { TRTCParams, TRTCCloudDef } from 'trtc-react-native'

术语比较

本节比较了 Tencent RTC Engine 和 Agora 针对关键 RTC 概念使用的术语。要了解更多关于 Tencent RTC Engine 术语表的信息,请访问 基本概念
Tencent RTC Engine 术语
Agora 术语
说明
房间
频道
将 RTC 参与者联系在一起的团体。
主播
主持人
拥有推流权限的房间用户类型,可以向服务端推送音视频流。
主播也可以订阅播放其他主播的音视频流。
观众
观众
只能订阅其他主播/主持人的房间用户类型

功能和 API 比较

本节列出了一些代码示例,比较了 Agora Video SDK 和 Tencent RTC Engine SDK 中常见 RTC 功能的实现:

初始化 Tencent RTC /声网客户端实例

Web
Flutter
React Native
Agora
// Create an Agora Web client
const agoraWebClient = AgoraRTC.createClient({
mode: "rtc",
codec: "vp8"
});
Tencent RTC
// Create a TRTC Web client
const trtcWebClient = TRTC.create();
Agora
RtcEngine agoraFlutterEngine = createAgoraRtcEngine();

await agoraFlutterEngine.initialize(
const RtcEngineContext(appId: "<app id>")
);
Tencent RTC
// Create a TRTC instance
TRTCCloud trtcFlutterEngine = await TRTCCloud.sharedInstance();
Agora
const agoraRNEngine = createAgoraRtcEngine();

await agoraRNEngine.initialize({ appId: "<app id>" });
Tencent RTC
// Create a TRTC instance
const trtcRNEngine = TRTCCloud.sharedInstance();

进入 Tencent RTC 房间/声网频道

Web
Flutter
React Native
Agora
await agoraWebClient.join(appId, channelName, token, userId);
Tencent RTC
try {
await trtcWebClient.enterRoom({
// Your application's SDKAppID
sdkAppId: 12345678,
userId: "<custom user id>",
// User signature, generated from your appliction's SDKSecretKey
userSig: "<user signature>",
roomId: 1234
});
console.log('Entered the room successfully');
} catch (error) {
console.error('Failed to enter the room ' + error);
}
Agora
await agoraFlutterEngine.joinChannel(
token: "<your token>",
channelId: "<channel id>",
// user id
uid: 0
options: const ChannelMediaOptions(
autoSubscribeVideo: true,
autoSubscribeAudio: true,
publishCameraTrack: true,
publishMicrophoneTrack: true
)
);
Tencent RTC
trtcFlutterEngine.enterRoom(
TRTCParams(
// Your application's SDKAppID
sdkAppId: 12345678,
userId: "<custom user id>",
// User signature, generated from your appliction's SDKSecretKey
userSig: "<user signature>",
roomId: 1234,
// Enter the room as Anchor
role: TRTCRoleType.anchor,
),
TRTCAppScene.live
);

print("Enter the room successfully");
Agora
const token = "<your token>";
const channelName = "<your channel id>";
const localUserId = 0;

agoraRNEngine.joinChannel(
token,
channelName,
localUserId,
{
autoSubscribeVideo: true,
autoSubscribeAudio: true,
publishCameraTrack: true,
publishMicrophoneTrack: true
}
);
Tencent RTC
trtcRNEngine.enterRoom(
new TRTCParams({
// Your application's SDKAppID
sdkAppId: 12345678,
userId: "<custom user id>",
// User signature, generated from your appliction's SDKSecretKey
userSig: "<user signature>",
roomId: 1234
}),
// Enter the room in audio and video call scenarios
TRTCCloudDef.TRTC_APP_SCENE_VIDEOCALL
);

设置事件监听器

Web
Flutter
React Native
Agora
agoraWebClient.on("user-joined", async (user, mediaType) => {
console.log("User joins the channel");
});
Tencent RTC
trtcWebClient.on(TRTC.EVENT.REMOTE_USER_ENTER, event => {
const userId = event.userId;
console.log(User ${userId} enters the room);
});
Agora
agoraFlutterEngine.registerEventHandler(
RTCEngineEventHandler(
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {
print("Remote user $remoteUid joined");
},
)
);
Tencent RTC
// Define a TRTCCloudListener with relative events
TRTCCloudListener listener = TRTCCloudListener(
onEnterRoom: (result) {
if(result > 0) {
print("Enter room success.");
}
},
onRemoteUserEnterRoom: (userId) {
print("Remote user $userId enters the room.")
},
onError: (errCode, errMsg) {
print("Error $errCode: $errMsg");
}
);

// Register the event listener with TRTC engine
trtcFlutterEngine.registerListener(listener);
Agora
agoraRNEngine.registerEventHandler({
onUserJoined: (connection, uid) {
console.log(`Remote user ${uid} joins the room`);
}
});
Tencent RTC
const onRtcListener = useCallback((type:TRTCCloudListener, params:any) => {
if (type === TRTCCloudListener.onEnterRoom) {
if (params.result > 0) {
console.log("Enter room success.");
}
} else if (type === TRTCCloudListener.onRemoteUserEnterRoom) {
console.log(`Remote user ${params.userId} enters the room.`);
} else if (type === TRTCCloudListener.onError) {
console.error(`Error ${params.errCode}: ${params.errMsg}.`);
}
});

trtcRNEngine.registerListener(onRtcListener);

收集, 发布或取消发布本地 Tencent RTC 音视频流/声网音视频轨道

Web
Flutter
React Native
Assume the container HTML element for local audio and video is:
<div class="local-video-container" width="1920" height="1080"></div>
Agora
// Capture both microphone and camera tracks
const [microphoneTrack, cameraTrack] = await agoraWebClient.createMicrophoneAndCameraTracks();

// Render
const localMediaContainer = document.getElementById('local-video-container');
cameraTrack.play(localMediaContainer);

// Publish microphone and camera tracks
await agoraWebClient.publish([microphoneTrack, cameraTrack]);

// Unpublish tracks
await agoraWebClient.unpublish();
Tencent RTC
const view = document.getElementById('local-video-container');

// Local video stream
// Get the list of available cameras
const cameraList = await TRTC.getCameraList();

if(cameraList[0]) {
// Start collecting video
// Publish the first (available) camera's video stream to the current room
await trtcWebClient.startLocalVideo({
view,
options: { cameraId: cameraList[0].deviceId }
});
}

// Unpublish and stop collecting video
await trtcWebClient.stopLocalVideo();

// Local audio stream
// Get the list of available microphones.
const microphoneList = await TRTC.getMicrophoneList();

if(microphoneList[0]) {
// Start collecting audio
// Publish the first (available) microphone's audio stream to the current room
await trtcWebClient.startLocalAudio({
options: { microphoneId: microphoneList[0].deviceId }
});
}

// Unpublish and stop collecting audio
await trtc.stopLocalAudio();
Agora
// Local video track
// Display the local video by enabling the video module and starting local video preview
await agoraFlutterEngine.enableVideo();
await agoraFlutterEngine.startPreview();

// Render the local video via AgoraVideoView widget
Widget _localVideo() {
return AgoraVideoView(
controller: VideoViewController(
rtcEngine: agoraFlutterEngine,
canvas: const VideoCanvas(
// Specify the local user id
uid: 0,
// Set the video rendering mode
renderMode: RenderModeType.renderModeHidden
)
)
);
}

// Disable the video module and stop local video preview
agoraFlutterEngine.disableVideo();
agoraFlutterEngine.stopPreview();

// Local audio track is enabled by default in Agora
Tencent RTC
// Local video stream
import 'package:tencent_rtc_sdk/trtc_cloud_video_view.dart';

// Before enabling the camera preview, you can set the local video rendering parameters
trtcFlutterEngine.setLocalRenderParams(
TRTCRenderParams(
fillMode: TRTCVideoFillMode.fill,
mirrorType: TRTCVideoMirrorType.auto,
rotation: TRTCVideoRotation.rotation0
)
);

// Render the local video via TRTCCloudVideoView widget
Widget _localVideo() {
return TRTCCloudVideoView(
key: ValueKey(0),
onViewCreated: (viewId) {
// Set to 'false' if using rear camera
bool useFrontCamera = true;
// Start local video preview using front camera
trtcFlutterEngine.startLocalPreview(useFrontCamera, viewId);
// Stop local video preview
trtcFlutterEngine.stopLocalPreview();
}
)
}

// Local audio stream
// Enable the audio module and start publishing local audio
trtcFlutterEngine.startLocalAudio(TRTCAudioQuality.speech);
// Disable the audio module and stop publishing local audio
trtcFlutterEngine.stopLocalAudio();
Agora
<RtcSurfaceView
canvas={{ uid: 0 }}
style={ width: '90%', height: 200 }
/>

<!-- Local audio track is enabled by default in Agora -->
Tencent RTC
import { TXVideoView } from 'trtc-react-native';
<TXVideoView.LocalView
style={{ width: 1080, height: 1080 }}
/>
// Enable the audio module and start publishing local audio
trtcRNEngine.startLocalAudio();
// Disable the audio module and stop publishing local audio
trtcRNEngine.stopLocalAudio();

订阅并播放远端 Tencent RTC 音视频流/声网音视频轨道

Web
Flutter
React Native
Assume the container HTML element for remote audio and video is:
<div class="remote-video-container" width="1920" height="1080"></div>
Agora
agoraWebClient.on("user-published", async (user, mediaType) => {
// Initiate a subscription
await client.subscribe(user, mediaType);

// Subscribe to an audio track
if (mediaType === "audio") {
const audioTrack = user.audioTrack;
// Automatically play audio
audioTrack.play();
} else {
const videoTrack = user.videoTrack;
// Automatic video playback
videoTrack.play('remote-video-container');
}
});
Tencent RTC
// Video (listen for TRTC.EVENT.REMOTE_VIDEO_AVAILABLE)
trtcWebClient.on(TRTC.EVENT.REMOTE_VIDEO_AVAILABLE, ({ userId, streamType }) => {
// To play the video image, you need to place an HTMLElement in the DOM
// Assume this is a <div> element and has the id of `${userId}_${streamType}`
const view = `${userId}_${streamType}`;

// Start rendering remote video
trtcWebClient.startRemoteVideo({ userId, streamType, view });
});

// Audio (listen for TRTC.EVENT.REMOTE_AUDIO_AVAILABLE)
trtcWebClient.on(TRTC.EVENT.REMOTE_AUDIO_AVAILABLE, event => {
// Start playing remote audio
trtcWebClient.muteRemoteAudio(event.userId, false);
});
Agora
// Remote video track
// Render the remote video of a joined user, also via AgoraVideoView widget
Widget _remoteVideo(remoteuid, channelid) {
return AgoraVideoView(
controller: VideoViewController.remote(
rtcEngine: agoraFlutterEngine,
canvas: const VideoCanvas(uid: remoteuid),
connection: const RtcConnection(channelId: channelid)
)
);
}

// Local audio track is enabled by default in Agora
Tencent RTC
// Remote video stream
import 'package:tencent_rtc_sdk/trtc_cloud_video_view.dart';

// You can also set the remote video rendering parameters before rendering
trtcFlutterEngine.setRemoteRenderParams(
TRTCRenderParams(
fillMode: TRTCVideoFillMode.fill,
mirrorType: TRTCVideoMirrorType.auto,
rotation: TRTCVideoRotation.rotation0
)
);

// Render the remote video, also via TRTCCloudVideoView widget
Widget _remoteVideo(remoteuid) {
return TRTCCloudVideoView(
key: ValueKey(0),
onViewCreated: (viewId) {
// Start remote video view
trtcFlutterEngine.startRemoteView(
remoteuid,
TRTCVideoStreamType.big,
viewId
);
// Stop remote video view
trtcFlutterEngine.stopLocalPreview(
remoteuid,
TRTCVideoStreamType.big,
);
}
)
}

// Remote audio stream
// Mute/unmute a remote user's audio stream
bool isMuted = true;
trtcFlutterEngine.muteRemoteAudio(remoteuid, isMuted);
Agora
<React.Fragment key={remoteUid}>
<RtcSurfaceView
canvas={{ uid: remoteUid }}
style={ width: '90%', height: 200 }
/>
</React.Fragment>
// Mute/unmute a remote user's audio stream
let isMuted = true;
trtcRNEngine.muteRemoteAudioStream(remoteuid, isMuted);
Tencent RTC
import { TXVideoView } from 'trtc-react-native';

// Stop remote video playback
trtcRNEngine.stopRemoteView(remoteuid, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG);

// Mute/unmute remote audio playback
let isMuted = true;
trtcRNEngine.muteRemoteAudio(remoteuid, isMuted);
<TXVideoView.RemoteView
userId={remoteUserId}
streamType={TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG}
style={{ width: 1080, height: 1080 }}
/>

退出 Tencent RTC 房间/声网频道

Web
Flutter
React Native
Agora
await agoraWebClient.leave();
Tencent RTC
await trtcWebClient.exitRoom();

// Destroy the client instance and release releated resource if needed
trtcWebClient.destroy();
Agora
await agoraFlutterEngine.leaveChannel();
Tencent RTC
await trtcFlutterEngine.exitRoom();

// Destroy the client instance and release releated resource if needed
trtcFlutterEngine.destroySharedInstance();
Agora
agoraRNEngine.leaveChannel();
Tencent RTC
trtcRNEngine.exitRoom();

// Destroy the client instance and release releated resource if needed
trtcRNEngine.destroySharedInstance();

结论

以上章节列出了一部分 Agora 和 Tencent RTC Engine 功能的迁移方案, 关于更多对于 Tencent RTC Engine 功能与文档的细节, 请查看 产品功能
Tencent RTC 致力于帮助开发者快速搭建低成本、低延时、高品质的音视频互动解决方案. 如果您需要开发协助或其他关于 Tencent RTC Engine 集成的帮助, 欢迎 联系我们 或加入我们的 DiscordTelegram 社群。


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈