全部产品
云市场

iOS开发文档

更新时间:2019-04-03 10:43:22

SDK 简介

  • SDK 库名:AlicomRTCSDK.framework
  • 支持 iOS 8.x 及以上系统
  • 支持 armv64、armv7、i386、x86_64 四架构,静态库

SDK 工程设置

  • 下载AlicomRTCSDK.framework,并添加至 Linked Frameworks and Libraries
  • 下载ArtcSDK.framework,并添加至 Linked Frameworks and Libraries
  • 下载ArtcMediaEngine.framework,并添加至 Embedded Binaries
  • 在工程targetLinked Frameworks and Libraries添加 CoreTelephony.frameworklibc++.tbdlibz.tbd系统库
  • 在工程 targetBuild SettingsOther Linker Flags 增加 -ObjC 配置
  • pod依赖:
    1. pod 'OpenSSL', '~> 1.0.203'
    2. pod 'AliyunOSSiOS'

framework下载

demo 快速接入

  • SDK初始化
  1. // 有账号模式,需要申请阿里云账号,支持点对点
  2. [[AlicomRTC shareInstance] initWithRtcId:_userIdStr];
  3. [AlicomRTC shareInstance].delegate = self;
  4. [AlicomRTC shareInstance].callDelegate = self;
  5. // 日志配置
  6. [Logger shareInstance].logOff = NO;
  7. [Logger shareInstance].logLevel = LoggerLevel_Info;
  8. [Logger shareInstance].delegate = self;
  9. // Token设置
  10. [[Token shareInstance] setDelegate:self];
  • SDK状态回调
  1. #pragma mark - AlicomRTCServiceDelegate
  2. /**
  3. 初始化成功,服务可用
  4. */
  5. -(void)onServiceAvailable{
  6. self.isServiceAvailable = YES;
  7. [TXCommonUtil hiddenLoading];
  8. }
  9. /**
  10. 初始化失败,服务不可用
  11. @param errCode 错误码
  12. @param errMsg 错误信息
  13. */
  14. -(void)onServiceUnavailableWithErrorCode:(NSInteger)errCode errorMsg:(NSString *)errMsg {
  15. [TXCommonUtil hiddenLoading];
  16. self.isServiceAvailable = NO;
  17. self.errorTips = errMsg;
  18. NSLog(@"onServiceUnavailableWithErrorCode : %ld, msg = %@",(long)errCode,errMsg);
  19. NSString *tip = [NSString stringWithFormat:@"服务不可用,请重新登录,错误码:%ld,异常:%@",(long)errCode,errMsg];
  20. AlertControllerShow(tip);
  21. }
  22. /**
  23. 自定义消息接受回调
  24. @param sequence 消息序列号
  25. @param content 消息内容
  26. @param sourceRtcId 消息来源
  27. @param timestamp 时间戳
  28. */
  29. -(void)onCustomMessageReceivedWithSequence:(long long)sequence sourceRtcId:(NSString *)sourceRtcId content:(NSString *)content timestamp:(long long)timestamp {
  30. NSLog(@"onCustomMessageReceivedWithSequence,sequence = %lld,sourceRtcId = %@,content = %@,timestamp = %lld",sequence,sourceRtcId,content,timestamp);
  31. [TXCommonUtil hintProgressMessage:content title:@"收到消息"];
  32. }
  33. /**
  34. 自定义消息发送回调
  35. @param sequence 消息序列号
  36. @param isSuccess 发送消息是否成功
  37. @param errCode 失败的话,有错误码,否则为0
  38. @param errMsg 失败的话,错误信息。否则为nil
  39. */
  40. -(void)onCustomMessageSendedWithSequence:(long long)sequence isSuccess:(BOOL)isSuccess errorCode:(NSInteger)errCode errorMsg:(NSString *)errMsg {
  41. if (isSuccess) {
  42. NSLog(@"onCustomMessageSendedWithSequence,sequence = %lld,isSuccess = %d",sequence,isSuccess);
  43. }
  44. else {
  45. NSLog(@"onCustomMessageSendedWithSequence,sequence = %lld,isSuccess = %d,errorCode = %ld,errMsg = %@",sequence,isSuccess,(long)errCode,errMsg);
  46. [TXCommonUtil hintProgressMessage:[NSString stringWithFormat:@"%ld,%@",(long)errCode,errMsg] title:@"发送消息失败"];
  47. }
  48. }
  • Token获取并回传至SDK
  1. #pragma mark - TokenDelegate
  2. - (void)updateToken:(void(^)(Token *token))tokenHandler {
  3. // 参考阿里云pop接口接入获取token的方案
  4. NSString *allUrlStr = [NSString stringWithFormat:@"http://dyvmsapi.aliyuncs.com/?Signature=%@&%@",hmacSHA1String,sortStr];
  5. NSLog(@"allUrlStr___%@",allUrlStr);
  6. NSURL *url = [NSURL URLWithString:allUrlStr];
  7. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0f];
  8. NSURLSession *session = [NSURLSession sharedSession];
  9. [[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error){
  10. dispatch_async(dispatch_get_main_queue(), ^{
  11. if(!error){
  12. NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
  13. if ([result objectForKey:@"Module"]) {
  14. NSString *jsonStr = [result objectForKey:@"Module"];
  15. NSDictionary *dict = [TXCommonUtil dictionaryWithJsonString:jsonStr];
  16. self->_token = [[Token alloc] initWithDictionary:dict];
  17. block(self->_token,nil);
  18. }
  19. else{
  20. NSString *message = [result objectForKey:@"Message"];
  21. block(nil,[NSString stringWithFormat:@"token获取异常,无Module信息,msg = %@",message]);
  22. }
  23. }
  24. else{
  25. block(nil,[NSString stringWithFormat:@"token获取失败,error msg = %@",error.description]);
  26. }
  27. });
  28. }] resume];
  29. }
  • 创建点对点音频Call并拨打
  1. // VoIP 2 VoIP电话
  2. Call *voipCall = [[AlicomRTC shareInstance] createVoipCall:self.callNumLabel.text withExtendString:self.callExtendString];
  3. if (voipCall) {
  4. self.call = voipCall;
  5. [self.call start];
  6. }
  7. // VoIP 2 PSTN电话
  8. Call *pstnCall = [[AlicomRTC shareInstance] createPstnCall:self.callNumLabel.text andCalleeShowNumber:_showTextField.text withExtendString:self.callExtendString];
  9. if (pstnCall) {
  10. self.call = pstnCall;
  11. [self.call start];
  12. }
  • 创建点对点视频VideoCall并拨打
  1. // 设置分辨率
  2. [[AlicomRTC shareInstance] setCameraResolutionType:AlicomRTCVideoResolution720P];
  3. VideoCall *videoCall = [[AlicomRTC shareInstance] createVideoCall:self.calleeVoipStr withExtendString:self.callExtendString];
  4. if (videoCall) {
  5. self.videoCall = videoCall;
  6. [self.videoCall setCallTimeout:timeout.intValue];
  7. [self.videoCall start];
  8. }
  • Call状态监听
  1. #pragma mark - CallDelegate
  2. - (NSData *)ringtoneWithCallee:(Call *)call {
  3. NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://ytx-abc.oss-cn-beijing.aliyuncs.com/ringtone_2.mp3"]];
  4. return data;
  5. }
  6. - (NSData *)ringtoneWithCaller:(Call *)call {
  7. NSString *path = [[NSBundle mainBundle] pathForResource:@"ringtone_1" ofType:@"m4r"];
  8. NSData *data = [NSData dataWithContentsOfFile:path];
  9. return data;
  10. }
  11. // 被叫
  12. -(void)onReceivingAudioCall:(Call*)call {
  13. self.isCaller = NO;
  14. self.call = call;
  15. [self showCalleeView];
  16. [self showHungupOnly:NO];
  17. if (self.call.callerParticipant.isPstn) {
  18. self.callNumLabel.text = self.call.callerParticipant.phoneNumber;
  19. }
  20. else{
  21. self.callNumLabel.text = self.call.callerParticipant.rtcId;
  22. }
  23. self.hintLabel.text = @"来电中...";
  24. }
  25. -(void)onReceivingVideoCall:(Call*)call {
  26. self.isCaller = NO;
  27. self.videoCall = (VideoCall *)call;
  28. [self.voipTextField resignFirstResponder];
  29. self.nameLabel.text = call.callerParticipant.rtcId;
  30. [self showCalleeView:YES];
  31. }
  32. -(void)onCallConnected:(Call*)call {
  33. if (self.isCaller) { //主叫
  34. self.hintLabel.text = @"呼叫中...";
  35. }
  36. else { //被叫
  37. //扬声器播放声音
  38. [[AlicomDeviceManager shareInstance] audioSpeakerIsOn:YES];
  39. self.hintLabel.text = @"通话中...";
  40. }
  41. }
  42. // 振铃
  43. -(void)onCallRinging:(Call*)call {
  44. self.actionLabel.text = @"振铃中...";
  45. }
  46. -(void)onCallAnswered:(Call*)call {
  47. //主叫本地停止嘟嘟声
  48. [self stopPlay];
  49. //扬声器播放声音
  50. [[AlicomDeviceManager shareInstance] audioSpeakerIsOn:YES];
  51. self.hintLabel.text = @"通话中...";
  52. self.answeredView.hidden = NO;
  53. }
  54. -(void)onPlayModeChanged:(Call*)call withMode:(Audio_Session_Mode)mode{
  55. switch (mode) {
  56. case Audio_Session_Mode_Headset:
  57. {
  58. [self.loudPlayAudioBtn setBackgroundColor:[UIColor yellowColor]];
  59. }
  60. break;
  61. case Audio_Session_Mode_Bluetooth:
  62. {
  63. [self.loudPlayAudioBtn setBackgroundColor:[UIColor blueColor]];
  64. }
  65. break;
  66. case Audio_Session_Mode_Receiver:
  67. {
  68. [self.loudPlayAudioBtn setBackgroundColor:[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1.0f]];
  69. }
  70. break;
  71. case Audio_Session_Mode_Speaker:
  72. {
  73. [self.loudPlayAudioBtn setBackgroundColor:[UIColor greenColor]];
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. -(void)onCallStopped:(Call *)call withCode:(NSInteger)code andMsg:(NSString *)msg{
  81. self.isCaller = YES;
  82. [self.muteBtn setBackgroundColor:[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1.0f]];
  83. [self.loudPlayAudioBtn setBackgroundColor:[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1.0f]];
  84. self.answeredView.hidden = YES;
  85. [self showCallerView];
  86. //停止播放音乐
  87. [self stopPlay];
  88. NSString * tipsStr = [NSString stringWithFormat:@"code___%ld\nmsg___%@",(long)code,msg];
  89. self.hintLabel.text = @"";
  90. //输出通话结束原因
  91. AlertControllerShow(tipsStr);
  92. self.call = nil;
  93. }
  94. - (void)onDtmfData:(Call *)call withDtmf:(NSString *)dtmf withTimestamp:(long long)timestamp {
  95. NSLog(@"onDtmfData,dtmf = %@,timestamp = %lld",dtmf,timestamp);
  96. self.dtmfData = [NSString stringWithFormat:@"%@\ndtmf : %@,timestamp : %lld",self.dtmfData ? self.dtmfData : @"",dtmf,timestamp];
  97. self.dtmfTextView.text = self.dtmfData;
  98. }
  99. /**
  100. 通话中的网络质量
  101. @param call Call对象,quality,网络质量,0-好,1-中,2-差
  102. */
  103. -(void)onNetworkQuality:(Call*)call withQuality:(int)quality {
  104. if (quality == 0) {
  105. [self.switchCameraButton setBackgroundColor:[UIColor greenColor]];
  106. }
  107. else if (quality == 1) {
  108. [self.switchCameraButton setBackgroundColor:[UIColor yellowColor]];
  109. }
  110. else if (quality == 2) {
  111. [self.switchCameraButton setBackgroundColor:[UIColor redColor]];
  112. }
  113. }
  114. /**
  115. 通话中的指标统计
  116. @param call Call对象,model StatisticModel 对象
  117. */
  118. -(void)onMediaStatistics:(Call*)call withModel:(StatisticModel *)model {
  119. NSString *statisticLog = [NSString stringWithFormat:@"onMediaStatistics,统计指标,音延迟 = %d ms,视延迟 = %d ms,发送:音丢包率 = %.2f,视丢包率 = %.2f,帧率 = %hu fps,分辨率 = %dx%d,码率 = %lu kb,接收:音丢包率 = %.2f,视丢包率 = %.2f,帧率 = %hu fps,分辨率 = %dx%d,码率 = %lu kb",model.audioRtt,model.videoRtt,(model.audioSentLostRate / 100.0),(model.videoSentLostRate / 100.0),model.sentFrameRate,model.videoSentWidth,model.videoSentHeight,(model.sentBitRate / 1024),(model.audioReceivedLostRate / 100.0),(model.videoReceivedLostRate / 100.0),model.receivedFrameRate,model.videoReceivedWidth,model.videoReceivedHeight,(model.receivedBitRate / 1024)];
  120. [[Logger shareInstance] logLevel:LoggerLevel_Debug withString:TXLog(statisticLog)];
  121. NSString *statisticStr = [NSString stringWithFormat:@" 账号: \n %@ \n 音延迟 = %d ms \n 视延迟 = %d ms \n 发送:\n 音丢包率 = %.2f \n 视丢包率 = %.2f \n 帧率 = %hu fps \n 分辨率 = %dx%d \n 码率 = %lu kb \n 接收:\n 音丢包率 = %.2f \n 视丢包率 = %.2f \n 帧率 = %hu fps \n 分辨率 = %dx%d \n 码率 = %lu kb",self.voip,model.audioRtt,model.videoRtt,(model.audioSentLostRate / 100.0),(model.videoSentLostRate / 100.0),model.sentFrameRate,model.videoSentWidth,model.videoSentHeight,(model.sentBitRate / 1024),(model.audioReceivedLostRate / 100.0),(model.videoReceivedLostRate / 100.0),model.receivedFrameRate,model.videoReceivedWidth,model.videoReceivedHeight,(model.receivedBitRate / 1024)];
  122. self.statisticsLabel.text = statisticStr;
  123. }
  124. /**
  125. 音视频模式变更
  126. @param call call对象
  127. @param mode 输出mode,0-视频,1-音频
  128. */
  129. -(void)onMediaModeChanged:(Call*)call withMode:(int )mode {
  130. NSString *hintLog = [NSString stringWithFormat:@"onMediaModeChanged,mode = %d",mode];
  131. [[Logger shareInstance] logLevel:LoggerLevel_Debug withString:TXLog(hintLog)];
  132. if (mode == 1) {
  133. [TXCommonUtil hintProgressMessage:@"音频模式"];
  134. }
  135. else if (mode == 0) {
  136. }
  137. }
  • Call取消/停止/拒接通话
  1. [self.call stop];
  • Logger日志输出,可选
  1. #pragma mark - LogDelegate
  2. -(void)outputLogString:(NSString*)logString{
  3. }

常见类及 API 接口

  • Token类及属性,Token是使用该SDK的通行证,开发者从服务端获取该实例
  1. @property(nonatomic, weak) id<TokenDelegate> delegate;
  2. @property(nonatomic,strong) NSString *tokenData;
  3. @property(nonatomic,strong) NSString *username;
  4. @property(nonatomic,strong) NSNumber *cleansession;
  5. @property(nonatomic,strong) NSString *clientId;
  6. @property(nonatomic,strong) NSString *conferenceTopic;
  7. @property(nonatomic,strong) NSString *host;
  8. @property(nonatomic,assign) NSNumber *meetingEventKeepAliveInterval;
  9. @property(nonatomic,strong) NSNumber *phoneTopic;
  10. @property(nonatomic,strong) NSNumber *port;
  11. @property(nonatomic,strong) NSNumber *reconnectTimeout;
  12. @property(nonatomic,strong) NSNumber *registerTime;
  13. @property(nonatomic,strong) NSNumber *sdkClientPort;
  14. @property(nonatomic,strong) NSString *serverId;
  15. @property(nonatomic,strong) NSString *sgwServerTopic;
  16. @property(nonatomic,strong) NSNumber *tlsport;
  17. @property(nonatomic,strong) NSNumber *useTLS;
  18. @property(nonatomic,strong) NSString *vRtcId; //有账号模式
  • Token类的TokenDelegate方法开发者必须实现,用于SDK从开发者获取token的回调
  1. /**
  2. 提供给客户APP具体实现更新token的方法
  3. @param tokenHandler 刷新token后,回传token对象
  4. */
  5. @required
  6. - (void)updateToken:(void(^)(Token *token))tokenHandler;
  • AlicomRTC类属性及API,是本SDK主类
  1. @property(nonatomic, weak) id<AlicomRTCServiceDelegate> delegate;
  2. @property(nonatomic, weak) id<CallDelegate> callDelegate;
  3. /**
  4. 单例
  5. @return self
  6. */
  7. + (instancetype)shareInstance;
  8. /**
  9. AliComRTC SDK版本信息
  10. @return SDK version
  11. */
  12. + (NSString *)getVersion;
  13. /**
  14. 初始化rtcId并开始连接服务(有账号模式:点对点,多方音频)
  15. @param rtcId rtcId
  16. */
  17. - (void)initWithRtcId:(NSString*)rtcId;
  18. /**
  19. 断开服务并销毁
  20. */
  21. - (void)destroy;
  22. /**
  23. voip2voip通话
  24. @param calleeRtcId 被叫rtcId账号
  25. @param extendString 拓展字段(非必要参数)
  26. @return Call的对象(需判断返回是否为空值)
  27. */
  28. - (Call *)createVoipCall:(NSString *)calleeRtcId withExtendString:(NSString *)extendString;
  29. /**
  30. voip2pstn通话
  31. @param calleePhoneNumber 被叫电话号码
  32. @param calleeShowNumber 被叫显示来电号码
  33. @param extendString 拓展字段(非必要参数)
  34. @return Call的对象(需判断返回是否为空值)
  35. */
  36. - (Call *)createPstnCall:(NSString *)calleePhoneNumber andCalleeShowNumber:(NSString *)calleeShowNumber withExtendString:(NSString *)extendString;
  37. /**
  38. voip2callCenter通话
  39. @param calleePhoneNumber 被叫电话号码
  40. @param calleeShowNumber 被叫显示来电号码
  41. @param extendString 拓展字段(非必要参数)
  42. @return Call的对象(需判断返回是否为空值)
  43. */
  44. - (Call *)createCenterCall:(NSString *)calleePhoneNumber andCalleeShowNumber:(NSString *)calleeShowNumber withExtendString:(NSString *)extendString;
  45. /**
  46. 点对点视频通话
  47. @param calleeRtcId 被叫rtcId账号
  48. @param extendString 拓展字段(非必要参数)
  49. @return VideoCall的对象(需判断返回是否为空值)
  50. */
  51. -(VideoCall *)createVideoCall:(NSString *)calleeRtcId withExtendString:(NSString *)extendString;
  52. /**
  53. 视频通话分辨率设置(音频通话不需要)
  54. @param resolutionType 捕获视频分辨率,详见枚举(默认:640x368)
  55. */
  56. -(void)setCameraResolutionType:(AlicomRTCVideoResolutionType )resolutionType;
  • AlicomRTC类的AlicomRTCServiceDelegate方法,开发者是需要实现的,及时获取SDK的有效信息
  1. @required
  2. /**
  3. 初始化成功,服务可用
  4. */
  5. -(void)onServiceAvailable;
  6. /**
  7. 初始化失败,服务不可用
  8. @param errCode 错误码
  9. @param errMsg 错误信息
  10. */
  11. -(void)onServiceUnavailableWithErrorCode:(NSInteger)errCode errorMsg:(NSString *)errMsg;
  12. @optional
  13. /**
  14. 自定义消息接受回调
  15. @param sequence 消息序列号
  16. @param content 消息内容
  17. @param sourceRtcId 消息来源
  18. @param timestamp 时间戳
  19. */
  20. -(void)onCustomMessageReceivedWithSequence:(long long)sequence sourceRtcId:(NSString *)sourceRtcId content:(NSString *)content timestamp:(long long)timestamp;
  21. /**
  22. 自定义消息发送回调
  23. @param sequence 消息序列号
  24. @param isSuccess 发送消息是否成功
  25. @param errCode 失败的话,有错误码,否则为0
  26. @param errMsg 失败的话,错误信息。否则为nil
  27. */
  28. -(void)onCustomMessageSendedWithSequence:(long long)sequence isSuccess:(BOOL)isSuccess errorCode:(NSInteger)errCode errorMsg:(NSString *)errMsg;
  • Participant类属性及API
  1. //isPstn
  2. @property(nonatomic,assign) BOOL isPstn;
  3. //是否在说话
  4. @property(nonatomic,assign) BOOL isActiveSpeaking;
  5. //参与者rtcId
  6. @property(nonatomic,strong) NSString *rtcId;
  7. //参与者phoneNumber
  8. @property(nonatomic,strong) NSString *phoneNumber;
  9. //参与者showNumber
  10. @property(nonatomic,strong) NSString *showNumber;
  11. //参与者streamId
  12. @property(nonatomic,strong) NSString *streamId;
  13. //参与者是否被静音
  14. @property(nonatomic,assign) BOOL isMute;
  15. @property(nonatomic,strong) NSString *uuid;
  • Call类属性与API,表示具体一个通话
  1. //主叫方
  2. @property(nonatomic,strong) Participant *callerParticipant;
  3. //被叫方
  4. @property(nonatomic,strong) Participant *calleeParticipant;
  5. //扩展字段
  6. @property(nonatomic,strong) NSString *extendString;
  7. //放音路由
  8. @property(nonatomic,assign) Audio_Session_Mode callPlayMode;
  9. /**
  10. 开始连接媒体服务
  11. */
  12. -(void)start;
  13. /**
  14. 关闭媒体连接
  15. */
  16. -(void)stop;
  17. /**
  18. 本地是否静音
  19. */
  20. -(BOOL)isMuted;
  21. /**
  22. 本地静音
  23. */
  24. -(void)mute;
  25. /**
  26. 本地取消静音
  27. */
  28. -(void)unmute;
  29. /**
  30. 呼叫默认超时时间设置,默认45s,可设置时间区间30~90s
  31. */
  32. -(void)setCallTimeout:(int) time;
  • Call类的CallDelegate方法,开发者需要实现,可获取每次通话生命周期
  1. /**
  2. 被叫来电,振铃彩铃
  3. @param call Call对象
  4. */
  5. -(NSData *)ringtoneWithCallee:(Call*)call;
  6. /**
  7. 主叫呼叫中,振铃彩铃
  8. @param call Call对象
  9. */
  10. -(NSData *)ringtoneWithCaller:(Call*)call;
  11. /**
  12. 音频电话来电,被叫振铃,并返回振铃数据
  13. @param call Call对象
  14. */
  15. -(void)onReceivingAudioCall:(Call*)call;
  16. /**
  17. 视频电话来电,被叫振铃,并返回振铃数据
  18. @param call VideoCall对象
  19. */
  20. -(void)onReceivingVideoCall:(Call*)call;
  21. /**
  22. 媒体连接成功了
  23. @param call Call对象
  24. */
  25. -(void)onCallConnected:(Call*)call;
  26. /**
  27. 接通对方了,主叫振铃
  28. @param call Call对象
  29. */
  30. -(void)onCallRinging:(Call*)call;
  31. /**
  32. 被叫接听了,主叫停止振铃
  33. @param call Call对象
  34. */
  35. -(void)onCallAnswered:(Call*)call;
  36. /**
  37. 通话结束
  38. @param call Call对象
  39. @param code code
  40. @param msg msg
  41. */
  42. -(void)onCallStopped:(Call *)call withCode:(NSInteger)code andMsg:(NSString *)msg;
  43. /**
  44. 音频输出模式变更
  45. @param call call对象
  46. @param mode 输出mode
  47. */
  48. -(void)onPlayModeChanged:(Call*)call withMode:(Audio_Session_Mode)mode;
  49. /**
  50. 音频输出dtmf
  51. @param call call对象
  52. @param dtmf 输出dtmf,timestamp 输出timestamp
  53. */
  54. -(void)onDtmfData:(Call*)call withDtmf:(NSString *)dtmf withTimestamp:(long long)timestamp;
  55. /**
  56. 通话中的网络质量
  57. @param call Call对象,quality,网络质量,0-好,1-中,2-差
  58. */
  59. -(void)onNetworkQuality:(Call*)call withQuality:(int)quality;
  60. /**
  61. 通话中的指标统计
  62. @param call Call对象,model StatisticModel 对象
  63. */
  64. -(void)onMediaStatistics:(Call*)call withModel:(StatisticModel *)model;
  65. /**
  66. 音视频模式变更
  67. @param call call对象
  68. @param mode 输出mode,0-视频,1-音频
  69. */
  70. -(void)onMediaModeChanged:(Call*)call withMode:(int )mode;
  • Logger类及属性,日志输出设置
  1. // 日志开关
  2. @property (nonatomic,assign) BOOL logOff;
  3. // 日志等级
  4. @property (nonatomic,assign) LoggerLevel logLevel;
  5. @property (nonatomic,weak) id<LoggerDelegate> delegate;
  6. // 日志等级枚举
  7. typedef NS_ENUM(NSInteger, LoggerLevel) {
  8. LoggerLevel_Error, //最高日志等级,建议输出错误信息;
  9. LoggerLevel_Warn, //略高于Info,建议输出可能存在隐患但目前仍为造成错误的信息,比如token即将过期等其他关键行为;
  10. LoggerLevel_Info, //略高于Debug,建议输出SDK运行时关键节点行为,如执行到关键方法、关键参数等;
  11. LoggerLevel_Debug, //略高于Verbose,建议输出SDK运行时较为底层的行为,如ARTC运行时日志、收发信令完整内容等;
  12. LoggerLevel_Verbose //最低等级日志,建议关注非常细节的行为时才需要了解,如MQTT运行时日志、日志上传进度等;
  13. };
  • Logger类的Delegate方法,如果想输出日志并保存,可以实现此方法
  1. /**
  2. 对外输出函数
  3. available v1.0.0
  4. @param logString 输出内容
  5. */
  6. -(void)outputLogString:(NSString*)logString;

常见错误码

  1. //错误码
  2. typedef NS_ENUM(NSInteger, ERROR_CODE) {
  3. //mqtt及token异常的错误基准,所有mqtt及token错误都是1xxxxxx的形式
  4. ERROR_MQTT_BASE = 1000000,
  5. //mqtt连接失败
  6. ERROR_MQTT_CONNECT_FAIL = ERROR_MQTT_BASE + 100,
  7. //mqtt消息发送失败
  8. ERROR_MQTT_SEND_FAIL = ERROR_MQTT_BASE + 101,
  9. //token无效
  10. ERROR_TOKEN_INVALID = ERROR_MQTT_BASE + 102,
  11. //token获取失败
  12. ERROR_GET_TOKEN_FAIL = ERROR_MQTT_BASE + 103,
  13. //token上传失败
  14. ERROR_UPLOAD_TOKEN_FAIL = ERROR_MQTT_BASE + 104,
  15. //本地业务异常的错误基准,所有业务错误都是2xxxxxx的形式
  16. ERROR_CALL_BASE = 2000000,
  17. //本地主动挂断
  18. ERROR_LOCAL_STOP = ERROR_CALL_BASE,
  19. //远端主动挂断
  20. ERROR_REMOTE_STOP = ERROR_CALL_BASE + 99,
  21. //拨打自己
  22. ERROR_CALL_SELF = ERROR_CALL_BASE + 100,
  23. //拨打电话为空
  24. ERROR_CALL_EMPTY = ERROR_CALL_BASE + 101,
  25. //joinChannel超时
  26. ERROR_TIME_OUT = ERROR_CALL_BASE + 102,
  27. //被叫振铃超时,一般发生在主叫意外断线
  28. ERROR_CALLEE_ALERTING_TIMEOUT = ERROR_CALL_BASE + 103,
  29. //被叫不在线
  30. ERROR_NOT_ONLINE = ERROR_CALL_BASE + 104,
  31. //接听失败
  32. ERROR_ANSWER_FAIL = ERROR_CALL_BASE + 105,
  33. //拒绝应答
  34. ERROR_ANSWERED_REFUSE = ERROR_CALL_BASE + 106,
  35. //主叫取消呼叫
  36. ERROR_CALLER_CANCEL = ERROR_CALL_BASE + 107,
  37. //被叫无人接听
  38. ERROR_NO_ANSWER = ERROR_CALL_BASE + 108,
  39. //被叫占线在忙
  40. ERROR_ON_BUSING = ERROR_CALL_BASE + 109,
  41. //被叫版本过低
  42. ERROR_VERSION_OLD = ERROR_CALL_BASE + 110,
  43. //roomid为空
  44. ERROR_ROOM_ID_EMPTY = ERROR_CALL_BASE + 111,
  45. //被踢出房间
  46. ERROR_ROOM_KICKED = ERROR_CALL_BASE + 112,
  47. //AlicomRTC服务不可用
  48. ERROR_SERVICE_UNAVAILABLE = ERROR_CALL_BASE + 113,
  49. //RTCID为空
  50. ERROR_RTCID_EMPTY = ERROR_CALL_BASE + 114,
  51. //扩展字段超过128字节
  52. ERROR_EXTEND_STRING_LENG = ERROR_CALL_BASE + 115,
  53. //主动断开AlicomRTC服务
  54. ERROR_LOCAL_DESTROY = ERROR_CALL_BASE + 116,
  55. //状态不对,有别的通话正在进行中
  56. ERROR_LOCAL_BUSY = ERROR_CALL_BASE + 117,
  57. //自定义消息为空或长度超过1024
  58. ERROR_CUSTOM_MESSAGE_ERROR = ERROR_CALL_BASE + 120,
  59. //自定义消息网络异常
  60. ERROR_CUSTOM_MESSAGE_ERROR_NET = ERROR_CALL_BASE + 121,
  61. //对方接受自定义消息超时
  62. ERROR_CUSTOM_MESSAGE_TIMEOUT = ERROR_CALL_BASE + 122,
  63. //麦克风无权限
  64. ERROR_MAC_PHONE_NO_PERMISSION = ERROR_CALL_BASE + 130,
  65. //相机无权限
  66. ERROR_CAMERA_NO_PERMISSION = ERROR_CALL_BASE + 131,
  67. //服务端返回业务异常的错误基准,所有业务服务返回的错误都是3xxxxxx的形式,向上透出的错误码为基准+服务返回的错误码
  68. ERROR_SERVER_BASE = 3000000,
  69. //账号被登录或被踢
  70. ERROR_SERVER_KICKED = ERROR_SERVER_BASE + 110000,
  71. //服务端不可用
  72. ERROR_SERVER_UNAVAILABLE = ERROR_SERVER_BASE + 110001,
  73. //媒体sdk返回异常的错误基准,所有媒体返回的错误都是4xxxxxx的形式,向上透出的错误码为基准+媒体sdk返回的错误码
  74. ERROR_MEDIA_BASE = 4000000,
  75. //媒体网络中断
  76. ERROR_MEDIA_LOST = ERROR_MEDIA_BASE + 110000,
  77. //其他错误
  78. ERROR_UNKNOW = 8000000
  79. };