Commit c1c6a8ae by suolong

修改bug

parent 9a06339a
...@@ -84,6 +84,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -84,6 +84,9 @@ NS_ASSUME_NONNULL_BEGIN
// 寨信刷新 // 寨信刷新
+ (NSString *)fus_ZhaiXin_Refresh; + (NSString *)fus_ZhaiXin_Refresh;
// 环信登录状态刷新
+ (NSString *)fus_IM_Login_State_Refresh;
// 官方或者通知刷新 // 官方或者通知刷新
+ (NSString *)fus_OFFICIAL_MESSAGE_REFRESH; + (NSString *)fus_OFFICIAL_MESSAGE_REFRESH;
......
...@@ -133,6 +133,11 @@ ...@@ -133,6 +133,11 @@
return @"ZhaiXinRefresh"; return @"ZhaiXinRefresh";
} }
// 环信登录状态刷新
+ (NSString *)fus_IM_Login_State_Refresh {
return @"fus_IM_Login_State_Refresh";
}
// 官方或者通知刷新 // 官方或者通知刷新
+ (NSString *)fus_OFFICIAL_MESSAGE_REFRESH { + (NSString *)fus_OFFICIAL_MESSAGE_REFRESH {
return @"OfficialMessageRefresh"; return @"OfficialMessageRefresh";
......
...@@ -593,6 +593,11 @@ ...@@ -593,6 +593,11 @@
[self.livePusher destroy]; [self.livePusher destroy];
self.livePusher = nil; self.livePusher = nil;
// 单流直播结束后,主动释放系统音频会话,避免系统继续显示麦克风占用中。
[[AVAudioSession sharedInstance] setActive:NO
withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
error:nil];
[self fus_offTorch]; [self fus_offTorch];
[[FUSBeautyHelper shareInstance] fus_destroyBeautyEngine]; [[FUSBeautyHelper shareInstance] fus_destroyBeautyEngine];
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#import "FUSIMChatHttpHelper.h" #import "FUSIMChatHttpHelper.h"
#import "FUSSingleChatDBOperate.h" #import "FUSSingleChatDBOperate.h"
#import "FUSHttpHelper.h"
#import "FUSVideoChatFailAlertView.h" #import "FUSVideoChatFailAlertView.h"
#import "FUSSingleLiveEndedPopView.h" #import "FUSSingleLiveEndedPopView.h"
...@@ -69,7 +70,7 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) { ...@@ -69,7 +70,7 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) {
#define kmessageTypeToStr(type) [NSString stringWithFormat:@"%ld",type] #define kmessageTypeToStr(type) [NSString stringWithFormat:@"%ld",type]
@interface FUSIMChatService ()<EMChatManagerDelegate> @interface FUSIMChatService ()<EMChatManagerDelegate, EMClientDelegate>
/** /**
当前的会话对象 当前的会话对象
...@@ -87,6 +88,11 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) { ...@@ -87,6 +88,11 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) {
临时保存未点击过的未接听通话消息的数组 <EMMessage *> 临时保存未点击过的未接听通话消息的数组 <EMMessage *>
*/ */
@property (nonatomic,strong) NSMutableArray *tempUnacceptedConversationMsgArr; @property (nonatomic,strong) NSMutableArray *tempUnacceptedConversationMsgArr;
/**
是否已经安排了掉线后的登录校验,避免重复触发兜底重连
*/
@property (nonatomic,assign) BOOL hasPendingReconnectCheck;
/** /**
整个通话流程中对方的昵称 整个通话流程中对方的昵称
*/ */
...@@ -272,15 +278,108 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) { ...@@ -272,15 +278,108 @@ typedef NS_ENUM(NSInteger, FUSIMChatMessageType) {
{ {
// 防止重复绑定 // 防止重复绑定
[self fus_endSdkChatDelegate]; [self fus_endSdkChatDelegate];
// 注册环信客户端状态回调
[[EMClient sharedClient] addDelegate:self delegateQueue:dispatch_get_main_queue()];
// 注册消息回调 // 注册消息回调
[[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil]; [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
} }
- (void)fus_endSdkChatDelegate - (void)fus_endSdkChatDelegate
{ {
[[EMClient sharedClient] removeDelegate:self];
[[EMClient sharedClient].chatManager removeDelegate:self]; [[EMClient sharedClient].chatManager removeDelegate:self];
} }
/**
同步刷新环信登录状态,供私信列表等界面更新使用
*/
- (void)fus_notifyIMLoginStateChanged
{
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:FUSChatNotificationKeys.fus_IM_Login_State_Refresh object:nil];
});
}
/**
环信断线后延迟做一次兜底校验,优先等待 SDK 自身恢复
*/
- (void)fus_delayCheckAndReconnectIMIfNeeded
{
if (self.hasPendingReconnectCheck) {
return;
}
self.hasPendingReconnectCheck = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.hasPendingReconnectCheck = NO;
if ([EMClient sharedClient].isConnected) {
[self fus_notifyIMLoginStateChanged];
return;
}
if ([FUSHttpHelper getNetworkStatus] == AFNetworkReachabilityStatusNotReachable) {
return;
}
[[FUSIMUserService shareInstance] fus_retryLoginIfNeeded];
});
}
#pragma mark - EMClientDelegate
- (void)connectionStateDidChange:(EMConnectionState)aConnectionState
{
if (aConnectionState == EMConnectionConnected) {
self.hasPendingReconnectCheck = NO;
[self fus_notifyIMLoginStateChanged];
[self fus_delayUpdateTalkListToLastMessage];
return;
}
[self fus_notifyIMLoginStateChanged];
[self fus_delayCheckAndReconnectIMIfNeeded];
}
- (void)autoLoginDidCompleteWithError:(EMError *)aError
{
[self fus_notifyIMLoginStateChanged];
if (aError) {
FUSLogInfo(@"环信SDK自动登录失败——%@", aError.errorDescription);
[self fus_delayCheckAndReconnectIMIfNeeded];
return;
}
[self fus_delayUpdateTalkListToLastMessage];
}
- (void)userAccountDidLoginFromOtherDevice
{
[self fus_notifyIMLoginStateChanged];
[FUSRouter.userRouter showDifferentLoginWithTime:@""];
}
- (void)userAccountDidForcedToLogout:(EMError *)aError
{
[self fus_notifyIMLoginStateChanged];
FUSLogInfo(@"环信SDK被强制退出——%@", aError.errorDescription);
[FUSRouter.userRouter showDifferentLoginWithTime:@""];
}
- (void)userAccountDidRemoveFromServer
{
[self fus_notifyIMLoginStateChanged];
[FUSDialogView fus_showDialog:[NSString fus_versionLocalString:@"聊天账号已失效,请重新登录"]];
[FUSRouter.userRouter logOut];
}
- (void)userDidForbidByServer
{
[self fus_notifyIMLoginStateChanged];
[FUSDialogView fus_showDialog:[NSString fus_versionLocalString:@"聊天账号已被限制,请重新登录"]];
[FUSRouter.userRouter logOut];
}
#pragma mark - 会话列表相关 #pragma mark - 会话列表相关
- (NSString *)fus_analysisLastMsgSkeletonizeWithMsg:(EMMessage *)msg - (NSString *)fus_analysisLastMsgSkeletonizeWithMsg:(EMMessage *)msg
{ {
......
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
*/ */
- (void)fus_autoLoginWithAccount:(NSString *)account; - (void)fus_autoLoginWithAccount:(NSString *)account;
/**
环信掉线后的兜底重登
*/
- (void)fus_retryLoginIfNeeded;
// 环信登录成功回调 // 环信登录成功回调
@property (nonatomic, copy) void(^imLoginSucceedHandler)(void); @property (nonatomic, copy) void(^imLoginSucceedHandler)(void);
......
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
*/ */
@property (nonatomic,assign) NSInteger retryCount; @property (nonatomic,assign) NSInteger retryCount;
/**
当前是否正在执行环信登录,避免掉线时重复触发多次登录
*/
@property (nonatomic,assign) BOOL isLoggingIn;
// 老的数据 // 老的数据
@property (nonatomic, strong) NSMutableArray<EMMessage *> *oldDBArr; // 除去本地生成的消息 @property (nonatomic, strong) NSMutableArray<EMMessage *> *oldDBArr; // 除去本地生成的消息
...@@ -160,6 +165,15 @@ ...@@ -160,6 +165,15 @@
- (void)fus_autoLoginWithAccount:(NSString *)account - (void)fus_autoLoginWithAccount:(NSString *)account
{ {
if ([NSString isNull:account] || [NSString isNull:self.myUserPwd]) {
return;
}
if (self.isLoggingIn) {
return;
}
self.isLoggingIn = YES;
_myUserID = account; _myUserID = account;
// 启动环信的代理服务 // 启动环信的代理服务
...@@ -167,7 +181,7 @@ ...@@ -167,7 +181,7 @@
[self loginWithAccount:account passWord:_myUserPwd success:^{ [self loginWithAccount:account passWord:_myUserPwd success:^{
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:@"refresh_hyLogin_state" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:FUSChatNotificationKeys.fus_IM_Login_State_Refresh object:nil];
if (self.imLoginSucceedHandler) { if (self.imLoginSucceedHandler) {
self.imLoginSucceedHandler(); self.imLoginSucceedHandler();
self.imLoginSucceedHandler = nil; self.imLoginSucceedHandler = nil;
...@@ -181,6 +195,7 @@ ...@@ -181,6 +195,7 @@
// 重置重试次数 // 重置重试次数
self.retryCount = 0; self.retryCount = 0;
self.isLoggingIn = NO;
} failure:^(NSString *errorMsg) { } failure:^(NSString *errorMsg) {
...@@ -188,13 +203,18 @@ ...@@ -188,13 +203,18 @@
self.retryCount ++; self.retryCount ++;
if (self.retryCount <= 3) { // 重试3次 if (self.retryCount <= 3) { // 重试3次
[self fus_autoLoginWithAccount:account]; self.isLoggingIn = NO;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self fus_autoLoginWithAccount:account];
});
}else{ }else{
// 重置重试次数 // 重置重试次数
self.retryCount = 0; self.retryCount = 0;
self.isLoggingIn = NO;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:FUSChatNotificationKeys.fus_IM_Login_State_Refresh object:nil];
// 更新到最新的离线会话 // 更新到最新的离线会话
[[FUSIMChatService shareInstance] fus_delayUpdateTalkListToLastMessage]; [[FUSIMChatService shareInstance] fus_delayUpdateTalkListToLastMessage];
}); });
...@@ -202,6 +222,28 @@ ...@@ -202,6 +222,28 @@
}]; }];
} }
- (void)fus_retryLoginIfNeeded
{
if (self.isLoggingIn) {
return;
}
if ([EMClient sharedClient].isLoggedIn && [EMClient sharedClient].isConnected) {
return;
}
NSString *account = self.myUserID;
if ([NSString isNull:account]) {
account = [FUSCacheDataShare shareStore].userVerifyInfo.uid;
}
if ([NSString isNull:account] || [NSString isNull:self.myUserPwd]) {
return;
}
[self fus_autoLoginWithAccount:account];
}
- (void)fus_bindAPNsToken { - (void)fus_bindAPNsToken {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *token = [[NSUserDefaults standardUserDefaults] objectForKey:FUSChatUDKeys.fus_DEVICE_TOKEN_DATA]; NSData *token = [[NSUserDefaults standardUserDefaults] objectForKey:FUSChatUDKeys.fus_DEVICE_TOKEN_DATA];
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
[self registerNib:[UINib nibWithNibName:EASEMOB_CELL_IDENTIFIER bundle:[FUSChatCenterBunble bundle]] forCellReuseIdentifier:EASEMOB_CELL_IDENTIFIER]; [self registerNib:[UINib nibWithNibName:EASEMOB_CELL_IDENTIFIER bundle:[FUSChatCenterBunble bundle]] forCellReuseIdentifier:EASEMOB_CELL_IDENTIFIER];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(zhaiXinRefresh) name:FUSChatNotificationKeys.fus_ZhaiXin_Refresh object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(zhaiXinRefresh) name:FUSChatNotificationKeys.fus_ZhaiXin_Refresh object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_checkHyLoginState) name:@"refresh_hyLogin_state" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_checkHyLoginState) name:FUSChatNotificationKeys.fus_IM_Login_State_Refresh object:nil];
[self fus_checkHyLoginState]; [self fus_checkHyLoginState];
......
...@@ -1079,6 +1079,8 @@ typedef NS_ENUM(NSInteger, FUSStreamState) { ...@@ -1079,6 +1079,8 @@ typedef NS_ENUM(NSInteger, FUSStreamState) {
weakSelf.pushView = nil; weakSelf.pushView = nil;
}]; }];
}else{ }else{
// 单流直播结束时,需要显式销毁采集 helper,确保底层 pusher 与系统音频会话一起释放。
[self.pushView.captureHelper fus_destroy];
self.pushView = nil; self.pushView = nil;
} }
...@@ -1204,6 +1206,7 @@ typedef NS_ENUM(NSInteger, FUSStreamState) { ...@@ -1204,6 +1206,7 @@ typedef NS_ENUM(NSInteger, FUSStreamState) {
[self.liveFunctionView.linkMicroView fus_destroyLinkMic]; [self.liveFunctionView.linkMicroView fus_destroyLinkMic];
// 推流 // 推流
[self.pushView.captureHelper fus_stopStreamPush]; [self.pushView.captureHelper fus_stopStreamPush];
[self.pushView.captureHelper fus_pauseAudioCapture];
[self.liveFunctionView fus_cleanFunctionView]; [self.liveFunctionView fus_cleanFunctionView];
if (self.pushView.streamType == FUSStreamTypeRTC) { if (self.pushView.streamType == FUSStreamTypeRTC) {
...@@ -1212,6 +1215,8 @@ typedef NS_ENUM(NSInteger, FUSStreamState) { ...@@ -1212,6 +1215,8 @@ typedef NS_ENUM(NSInteger, FUSStreamState) {
weakSelf.pushView = nil; weakSelf.pushView = nil;
}]; }];
}else{ }else{
// 单流直播关闭房间时,补齐采集与音频会话销毁,避免麦克风继续被占用。
[self.pushView.captureHelper fus_destroy];
self.pushView = nil; self.pushView = nil;
} }
......
...@@ -1995,7 +1995,8 @@ static NSInteger const kFUSPayRoomCompanionPopViewTagLeft = 90917002; ...@@ -1995,7 +1995,8 @@ static NSInteger const kFUSPayRoomCompanionPopViewTagLeft = 90917002;
[[FUSLiveHelper shareInstance].liveMinimizeView removeFromSuperview]; [[FUSLiveHelper shareInstance].liveMinimizeView removeFromSuperview];
[FUSLiveHelper shareInstance].liveMinimizeView = nil; [FUSLiveHelper shareInstance].liveMinimizeView = nil;
if ([[FUSLiveHelper shareInstance] liveType] == FUSLiveTypeAnchor) { if ([[FUSLiveHelper shareInstance] liveType] == FUSLiveTypeAnchor) {
[[[[FUSLiveHelper shareInstance] liveVC] pushView].captureHelper fus_stopStreamPush]; // 预览开播页与直播中的退出,统一走完整销毁,确保相机/麦克风采集链路被彻底释放。
[[[[FUSLiveHelper shareInstance] liveVC] pushView].captureHelper fus_destroy];
[[[[FUSLiveHelper shareInstance] liveVC] playView] fus_stopWithUID:[FUSLiveHelper shareInstance].roomInfoModel.roomId]; [[[[FUSLiveHelper shareInstance] liveVC] playView] fus_stopWithUID:[FUSLiveHelper shareInstance].roomInfoModel.roomId];
[[[[FUSLiveHelper shareInstance] liveVC] liveFunctionView] fus_cleanFunctionView]; [[[[FUSLiveHelper shareInstance] liveVC] liveFunctionView] fus_cleanFunctionView];
} else if ([[FUSLiveHelper shareInstance] liveType] == FUSLiveTypeAudience) { } else if ([[FUSLiveHelper shareInstance] liveType] == FUSLiveTypeAudience) {
......
...@@ -776,18 +776,15 @@ ...@@ -776,18 +776,15 @@
} }
- (void)initTTSDK { - (void)initTTSDK {
NSInteger appId = 100667; NSString *currentBundleIdentifier = NSBundle.mainBundle.bundleIdentifier ?: @"";
NSString *formalBundleIdentifier = @"com.fusi.meet.live.chat.video.among.friends";
// 根据系统当前包名判断播放器配置,正式包走正式 license 与 appid。
BOOL useFormalTTSDKConfig = [currentBundleIdentifier isEqualToString:formalBundleIdentifier];
NSInteger appId = useFormalTTSDKConfig ? 642006 : 100667;
NSString *appname = FUSConfig.sharedInstanced.appConfigs.appName; NSString *appname = FUSConfig.sharedInstanced.appConfigs.appName;
NSString *channel = [FUSDeviceHelper fus_getChannelId]; NSString *channel = [FUSDeviceHelper fus_getChannelId];
NSString *bundleID = @"com.ft.chat.ios"; NSString *bundleID = currentBundleIdentifier;
NSString *lisenceFilePath = @"TTSDKLisenceFileForTest"; NSString *lisenceFilePath = useFormalTTSDKConfig ? @"TTSDKLisenceFile" : @"TTSDKLisenceFileForTest";
// NSInteger appId = 980302338;
// NSString *appname = @"FusiClub";
// NSString *channel = [FUSDeviceHelper fus_getChannelId];
// NSString *bundleID = @"com.fusi.meet.live.chat.video.among.friends";
// NSString *lisenceFilePath = @"TTSDKLisenceFile";
TTSDKConfiguration *configuration = [TTSDKConfiguration defaultConfigurationWithAppID:@(appId).description]; TTSDKConfiguration *configuration = [TTSDKConfiguration defaultConfigurationWithAppID:@(appId).description];
configuration.appName = appname; configuration.appName = appname;
......
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews]; [super viewDidLayoutSubviews];
self.tableView.width = self.scollView.width; self.tableView.width = self.scollView.width;
CGRect frame = CGRectMake(0, self.tableView.bottom, self.scollView.width, self.scollView.height - self.topView.height); CGRect frame = CGRectMake(0, self.tableView.bottom, self.scollView.width, [self fus_feedListVisibleHeight]);
if (!CGRectEqualToRect(frame, self.newsFeedListView.frame)) { if (!CGRectEqualToRect(frame, self.newsFeedListView.frame)) {
self.newsFeedListView.maxHeight = CGRectGetHeight(frame); self.newsFeedListView.maxHeight = CGRectGetHeight(frame);
self.newsFeedListView.frame = frame; self.newsFeedListView.frame = frame;
...@@ -199,12 +199,14 @@ ...@@ -199,12 +199,14 @@
self.tableView.tableContentHeightDidChangedHandler = ^(CGFloat height) { self.tableView.tableContentHeightDidChangedHandler = ^(CGFloat height) {
if (weakSelf.tableView.height != height) { if (weakSelf.tableView.height != height) {
CGFloat feedListVisibleHeight = [weakSelf fus_feedListVisibleHeight];
weakSelf.tableView.width = weakSelf.scollView.width; weakSelf.tableView.width = weakSelf.scollView.width;
weakSelf.tableView.height = height; weakSelf.tableView.height = height;
weakSelf.newsFeedListView.maxHeight = weakSelf.scollView.height - weakSelf.topView.height; // 个人页底部有悬浮操作栏,动态列表区域至少要保留可视高度,避免内容较少时无法滚动到“分享/相册/点赞”区域。
weakSelf.newsFeedListView.maxHeight = feedListVisibleHeight;
weakSelf.newsFeedListView.width = weakSelf.scollView.width; weakSelf.newsFeedListView.width = weakSelf.scollView.width;
weakSelf.newsFeedListView.height = weakSelf.scollView.height - weakSelf.topView.height; weakSelf.newsFeedListView.height = feedListVisibleHeight;
weakSelf.newsFeedListView.y = weakSelf.tableView.bottom; weakSelf.newsFeedListView.y = weakSelf.tableView.bottom;
weakSelf.scollView.contentSize = CGSizeMake(weakSelf.scollView.width, weakSelf.tableView.height + weakSelf.newsFeedListView.height); weakSelf.scollView.contentSize = CGSizeMake(weakSelf.scollView.width, weakSelf.tableView.height + weakSelf.newsFeedListView.height);
} }
...@@ -253,6 +255,10 @@ ...@@ -253,6 +255,10 @@
}; };
self.newsFeedListView.heightDidChangedHandler = ^(CGFloat height) { self.newsFeedListView.heightDidChangedHandler = ^(CGFloat height) {
CGFloat feedListVisibleHeight = [weakSelf fus_feedListVisibleHeight];
if (height < feedListVisibleHeight) {
height = feedListVisibleHeight;
}
CGFloat newContentOffsetHeight = height + weakSelf.tableView.height; CGFloat newContentOffsetHeight = height + weakSelf.tableView.height;
CGFloat contentOffsetY = newContentOffsetHeight - weakSelf.scollView.height; CGFloat contentOffsetY = newContentOffsetHeight - weakSelf.scollView.height;
...@@ -813,6 +819,12 @@ ...@@ -813,6 +819,12 @@
return self.tableView.height - self.topView.height; return self.tableView.height - self.topView.height;
} }
/// 个人页下半部分列表的可视高度,避开顶部导航和底部悬浮栏,保证“分享/相册/点赞”区域始终可达。
- (CGFloat)fus_feedListVisibleHeight {
CGFloat height = self.scollView.height - self.topView.height - self.bottomView.height;
return MAX(height, 0);
}
#pragma mark - Animation Images #pragma mark - Animation Images
- (NSMutableArray *)onliveAnimationImgArr { - (NSMutableArray *)onliveAnimationImgArr {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment