Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions OCDemo/README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
# TRTC MacOS Demo (Objective-C)

这个开源示例Demo主要演示如何基于 [TRTC 实时音视频 SDK](https://cloud.tencent.com/document/product/647/32689),快速实现一些音视频场景的基本功能。
This open source example Demo mainly demonstrates how to quickly implement some basic functions of audio and video scenarios based on [TRTC Real-time Audio and Video SDK](https://cloud.tencent.com/document/product/647/32689).

在这个示例项目中包含了以下场景:
The following scenarios are included in this sample project:

- 视频通话
- 视频互动直播
- video call
- Video interactive live broadcast

## 环境要求
- Xcode 10.2及以上版本
## Environmental requirements
- Xcode 10.2 and above

## 前提条件
您已 [注册腾讯云](https://cloud.tencent.com/document/product/378/17985) 账号,并完成 [实名认证](https://cloud.tencent.com/document/product/378/3629)
## Prerequisites
You have [registered Tencent Cloud](https://cloud.tencent.com/document/product/378/17985) account and completed [real-name authentication](https://cloud.tencent.com/document/product/378 /3629).

## 操作步骤
## Steps

### 步骤1:创建新的应用
1. 登录实时音视频控制台,选择【开发辅助】>【[快速跑通Demo](https://console.cloud.tencent.com/trtc/quickstart)】。
2. 单击【立即开始】,输入应用名称,例如`TestTRTC`,单击【创建应用】。
3. 单击【我已下载】,会看到页面上展示了您的 SDKAppID 和密钥。
### Step 1: Create a new application
1. Log in to the real-time audio and video console, select [Development Assistance] > [Quick Run Demo] (https://console.cloud.tencent.com/trtc/quickstart)].
2. Click [Start Now], enter the application name, such as `TestTRTC`, and click [Create Application].
3. Click [I have downloaded] and you will see your SDKAppID and key displayed on the page.

### 步骤2:配置 Demo 工程中的AppID和密钥
1. 打开工程中的 [GenerateTestUserSig.h](TRTCDemo/TRTC/GenerateTestUserSig.h) 文件
2. 配置`GenerateTestUserSig.h`文件中的相关参数:
<ul><li>SDKAPPID:默认为0,请设置为实际的 SDKAppID</li>
<li>SDKSECRETKEY:默认为空字符串,请设置为实际的密钥信息。</li></ul>
<img src="https://main.qcloudimg.com/raw/15d986c5f4bc340e555630a070b90d63.png">
3. 返回实时音视频控制台,单击【粘贴完成,下一步】。
4. 单击【关闭指引,进入控制台管理应用】。
### Step 2: Configure the AppID and key in the Demo project
1. Open the [GenerateTestUserSig.h](TRTCDemo/TRTC/GenerateTestUserSig.h) file in the project
2. Configure the relevant parameters in the `GenerateTestUserSig.h` file:
<ul><li>SDKAPPID: The default is 0, please set it to the actual SDKAppID. </li>
<li>SDKSECRETKEY: The default is an empty string, please set it to the actual key information. </li></ul>
<img src="https://main.qcloudimg.com/raw/15d986c5f4bc340e555630a070b90d63.png">
3. Return to the real-time audio and video console and click [Paste Complete, Next].
4. Click [Close the guide and enter the console management application].

>!本文提到的生成 UserSig 的方案是在客户端代码中配置 SDKSECRETKEY,该方法中 SDKSECRETKEY 很容易被反编译逆向破解,一旦您的密钥泄露,攻击者就可以盗用您的腾讯云流量,因此**该方法仅适合本地跑通 Demo 和功能调试**。
>正确的 UserSig 签发方式是将 UserSig 的计算代码集成到您的服务端,并提供面向 App 的接口,在需要 UserSig 时由您的 App 向业务服务器发起请求获取动态 UserSig。更多详情请参见 [服务端生成 UserSig](https://cloud.tencent.com/document/product/647/17275#Server)
>! The solution to generate UserSig mentioned in this article is to configure SDKSECRETKEY in the client code. In this method, SDKSECRETKEY can easily be decompiled and reverse cracked. Once your key is leaked, the attacker can steal your Tencent Cloud traffic. Therefore **This method is only suitable for local run-through Demo and functional debugging**.
>The correct way to issue UserSig is to integrate the UserSig calculation code into your server and provide an App-oriented interface. When UserSig is needed, your App initiates a request to the business server to obtain the dynamic UserSig. For more details, please see [Server-side generation of UserSig](https://cloud.tencent.com/document/product/647/17275#Server).

## 5. 编译运行
在终端窗口中 cd Podfile 所在目录执行以下命令安装 TRTC SDK
## 5. Compile and run
In the terminal window, cd to the directory where the Podfile is located and execute the following command to install TRTC SDK
```
pod install
```
或使用以下命令更新本地库版本:
Or use the following command to update the local library version:
```
pod update
```
使用 XCode 9.0 以上的版本) 打开源码目录下的 TRTCDemo.xcworkspace 工程,编译并运行 Demo 工程即可。
Use XCode (version 9.0 or above) to open the TRTCDemo.xcworkspace project in the source directory, compile and run the Demo project.
62 changes: 31 additions & 31 deletions OCDemo/TRTCDemo/TRTC/GenerateTestUserSig.h
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
/*
* Module: GenerateTestUserSig
* Module: GenerateTestUserSig
*
* Function: 用于生成测试用的 UserSigUserSig 是腾讯云为其云服务设计的一种安全保护签名。
* 其计算方法是对 SDKAppID、UserID 和 EXPIRETIME 进行加密,加密算法为 HMAC-SHA256
* Function: used to generate UserSig for testing. UserSig is a security protection signature designed by Tencent Cloud for its cloud services.
* The calculation method is to encrypt SDKAppID, UserID and EXPIRETIME, and the encryption algorithm is HMAC-SHA256.
*
* Attention: 请不要将如下代码发布到您的线上正式版本的 App 中,原因如下:
* Attention: Please do not publish the following code into your online official version of the App for the following reasons:
*
* 本文件中的代码虽然能够正确计算出 UserSig,但仅适合快速调通 SDK 的基本功能,不适合线上产品,
* 这是因为客户端代码中的 SDKSECRETKEY 很容易被反编译逆向破解,尤其是 Web 端的代码被破解的难度几乎为零。
* 一旦您的密钥泄露,攻击者就可以计算出正确的 UserSig 来盗用您的腾讯云流量。
* Although the code in this file can correctly calculate UserSig, it is only suitable for quickly adjusting the basic functions of the SDK and is not suitable for online products.
* This is because the SDKSECRETKEY in the client code is easily decompiled and reverse-engineered, especially the web-side code, which is almost zero difficulty in cracking.
* Once your key is leaked, an attacker can calculate the correct UserSig to steal your Tencent Cloud traffic.
*
* 正确的做法是将 UserSig 的计算代码和加密密钥放在您的业务服务器上,然后由 App 按需向您的服务器获取实时算出的 UserSig
* 由于破解服务器的成本要高于破解客户端 App,所以服务器计算的方案能够更好地保护您的加密密钥。
* The correct approach is to put the UserSig calculation code and encryption key on your business server, and then have the App obtain the real-time calculated UserSig from your server on demand.
* Since it is more expensive to crack a server than a client app, a server-computed approach better protects your encryption keys.
*
* Referencehttps://cloud.tencent.com/document/product/647/17275#Server
* Reference: https://cloud.tencent.com/document/product/647/17275#Server
*/

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
* 腾讯云 SDKAppId,需要替换为您自己账号下的 SDKAppId
* Tencent Cloud SDKAppId needs to be replaced with the SDKAppId under your own account.
*
* 进入腾讯云实时音视频[控制台](https://console.cloud.tencent.com/rav ) 创建应用,即可看到 SDKAppId
* 它是腾讯云用于区分客户的唯一标识。
* Enter Tencent Cloud Real-time Audio and Video [Console] (https://console.cloud.tencent.com/rav) to create an application and you can see the SDKAppId.
* It is the unique identifier used by Tencent Cloud to distinguish customers.
*/
static const int _SDKAppID = 0;

/**
* 签名过期时间,建议不要设置的过短
* It is recommended not to set the signature expiration time too short.
*
* 时间单位:秒
* 默认时间:7 x 24 x 60 x 60 = 604800 = 7
* Time unit: seconds
*Default time: 7 x 24 x 60 x 60 = 604800 = 7 days
*/
static const int _EXPIRETIME = 604800;

/**
* 计算签名用的加密密钥,获取步骤如下:
* The encryption key used to calculate the signature, the steps to obtain are as follows:
*
* step1. 进入腾讯云实时音视频[控制台](https://console.cloud.tencent.com/rav ),如果还没有应用就创建一个,
* step2. 单击您的应用,并进一步找到“快速上手”部分。
* step3. 点击“查看密钥”按钮,就可以看到计算 UserSig 使用的加密的密钥了,请将其拷贝并复制到如下的变量中
* step1. Enter Tencent Cloud Real-time Audio and Video [Console] (https://console.cloud.tencent.com/rav), if there is no application yet, create one.
* step2. Click on your app and further find the "Get Started" section.
* step3. Click the "View Key" button to see the encrypted key used to calculate UserSig. Please copy it to the following variable
*
* 注意:该方案仅适用于调试Demo,正式上线前请将 UserSig 计算代码和密钥迁移到您的后台服务器上,以避免加密密钥泄露导致的流量盗用。
* 文档:https://cloud.tencent.com/document/product/647/17275#Server
* Note: This solution is only suitable for debugging Demo. Please migrate the UserSig calculation code and key to your backend server before official launch to avoid traffic theft caused by encryption key leakage.
* Document: https://cloud.tencent.com/document/product/647/17275#Server
*/
static NSString * const _SDKSECRETKEY = @"";


@interface GenerateTestUserSig : NSObject
/**
* 计算 UserSig 签名
* Calculate UserSig signature
*
* 函数内部使用 HMAC-SHA256 非对称加密算法,对 SDKAPPIDuserId EXPIRETIME 进行加密。
* The HMAC-SHA256 asymmetric encryption algorithm is used internally to encrypt SDKAPPID, userId and EXPIRETIME.
*
* @note: 请不要将如下代码发布到您的线上正式版本的 App 中,原因如下:
* @note: Please do not publish the following code into your online official version of the App for the following reasons:
*
* 本文件中的代码虽然能够正确计算出 UserSig,但仅适合快速调通 SDK 的基本功能,不适合线上产品,
* 这是因为客户端代码中的 SDKSECRETKEY 很容易被反编译逆向破解,尤其是 Web 端的代码被破解的难度几乎为零。
* 一旦您的密钥泄露,攻击者就可以计算出正确的 UserSig 来盗用您的腾讯云流量。
* Although the code in this file can correctly calculate UserSig, it is only suitable for quickly adjusting the basic functions of the SDK and is not suitable for online products.
* This is because the SDKSECRETKEY in the client code is easily decompiled and reverse-engineered, especially the web-side code, which is almost zero difficulty in cracking.
* Once your key is compromised, an attacker can calculate the correct UserSig to steal your Tencent Cloud traffic.
*
* 正确的做法是将 UserSig 的计算代码和加密密钥放在您的业务服务器上,然后由 App 按需向您的服务器获取实时算出的 UserSig
* 由于破解服务器的成本要高于破解客户端 App,所以服务器计算的方案能够更好地保护您的加密密钥。
* The correct approach is to put the UserSig calculation code and encryption key on your business server, and then have the App obtain the real-time calculated UserSig from your server on demand.
* Since it is more expensive to crack a server than a client app, a server-computed approach better protects your encryption keys.
*
* 文档:https://cloud.tencent.com/document/product/647/17275#Server
* Document: https://cloud.tencent.com/document/product/647/17275#Server
*/
+ (NSString *)genTestUserSig:(NSString *)identifier;
@end
Expand Down
4 changes: 2 additions & 2 deletions OCDemo/TRTCDemo/TRTC/Manager/TRTCUserManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ NS_ASSUME_NONNULL_BEGIN

- (void)setRemoteNetQuality:(NSArray<TRTCQualityInfo *> *)remoteQuality;

/// 临时停止掉界面上不出现的视频
/// Temporarily stop videos that do not appear on the interface
- (void)hideRenderViewExceptUser:(NSString *)userId;

/// 恢复临时停止的视频
/// Resume temporarily stopped video
- (void)recoverAllRenderViews;

@end
Expand Down
8 changes: 4 additions & 4 deletions OCDemo/TRTCDemo/TRTC/RenderView/TXRenderView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@

@interface TXRenderView ()

// 视频页面
// Video page
@property (weak) IBOutlet NSView *contentView;

// 左下角的用户信息
// User information in the lower left corner
@property (weak) IBOutlet NSView *userInfoView;
@property (weak) IBOutlet NSTextField *nameLabel;
@property (weak) IBOutlet NSImageView *audioStateView;
@property (weak) IBOutlet NSLevelIndicator *volumeView;
@property (weak) IBOutlet NSImageView *signalView;

// 右上角的功能栏
// Function bar in the upper right corner
@property (weak) IBOutlet NSStackView *functionBar;
@property (weak) IBOutlet NSButton *rotateButton;
@property (weak) IBOutlet NSButton *streamButton;
@property (weak) IBOutlet NSButton *muteVideoButton;
@property (weak) IBOutlet NSButton *muteAudioButton;
@property (weak) IBOutlet NSButton *toggleFillModeButton;

// 无画面时显示的用户信息
// User information displayed when there is no screen
@property (weak) IBOutlet NSImageView *avatarView;

@property (nonatomic) TRTCVideoRotation rotation;
Expand Down
24 changes: 12 additions & 12 deletions OCDemo/TRTCDemo/TRTC/TRTCMainWindowController.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Module: TRTCMainWindowController
* Module: TRTCMainWindowController
*
* Function: 使用TRTC SDK完成 1v1 1vn 的视频通话功能
* Function: Use TRTC SDK to complete 1v1 and 1vn video call functions
*
* 1. 支持九宫格平铺和前后叠加两种不同的视频画面布局方式,该部分由 _layoutInBounds 方法来计算每个视频画面的位置排布和大小尺寸
* 1. Supports two different video screen layout methods: nine-square tiles and front-to-back overlay. This part uses the _layoutInBounds method to calculate the position, arrangement and size of each video screen.
*
* 2. 支持对视频通话的分辨率、帧率和流畅模式进行调整,该部分由 TRTCSettingViewController 来实现
* 2. Supports adjusting the resolution, frame rate and smooth mode of video calls. This part is implemented by TRTCSettingViewController
*
* 3. 创建或者加入某一个通话房间,需要先指定 roomid userid,这部分由 TRTCNewWindowController 来实现
* 3. To create or join a call room, you need to specify roomid and userid first. This part is implemented by TRTCNewWindowController
*/

#import <Cocoa/Cocoa.h>
Expand All @@ -17,29 +17,29 @@ NS_ASSUME_NONNULL_BEGIN

@interface TRTCMainWindowController : NSWindowController

/// 录屏预览窗口
/// Screen recording preview window
@property (strong) IBOutlet NSWindow *screenShareWindow;

/// 跨房通话窗口
/// Inter-room call window
@property (strong) IBOutlet NSWindow *connectRoomWindow;
@property (strong) NSString *connectRoomId;
@property (strong) NSString *connectUserId;
@property (assign, nonatomic, readonly) BOOL canConnectRoom;
@property (assign, nonatomic) BOOL connectingRoom;

/// 音频设备选则列表
/// Audio device selection list
@property (strong) IBOutlet NSTableView *audioSelectView;

/// 视频设备选则列表
/// Video equipment selection list
@property (strong) IBOutlet NSTableView *videoSelectView;

/// 美颜窗口
/// beauty window
@property (strong) IBOutlet NSPanel *beautyPanel;

///是否开启美颜(磨皮)
///Whether to turn on beauty treatment (dermabrasion)
@property BOOL beautyEnabled;

// 以下为美颜参数
// The following are beauty parameters
@property NSInteger beautyLevel;
@property NSInteger rednessLevel;
@property NSInteger whitenessLevel;
Expand Down
Loading