美文网首页
腾讯云视频通讯笔记

腾讯云视频通讯笔记

作者: 考槃在涧 | 来源:发表于2018-04-08 15:09 被阅读76次

TILCallSDK

TILCallSDK基于ILiveSDK,实现双人(多人)业务功能封装。ILiveSDK是对QAVSDK和IMSDK的封装。

TILCallSDK基本类

类名 作用
TILBaseCall
TILC2CCall
TILMultiCall
<a name="tilbasecall"></a>TILBaseCall
/**
 发送自定义通知
 
 @param notif  通知
 @param result 发送结果
 */
- (void)postNotification:(TILCallNotification*)notif result:(TILResultBlock)result;

/**
 获取通话类型

 @return 通话类型
 */
- (TILCallType)getCallType;

/**
 获取通话id
 
 @return int 通话id
 */
- (int)getCallId;

/**
 获取通话状态
 
 @return TILCallStatus 通话状态
 */
- (TILCallStatus)getCallStatus;

/**
 设置根视图
 */
- (void)createRenderViewIn:(UIView*)view;

/**
 在给定区域绘制用户的视频结果
 
 @param identifier  用户id
 @param rect        位置区域
 */
- (void)addRenderFor:(NSString *)identifier atFrame:(CGRect)rect;

/**
 移除用户的渲染结果
 
 @param identifier 用户id
 */
- (void)removeRenderFor:(NSString*)identifier;

/**
 交换渲染位置
 
 @param  identifier         用户1
 @param  anotherIdentifier  用户2
 @return BOOL               交换结果
 */
- (BOOL)switchRenderView:(NSString *)identifier with:(NSString *)anotherIdentifier;

/**
 修改渲染区域
 
 @param rect        新的区域
 @param identifier  用户
 */
- (void)modifyRenderView:(CGRect)rect forIdentifier:(NSString*)identifier;

/**
 把渲染视图放到最前面
 
 @param identifier  用户
 */
- (void)bringRenderViewToFront:(NSString*)identifier;

/**
 把渲染视图放到最后面
 
 @param identifier  用户
 */
- (void)sendRenderViewToBack:(NSString*)identifier;

/**
 获取渲染视图
 
 @param  identifier       用户
 @return ILiveRenderView  渲染视图
 */
- (ILiveRenderView *)getRenderFor:(NSString *)identifier;

#pragma mark - Device Controller

/**
 设置开启/关闭摄像头

 @param enable 是否开启
 @param pos    摄像头位置
 @param result 开启结果
 */
- (void)enableCamera:(BOOL)enable pos:(TILCallCameraPos)pos result:(TILResultBlock)result;

/**
 是否开启了摄像头

 @return YES 已开启
 */
- (BOOL)isCameraEnabled;

/**
 切换摄像头位置

 @param result 切换结果
 */
- (void)switchCamera:(TILResultBlock)result;

/**
 获取摄像头位置

 @return 摄像头位置
 */
- (TILCallCameraPos)getCameraPos;

/**
 开启/关闭扬声器

 @param enable 是否开启扬声器

 @return 操作结果
 */

/**
 开启/关闭扬声器

 @param enable 是否开启扬声器
 @param result 操作结果
 */
- (void)enableSpeaker:(BOOL)enable result:(TILResultBlock)result;

/**
 是否开启了扬声器

 @return YES 已开启
 */
- (BOOL)isSpeakerEnabled;

/**
 开启/关闭麦克风
 
 @param enable 是否开启麦克风
 
 @return 操作结果
 */

/**
 开启/关闭麦克风

 @param enable 是否开启麦克风
 @param result 操作结果
 */
- (void)enableMic:(BOOL)enable result:(TILResultBlock)result;

/**
 是否开启了麦克风
 
 @return YES 已开启
 */
- (BOOL)isMicEnabled;

#pragma mark - Message Method

/**
 切换声音模式
 */
- (void)switchAudioMode;

/**
 获取声音模式
 
 @return 声音模式
 */
- (TILCallAudioMode)getAudioMode;
<a name="tilc2ccall"></a>TILC2CCall

TILC2CCall封装了双人视频聊天相关的一些方法。

#pragma mark - init method

/**
 初始化对象

 @param config 配置参数

 @return 对象
 */
- (instancetype)initWithConfig:(TILCallConfig*)config;

#pragma mark - get method

/**
 获取对方id

 @return 用户id
 */
- (NSString*)getPeer;

#pragma mark - sponsor method

/**
 发起通话请求

 @param callTip 通话类型
 @param custom  自定义信息
 @param result  请求结果
 */
- (void)makeCall:(NSString*)callTip custom:(NSString*)custom result:(TILResultBlock)result;

/**
 取消通话邀请

 @param result 取消结果
 */
- (void)cancelCall:(TILResultBlock)result;

#pragma mark - responder method

/**
 接受通话请求

 @param result 接受结果
 */
- (void)accept:(TILResultBlock)result;

/**
 拒绝通话请求�

 @param result 拒绝结果
 */
- (void)refuse:(TILResultBlock)result;

/**
 回复正在通话

 @param result 回复结果
 */
- (void)responseLineBusy:(TILResultBlock)result;

#pragma mark - sponsor responder method

/**
 挂断通话
 
 @param result 挂断结果
 */
- (void)hangup:(TILResultBlock)result;

#pragma mark - send message

