BGLiveBaseController.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // BGLiveBaseController.h
  3. // BugoLive
  4. //
  5. // Created by xfg on 16/11/23.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. // 直播基类
  8. #import <UIKit/UIKit.h>
  9. #import <CoreTelephony/CTCallCenter.h>
  10. #import <CoreTelephony/CTCall.h>
  11. #import "BGBaseViewController.h"
  12. #import "BGIMMsgHandler.h"
  13. #import "CurrentLiveInfo.h"
  14. @interface BGLiveBaseController : BGBaseViewController
  15. {
  16. @private
  17. // 用于音频退出直播时还原现场
  18. NSString *_audioSesstionCategory; // 进入房间时的音频类别
  19. NSString *_audioSesstionMode; // 进入房间时的音频模式
  20. @protected
  21. CTCallCenter *_callCenter; // 电话监听
  22. BOOL _isAtForeground; // 是否在前台
  23. BOOL _isPhoneInterupt; // 是否是电话中断
  24. BOOL _hasHandleCall;
  25. BGIMMsgHandler *_iMMsgHandler; // IM处理单例
  26. NSTimeInterval _backGroundTime; // 进入后台时间(s)
  27. NSTimeInterval _foreGroundTime; // 进入后台时间(s)
  28. // 切换房间
  29. id<AVRoomAble> _switchingToRoom; // 切换房间
  30. id<IMHostAble> _currentUser; // 当前使用的用户
  31. CurrentLiveInfo *_liveInfo; // 当前直播间信息
  32. BOOL _isHost; // 是否主播
  33. NSString *_roomIDStr; // 房间ID
  34. BOOL _hasShowVagueImg; // 是否已经显示过了模糊图片
  35. BOOL _hasOnMute; // 是否静音了
  36. UILabel *_lossRateSendTipLabel; // 主播丢包率严重情况提示(一般是网络差的情况)
  37. NSInteger _enterLiveStatus;
  38. BOOL _isReEnterChatGroup; // 主播掉线后重新连接上来后,需要重新加入聊天室,而不是创建聊天室
  39. }
  40. @property (nonatomic, strong) id<FWShowLiveRoomAble> liveItem; // 开启、观看直播传入的实体
  41. @property (nonatomic, copy) NSString *vagueImgUrl; // 模糊背景图片url
  42. @property (nonatomic, strong) UIImageView *vagueImgView; // 模糊背景图片
  43. @property (nonatomic, assign) BOOL isDirectCloseLive; // 该参数针对主播、观众,表示是否直播关闭直播,而不显示结束界面
  44. @property (nonatomic, strong) BGIMMsgHandler *iMMsgHandler; // IM处理单例
  45. @property (nonatomic, strong) CurrentLiveInfo *liveInfo; // 当前直播间信息
  46. @property (nonatomic, strong) NSString *roomIDStr; // 房间ID
  47. @property (nonatomic, assign) NSInteger liveType; // 视频类型,对应枚举FW_LIVE_TYPE
  48. @property (nonatomic, assign) NSInteger sdkType; // SDK类型
  49. @property (nonatomic, assign) NSInteger mickType; // 连麦类型
  50. @property (nonatomic, assign) BOOL isHost; // 是否主播
  51. @property (nonatomic, assign) BOOL hasVideoControl; // 点播时,视频控制操作(是否显示播放进度条等)
  52. @property (nonatomic, assign) NSInteger enterChatGroupTimes;// 加入聊天组尝试次数
  53. @property (nonatomic, assign) BOOL hasEnterChatGroup; // 已经加入了一次聊天组,这里不记录成功与否
  54. @property(nonatomic, strong) NSMutableArray *modelArr;
  55. // 创建直播传入实体
  56. - (instancetype)initWith:(id<FWShowLiveRoomAble>)liveItem modelArr:(NSArray *)modelArr;
  57. /**
  58. 弹出退出或直接退出
  59. @param isDirectCloseLive 该参数针对主播、观众,表示是否直播关闭直播,而不显示结束界面
  60. @param isHostShowAlert 该参数针对主播,表示主播是否需要弹出“您当前正在直播,是否退出直播?”,正常情况都需要弹出这个,目前有一种情况不需要弹出,不需要弹出的情况:1、当前直播被后台系统关闭了的情况 2、SDK结束了直播
  61. @param succ 成功回调
  62. @param failed 失败回调
  63. */
  64. - (void)alertExitLive:(BOOL)isDirectCloseLive isHostShowAlert:(BOOL)isHostShowAlert succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed;
  65. // 判断对应类型然后做对应的退出操作
  66. - (void)realExitLive:(FWVoidBlock)succ failed:(FWErrorBlock)failed;
  67. // 退出聊天组:观众退出聊天组前先发退出消息、主播直接退出(主播不用解散聊天组,服务端会做该操作)
  68. - (void)exitChatGroup;
  69. // 视频第一帧加载出来后隐藏模糊背景
  70. - (void)hideVagueImgView;
  71. // 释放该释放的东西
  72. - (void)releaseAll;
  73. @end
  74. // 供子类重写
  75. @interface BGLiveBaseController (ProtectedMethod)
  76. /**
  77. 请求完接口后,刷新直播间相关信息
  78. @param liveItem 视频Item
  79. @param liveInfo 接口获取下来的数据实体
  80. */
  81. - (void)refreshLiveItem:(id<FWShowLiveRoomAble>)liveItem liveInfo:(CurrentLiveInfo *)liveInfo;
  82. /**
  83. 开始进入聊天组
  84. @param chatGroupID 聊天组ID
  85. @param succ 成功回调
  86. @param failed 失败回调
  87. */
  88. - (void)startEnterChatGroup:(NSString *)chatGroupID succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed;
  89. // 加入聊天组成功
  90. - (void)enterChatGroupSucc:(CurrentLiveInfo *)liveInfo;
  91. /**
  92. 业务上退出直播:退出的时候分SDK退出和业务退出,减少退出等待时间
  93. @param isDirectCloseLive 该参数针对主播、观众,表示是否直播关闭直播,而不显示结束界面
  94. @param succ 成功回调
  95. @param failed 失败回调
  96. */
  97. - (void)onServiceExitLive:(BOOL)isDirectCloseLive succ:(FWVoidBlock)succ failed:(FWErrorBlock)failed;
  98. // 加入直播前先判断网络环境
  99. - (void)checkNetWorkBeforeLive;
  100. // 添加网络监听
  101. - (void)addNetListener;
  102. // 添加电话监听: 进入直播成功后监听
  103. - (void)addPhoneListener;
  104. // 移除电话监听:退出直播后监听
  105. - (void)removePhoneListener;
  106. // 退出直播界面
  107. - (void)onExitLiveUI;
  108. // app进入前台
  109. - (void)onAppEnterForeground;
  110. // app进入后台
  111. - (void)onAppEnterBackground;
  112. // 是否正在被电话打断
  113. - (void)phoneInterruptioning:(BOOL)interruptioning;
  114. // 声音打断监听
  115. - (void)onAudioInterruption:(NSNotification *)notification;
  116. // 监听耳机插入和拔出
  117. - (void)audioRouteChangeListenerCallback:(NSNotification*)notification;
  118. @end