开发者中心

名称:上海璟梦信息科技有限公司实时音视频 集成文档
版本:V1.0.0
日期:2022-02-15

一.集成指南

1 申请appId 和appToken

1.开发者平台申请

2.导入SDK包

  1. 导入libCLVoiceRtvSDK.a
  2. 导入libCLVoiceVLSDK.a

SDK导入之后,需要在info.plist申请相机,麦克风等相应权限

3配置

需要在Build Settings -> Other Linker Arguments 中,添加**-ObjC**

二.接口调用

1.SDK初始化

导入头文件**#import “CLVoiceRtvManage.h”**

/**
 获取单例对象
 @return GtVoiceRtvManage实例
 */
+ (instancetype)sharedInstance;

///SDK初始化
[[CLVoiceRtvManage sharedInstance] initWithAppId:@"100041" appToken:@"U2FsdGVkX1/xXU9eqTRMOjrIVni7+Dqt5k4jpDub64g=" environment:kServerEnvironment_Release];

2.查询房间是否存在

/**
 根据房间id查询放假状态

 @param roomId 查询的房间id
 @param userId 查询用户Id
 @param completion 返回结果
 */
- (void)queryRoomStatusRoomId:(NSString *)roomId userId:(NSString *)userId completion:(void(^)(int64_t result,NSString * msg))completion;
//示例:

  [[CLVoiceRtvManage sharedInstance] initWithAppId:<#appId#> appToken:<#appToken#> environment:kServerEnvironment_Release];  
  [[CLVoiceRtvManage sharedInstance] queryRoomStatusRoomId:body.roomId userId:[CLImClient shared].userId completion:^(int64_t result, NSString *msg) {
        if (result !=0) {
        }else{
            dispatch_async(dispatch_get_main_queue(), ^{
                [[NSNotificationCenter defaultCenter] postNotificationName:@"kCallOfflineLastMessage" object:lastMessage userInfo:nil];
            });
        }
    }];
//注意:查询房间用户未登录,要进行tcp连接,可以调用初始化方法

2.创建或登录房间

/**
 创建或者登录房间

 @param userId 用户Id(透传客户方自己的用户编号)
 @param roomSecret 房间密钥
 @param roomId 房间Id(相同appId,相同roomId的用户会分配到同一个房间)
 @param loginType  0为创建房间 1登录房间
 */
- (void)loginRoomWithUserId:(NSString *)userId roomId:(NSString *)roomId roomSecret:(NSString *)roomSecret;
- (void)loginRoomWithUserId:(NSString *)userId
                     roomId:(NSString *)roomId
                 roomSecret:(NSString *)roomSecret
                  loginType:(NSString *)loginType;

3.退出房间

//退出房间
- (void)logout;

//示例
[[CLVoiceRtvManage sharedInstance] logout];

4.代理设置

/**
 添加代理

 @param aDelegate 代理对象
 */
- (void)addDelegate:(id)aDelegate;

/**
 移除代理

 @param aDelegate 代理对象
 */
- (void)removeDelegate:(id)aDelegate;

/**
 移除所有代理对象
 */
- (void)removeAllDelegates;

5.常用代理方法

/**
 网络断开后,重连多次失败返回
 
 @param sender GtVoiceRtvManage实例
 @param desc 错误描述
 */
- (void)chatManage:(CLVoiceRtvManage *)sender connectFail:(NSString *)desc;

/**
 在网络异常(如:wifi-->3G, 3G-->wifi,无网络-->3G/wifi),开始自动重新登录
 
 @param sender GtVoiceRtvManage实例
 @param tryReLoginTimes 重新登录尝试次数
 */
- (void)chatManage:(CLVoiceRtvManage *)sender beginAutoReLoginWithTryTimes:(NSUInteger)tryReLoginTimes;

/**
 登录结果-回调
 
 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败
 @param msg 成功时为nil,失败时为错误原因
 */
- (void)chatManage:(CLVoiceRtvManage *)sender loginRespWithResult:(int)result msg:(NSString *)msg;

/**
 注销结束-回调
 
 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败
 @param msg 成功时为nil,失败时为错误原因
 */
- (void)chatManage:(CLVoiceRtvManage *)sender logoutRespWithResult:(int)result msg:(NSString *)msg;

/**
 发送文本回调
 
 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败
 @param msg 成功时为nil,失败时为错误原因
 @param expand 扩展字段,可放空
 */
- (void)chatManage:(CLVoiceRtvManage *)sender sendMessageWithResult:(int)result msg:(NSString *)msg ext1:(NSData *)ext1 ext2:(NSString *)ext2;

/**
 接收到文本消息通知
 
 @param sender GtVoiceRtvManage实例
 @param TextMessageNotify TextMessageNotify模型
 */
- (void)chatManage:(CLVoiceRtvManage *)sender msgNotify:(CLVoiceRtvMsgNotify *)msgNotify;

/**
 上下麦回调
 
 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败
 @param msg 成功时为nil,失败时为错误原因
 @param onoff Yes:当前上麦状态 No:当前下麦状态
 */
- (void)chatManage:(CLVoiceRtvManage *)sender chatMicRespWithResult:(int)result msg:(NSString *)msg status:(BOOL)status;

/**
 发送实时语音错误返回,只有发送失败才会收到回调,注意音频发送是频繁的,出现错误时此事件是一连串的
 
 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败
 @param msg 成功时为nil,失败时为错误原因
 */
- (void)chatManage:(CLVoiceRtvManage *)sender sendRealTimeVoiceMessageError:(int)result msg:(NSString *)msg;

/**
 当开启播放声音的计量检测,返回实时语音或自动播放的峰值和平均值
 
 @param sender GtVoiceRtvManage实例
 @param peakPower 声音分贝的峰值
 @param avgPower 声音分贝的平均值
 */
- (void)chatManage:(CLVoiceRtvManage *)sender playMeteringPeakPower:(float)peakPower AvgPower:(float)avgPower;

/**
 当开启录音的计量检测,返回实时录音的峰值和平均值
 
 @param sender GtVoiceRtvManage实例
 @param peakPower 声音分贝的峰值
 @param avgPower 声音分贝的平均值
 */
- (void)chatManage:(CLVoiceRtvManage *)sender recorderMeteringPeakPower:(float)peakPower AvgPower:(float)avgPower;

/**
 网络延迟
 
 @param sender GtVoiceRtvManage实例
 @param delay 延迟时间(单位:毫秒)
 */
- (void)chatManage:(CLVoiceRtvManage *)sender netWorkDelay:(UInt64)delay;

/**
 音量修改回调

 @param sender GtVoiceRtvManage实例
 @param result 0为成功,其他为失败(4000=音频管理器未初始化)
 @param msg 成功时为nil,失败时为错误原因
 @param volume 修改后的音量大小(0~1)
 @param userId 用户编号
 */
- (void)chatManage:(CLVoiceRtvManage *)sender volumeValueChangeWithResult:(int)result msg:(NSString *)msg volume:(float)volume UserId:(NSString *)userId;

- (void)willDisplayFrame:(CVPixelBufferRef)pixelBuffer timestamp:(uint64_t)timestamp identity:(NSString *)identity;

6.日志设置

/**
 设置日志级别
 
 @param logLevel 0--关闭日志  1--error  2--debug(不设置为默认该级别) 3--warn  4--info  5--trace
 */
- (void)setLogLevel:(int)logLevel;

7.扬声器及听筒设置

/**
 设置扬声器模式
 */
- (void)setAudioRouteToSpeaker;

/**
 设置听筒模式
 */
- (void)setAudioRouteToNone;

8.上下麦设置

  • (BOOL)getCurrentMicState;//返回当前上下麦状态,YES:上麦
/**
 上/下麦

 @param micType YES:上麦 NO:下麦
 @param timeLimit 限时上麦时间(单位:秒)
 */
- (void)chatMicWithMicType:(BOOL)micType timeLimit:(int)timeLimit;

9.音量设置

/**
 根据用户Id来设置播放音量

 @param volume 0.0~1.0,默认为1.0
 @param userId 用户id
 */
- (void)setVolume:(float)volume userId:(NSString *)userId;

三.消息发送

1.消息类型

typedef NS_ENUM(NSUInteger, CLVoiceRtvMessageType) {
    GtVoiceRtvMessageType_Voice                         = 0,//语音消息
    GtVoiceRtvMessageType_Text                          = 1,//文字消息
    GtVoiceRtvMessageType_Url                           = 2,//语音url
    GtVoiceRtvMessageType_TextAndUrl                    = 3,//语音url+文字
    GtVoiceRtvMessageType_Video                         = 5,
    GtVoiceRtvMessageType_Login                         = 100,//登录通知
    GtVoiceRtvMessageType_Logout                        = 101,//退出通知
};

2.消息发送

/**
 发送消息
 
 @param type 消息类型
 @param text 文字内容
 @param voiceUrl 语音文件网络地址
 @param voiceDuration 语音时长
 @param expand 扩展字段
 */
- (void)sendMessageWithType:(CLVoiceRtvMessageType)type 
                       text:(NSString *)text 
                   voiceUrl:(NSString *)voiceUrl 
              voiceDuration:(int)voiceDuration 
                       ext1:(NSData *)ext1 
                       ext2:(NSString *)ext2;

四.视频

1.初始化

初始化CLVoiceVLSDK

/**
 单例

 @return GtVoiceVLSDK唯一实例
 */
+ (instancetype)sharedInstance;

/**
 初始化

 @param appId 应用编号
 @param isTest YES:测试环境 NO:正式环境
 @param uuid 唯一标识
 */
- (void)initWithAppId:(NSString *)appId isTest:(BOOL)isTest uuid:(NSString *)uuid;

2.登录视频房间

/**
 登录房间

 @param roomId 房间Id
 @param userId 用户Id
 @param isOpenCamera 是否打开摄像头
 @param preView 父视图(为空的话默认添加到根视图上)
 @param infoArray 位置描述信息,默认传nil
 */
- (void)loginWithRoomId:(NSString *)roomId
                 userId:(NSString *)userId
           isOpenCamera:(BOOL)isOpenCamera
                preView:(UIView *)preView
              infoArray:(NSMutableArray <CLVoiceVLInfoModel *> *)infoArray;

3.退出视频房间

/**
 退出房间
 */
- (void)logout;

4.分辨率支持

typedef NS_ENUM (NSUInteger, GtVoiceVLVideoSessionPreset) { // 视频分辨率(都是16:9 当此设备不支持当前分辨率,自动降低一级)
    GtVoiceVLCaptureSessionPreset144x192    = 0, // 最低分辨率
    GtVoiceVLCaptureSessionPreset360x640    = 1, // 低分辨率
    GtVoiceVLCaptureSessionPreset540x960    = 2, // 中分辨率
    GtVoiceVLCaptureSessionPreset720x1280   = 3  // 高分辨率
};

5.视频质量

typedef NS_ENUM (NSUInteger, GtVoiceVLVideoQuality) { // 视频质量
    GtVoiceVLVideoQuality_Low0      = 0, // 分辨率: 144 *192 帧数:10 码率:110Kps
    GtVoiceVLVideoQuality_Low1      = 1, // 分辨率: 360 *640 帧数:15 码率:500Kps
    GtVoiceVLVideoQuality_Low2      = 2, // 分辨率: 360 *640 帧数:24 码率:800Kps
    GtVoiceVLVideoQuality_Low3      = 3, // 分辨率: 360 *640 帧数:30 码率:800Kps
    GtVoiceVLVideoQuality_Medium1   = 4, // 分辨率: 540 *960 帧数:15 码率:800Kps
    GtVoiceVLVideoQuality_Medium2   = 5, // 分辨率: 540 *960 帧数:24 码率:800Kps
    GtVoiceVLVideoQuality_Medium3   = 6, // 分辨率: 540 *960 帧数:30 码率:800Kps
    GtVoiceVLVideoQuality_High1     = 7, // 分辨率: 720 *1280 帧数:15 码率:1000Kps
    GtVoiceVLVideoQuality_High2     = 8, // 分辨率: 720 *1280 帧数:24 码率:1200Kps
    GtVoiceVLVideoQuality_High3     = 9, // 分辨率: 720 *1280 帧数:30 码率:1200Kps
    GtVoiceVLVideoQuality_Default   = GtVoiceVLVideoQuality_Low0 // 默认配置
};

6.接收视频代理

- (void)willDisplayFrame:(CVPixelBufferRef)pixelBuffer timestamp:(uint64_t)timestamp identity:(NSString *)identity;

可以使用SDK自带GtVoiceVLDisplayView来进行视频播放

7.视频登录示例

1.视频登录

CLVoiceRtvManage * rtv = [CLVoiceRtvManage sharedInstance];
rtv.isOpenPushing = YES;///是否开启推流
rtv.cameraStatus  = 1;///摄像头是否开启
rtv.cameraPosition = GtVoiceVLCameraPositionType_Front;///摄影头方向
[rtv loginVideoRoomWithRoomId:self.roomId userId:self.userId isOpenCamera:YES preView:self.videoView];

2.设置视频接收视图

- (void)setPlayerViewWithView:(UIView *)view identity:(NSString *)identity{
    UIView *bgView = [[GtVoiceVLDisplayView alloc] initWithFrame:view.bounds];
    [view insertSubview:bgView atIndex:0];
    [self.pixDictionAry setObject:bgView forKey:identity];
}

3.视频播放

- (void)willDisplayFrame:(CVPixelBufferRef)pixelBuffer timestamp:(uint64_t)timestamp identity:(NSString *)identity;
{
    if ([self.pixDictionAry.allKeys containsObject:identity]) {
        GtVoiceVLDisplayView * disPlayView = self.pixDictionAry[identity];
        [disPlayView.superview bringSubviewToFront:disPlayView];
        [disPlayView updateInterfaceWithPixelBufferRef:pixelBuffer];
    }
}

五.历史版本

发布日期 发布版本 更新说明
2021-02-18 V1.0.0 初版发布