/**
 发送c2c消息
 
 @param msg         消息体
 @param identifier  接受者
 @param result      发送结果
 */
- (void)sendC2CMessage:(TIMMessage *)msg identifier:(NSString *)identifier result:(TILResultBlock)result;

/**
 发送在线c2c消息
 
 @param msg         消息体
 @param identifier  接受者
 @param result      发送结果
 */
- (void)sendC2COnlineMessage:(TIMMessage *)msg identifier:(NSString *)identifier result:(TILResultBlock)result;

用法示例:

发起视频通话

    _call = [[TILC2CCall alloc] initWithConfig:config]; //创建一个对象
    
    [_call createRenderViewIn:self.view];  // 创建视频视图
    __weak typeof(self) ws = self;
    [_call makeCall:nil custom:nil result:^(TILCallError *err) {
        if(err){
                // 呼叫失败
        }
        else{
             // 呼叫成功
        }
    }];

挂断视频通话

    [_call hangup:^(TILCallError *err) {
        if(err){
           // 失败
        }
        else{
           // 挂断成功
        }
    }];
<a name="tilmulticall"></a>TILMultiCall

这个类封装了多人视频聊天相关方法

#pragma mark - init method

/**
 初始化对象
 
 @param config 配置参数
 @return 对象
 */
- (instancetype)initWithConfig:(TILCallConfig*)config;

#pragma mark - get method
/**
 获取历史邀请成员列表
 @return 成员(TILCallMember*)列表
 */
- (NSArray*)getMembers;

#pragma mark - sponsor method

/**
 发起通话请求
 
 @param callTip 通话类型
 @param custom  自定义信息
 @param result  请求结果
 */
- (void)makeCall:(NSString*)callTip custom:(NSString*)custom result:(TILResultBlock)result;

/**
 取消通话邀请
 
 @param result  取消结果
 */
- (void)cancelAllCall:(TILResultBlock)result;

/**
 取消通话邀请
 
 @param identifiers 被取消者
 @param result      取消结果
 */
- (void)cancelCall:(NSArray *)identifiers result:(TILResultBlock)result;

/**
 发起邀请请求
 
 @param identifiers 被邀请者
 @param callTip     通话类型
 @param custom      自定义信息
 @param result      请求结果
 */
- (void)inviteCall:(NSArray *)identifiers callTip:(NSString*)callTip custom:(NSString*)custom  result:(TILResultBlock)result;
#pragma mark - responder method

/**
 接受通话请求
 
 @param result 接受结果
 */
- (void)accept:(TILResultBlock)result;

/**
 拒绝通话请求�
 
 @param result 拒绝结果
 */
- (void)refuse:(TILResultBlock)result;

/**
 回复正在通话
 
 @param result 回复结果
 */
- (void)responseLineBusy:(TILResultBlock)result;

#pragma mark - common method

/**
 挂断通话
 
 @param result 挂断结果
 */
- (void)hangup:(TILResultBlock)result;

#pragma mark - send message

/**
 发送c2c消息
 
 @param msg         消息体
 @param identifier  接受者
 @param result      发送结果
 */
- (void)sendC2CMessage:(TIMMessage *)msg identifier:(NSString *)identifier result:(TILResultBlock)result;

/**
 发送在线c2c消息
 
 @param msg         消息体
 @param identifier  接受者
 @param result      发送结果
 */
- (void)sendC2COnlineMessage:(TIMMessage *)msg identifier:(NSString *)identifier result:(TILResultBlock)result;

/**
 发送群消息
 
 @param msg    消息体
 @param result  发送结果
 */
- (void)sendGroupMessage:(TIMMessage *)msg result:(TILResultBlock)result;

/**
 发送在线群消息
 
 @param msg    消息体
 @param result  发送结果
 */
- (void)sendGroupOnlineMessage:(TIMMessage *)msg result:(TILResultBlock)result;

ILiveSDK

初始化ILiveSDK:

接口名 接口描述
initSdk: accountType: ILiveSDK内部类初始化,告知AppId。内部包含了IMSDK的初始化
参数类型 参数名 说明
int appId 业务方appid
int accountType 业务方 accountType

示例:

[[ILiveSDK getInstance] initSdk:SDKAppID accountType:AccountType];

账号注册和登录

账号注册和登录分独立模式托管模式两种模式:

独立模式:用户帐号信息由开发者保存,用户身份验证(比如注册与验密)也由开发者负责;
托管模式:由腾讯为开发者提供帐号的密码注册、存储和密码验证,以及第三方openid和token的托管验证服务。

我们选择使用独立模式来进行注册和登录。

独立模式注册之后,用户在APP客户端登录,输入帐号密码后到服务器验证,验证成功后,APP自有帐号登录服务器使用私钥派发签名(UserSig)给客户端,APP客户端使用用户帐号和私钥签名,调用音视频SDK或即时通信SDK的接口进行验证,验证成功后即可使用音视频云或即时通信云服务。验证代码如下:

    [[ILiveLoginManager getInstance] iLiveLogin:username sig:sig succ:^{
            //独立模式登录成功 sig是服务器验证账号密码成功之后返回的
    }failed:^(NSString *moudle, int errId, NSString *errMsg) {
            //独立模式登录失败
    }];

相关文章

网友评论

      本文标题:腾讯云视频通讯笔记

      本文链接:https://www.haomeiwen.com/subject/mizphftx.html