Commit 9d01856a by suolong

提交下bug处理

parent fa916616
...@@ -78,12 +78,12 @@ static const NSString *FUSCidUDKey = @"FUSCidUDKey"; ...@@ -78,12 +78,12 @@ static const NSString *FUSCidUDKey = @"FUSCidUDKey";
/// App Version /// App Version
- (NSString *)appVersion { - (NSString *)appVersion {
return @"7850"; return @"7851";
} }
/// App Dot Version /// App Dot Version
- (NSString *)appDotVersion { - (NSString *)appDotVersion {
return @"7.8.5.0"; return @"7.8.5.1";
} }
/// App Id /// App Id
......
...@@ -352,7 +352,9 @@ NSString * const kEVENT_RECHARGE_FIRST_RECHARGE_WINDOW_RECEIVE_OFFICIAL_RECAHARG ...@@ -352,7 +352,9 @@ NSString * const kEVENT_RECHARGE_FIRST_RECHARGE_WINDOW_RECEIVE_OFFICIAL_RECAHARG
case FUSJsWebCidExchangDiamond:// CID 为 6,跳转兑换宝石界面 case FUSJsWebCidExchangDiamond:// CID 为 6,跳转兑换宝石界面
{ {
FUSExchangeDiamondViewController *exchangeDiamondViewCtrl = [[FUSExchangeDiamondViewController alloc] init]; FUSExchangeDiamondViewController *exchangeDiamondViewCtrl = [[FUSExchangeDiamondViewController alloc] init];
[wkVC.navigationController pushViewController:exchangeDiamondViewCtrl animated:YES]; UIViewController *topViewController = [UIViewController fus_topViewController];
UINavigationController *navigationController = topViewController.navigationController ?: wkVC.navigationController;
[navigationController pushViewController:exchangeDiamondViewCtrl animated:YES];
break; break;
} }
case FUSJsWebCidBindPhone:// CID 为 7,跳转手机绑定界面 case FUSJsWebCidBindPhone:// CID 为 7,跳转手机绑定界面
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "FUSSocketManager.h" #import "FUSSocketManager.h"
#import "GCDAsyncSocket.h" #import "GCDAsyncSocket.h"
#import "FUSDataStatisticsManager.h" #import "FUSDataStatisticsManager.h"
#import <AFNetworking/AFNetworkReachabilityManager.h>
// socket 数据解析队列 // socket 数据解析队列
static dispatch_queue_t socket_queue; static dispatch_queue_t socket_queue;
...@@ -29,15 +30,16 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -29,15 +30,16 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
@implementation FUSSocketManager @implementation FUSSocketManager
{ {
GCDAsyncSocket *mSocket; // socket对象 GCDAsyncSocket *mSocket; // socket对象
NSArray<NSDictionary *> *mIPList; NSArray<NSDictionary *> *mIPList;
NSInteger mIPIndex; NSInteger mIPIndex;
NSString *mHost; // 主机名(IP地址) NSString *mHost; // 主机名(IP地址)
int mPort; // 端口号 int mPort; // 端口号
int mReconnectCount; // 重连次数 int mReconnectCount; // 重连次数
AFNetworkReachabilityStatus mLastNetworkStatus;
ConnectBlock mConnectBlock; // Socket连接回调 ConnectBlock mConnectBlock; // Socket连接回调
StatusBlock mStatusBlock; // 连接状态回调 StatusBlock mStatusBlock; // 连接状态回调
} }
...@@ -50,6 +52,38 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -50,6 +52,38 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
return [[self alloc] init]; return [[self alloc] init];
} }
- (instancetype)init
{
self = [super init];
if (self) {
mLastNetworkStatus = AFNetworkReachabilityStatusUnknown;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(fus_networkReachabilityChanged:)
name:AFNetworkingReachabilityDidChangeNotification
object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)fus_networkReachabilityChanged:(NSNotification *)notification
{
AFNetworkReachabilityStatus status = [notification.userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
BOOL wasOffline = mLastNetworkStatus == AFNetworkReachabilityStatusNotReachable;
mLastNetworkStatus = status;
// Reachability may recover before TCP reports a disconnect, leaving the socket
// half-open. Recreate it once when connectivity returns.
if (wasOffline && status > AFNetworkReachabilityStatusNotReachable && mHost.length > 0 && mPort > 0) {
FUSLogInfo(@"--->网络恢复,主动检查Socket连接");
[self fus_socketReconnectWithBlock:nil];
}
}
#pragma mark -- Socket相关类方法 #pragma mark -- Socket相关类方法
...@@ -85,22 +119,22 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -85,22 +119,22 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
FUSLogInfo(@"--->Socket连接失败, host或port为空"); FUSLogInfo(@"--->Socket连接失败, host或port为空");
return; return;
} }
// 先切断Socket // 先切断Socket
[self fus_cutOffSocketWithState:SocketOfflineByConnecting]; [self fus_cutOffSocketWithState:SocketOfflineByConnecting];
[[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketReconnectingNotification object:@{@"host":host,@"port":@(port)}]; [[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketReconnectingNotification object:@{@"host":host,@"port":@(port)}];
// 设置域名/端口号 // 设置域名/端口号
mHost = host; mHost = host;
mPort = port; mPort = port;
// 设置回调 // 设置回调
mConnectBlock = block; mConnectBlock = block;
// 上报统计 // 上报统计
[FUSDataStatisticsManager fus_startSocketConnect]; [FUSDataStatisticsManager fus_startSocketConnect];
mSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()]; mSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
// 连接Socket, 打印错误消息 // 连接Socket, 打印错误消息
NSError *error = nil; NSError *error = nil;
[mSocket connectToHost:host onPort:port withTimeout:10 error:&error]; [mSocket connectToHost:host onPort:port withTimeout:10 error:&error];
...@@ -119,7 +153,7 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -119,7 +153,7 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
if (mIPIndex >= mIPList.count) { if (mIPIndex >= mIPList.count) {
mIPIndex = 0; mIPIndex = 0;
} }
NSDictionary *ipDict = mIPList[mIPIndex]; NSDictionary *ipDict = mIPList[mIPIndex];
[self fus_socketConnectWithHost:ipDict[@"ip"] port:[ipDict[@"port"] intValue] block:block]; [self fus_socketConnectWithHost:ipDict[@"ip"] port:[ipDict[@"port"] intValue] block:block];
} }
...@@ -136,7 +170,7 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -136,7 +170,7 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
FUSLogInfo(@"--->发送Socket数据失败,data数据为空"); FUSLogInfo(@"--->发送Socket数据失败,data数据为空");
return; return;
} }
// 发送Socket数据 // 发送Socket数据
if (mSocket) { if (mSocket) {
[mSocket writeData:data withTimeout:MSG_TIMEOU tag:tag]; [mSocket writeData:data withTimeout:MSG_TIMEOU tag:tag];
...@@ -186,13 +220,13 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -186,13 +220,13 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
FUSLogInfo(@"--->Socket 主动切断"); FUSLogInfo(@"--->Socket 主动切断");
// 设置userData,标记为用户主动切断 // 设置userData,标记为用户主动切断
mSocket.userData = @(socketStatus); mSocket.userData = @(socketStatus);
// 取消Socket代理 // 取消Socket代理
[mSocket setDelegate:nil]; [mSocket setDelegate:nil];
// 断开Socket连接 // 断开Socket连接
[mSocket disconnect]; [mSocket disconnect];
// 制空Socket // 制空Socket
mSocket = nil; mSocket = nil;
} }
...@@ -201,25 +235,25 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -201,25 +235,25 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
#pragma mark -- AsyncSocketDelegate相关方法 #pragma mark -- AsyncSocketDelegate相关方法
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port - (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
{ {
[FUSDataStatisticsManager fus_socketConnectSucceedWithIp:mHost port:@(mPort).description]; [FUSDataStatisticsManager fus_socketConnectSucceedWithIp:mHost port:@(mPort).description];
FUSLogInfo(@"--->Socket 连接成功 host=%@,port=%d",host,port); FUSLogInfo(@"--->Socket 连接成功 host=%@,port=%d",host,port);
[[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketReconnectedNotification object:@{@"host":host,@"port":@(port)}]; [[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketReconnectedNotification object:@{@"host":host,@"port":@(port)}];
// Socket连接成功回调 // Socket连接成功回调
if (mConnectBlock) { if (mConnectBlock) {
mConnectBlock(YES); mConnectBlock(YES);
mConnectBlock = nil; mConnectBlock = nil;
} }
// Socket状态回调 // Socket状态回调
if (mStatusBlock) { if (mStatusBlock) {
mStatusBlock(SocketOnline); mStatusBlock(SocketOnline);
} }
// 重连次数归0 // 重连次数归0
mReconnectCount = 0; mReconnectCount = 0;
// 开始监听读取数据 // 开始监听读取数据
[mSocket readDataWithTimeout:MSG_TIMEOU tag:MSG_TAG]; [mSocket readDataWithTimeout:MSG_TIMEOU tag:MSG_TAG];
} }
...@@ -228,41 +262,41 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -228,41 +262,41 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
{ {
NSNumber *userData = sock.userData; NSNumber *userData = sock.userData;
NSInteger userDataValue = userData.integerValue; NSInteger userDataValue = userData.integerValue;
if (userDataValue == SocketOfflineByServer) { if (userDataValue == SocketOfflineByUser) {
// 用户主动断开
FUSLogInfo(@"--->socket断开连接, 用户主动断开");
mReconnectCount = 0; // 重连次数归0
// Socket状态回调
if (mStatusBlock) mStatusBlock(SocketOfflineByUser);
} else if (userDataValue == SocketOfflineByConnecting) {
FUSLogInfo(@"--->socket断开连接, 正在重建连接");
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketDisReconnectNotification object:@{@"host":mHost,@"port":@(mPort)}]; [[NSNotificationCenter defaultCenter] postNotificationName:kFUSSocketDisReconnectNotification object:@{@"host":mHost,@"port":@(mPort)}];
// v6.1.0 只要连接不上,就发送统计 // v6.1.0 只要连接不上,就发送统计
[FUSDataStatisticsManager fus_socketConnectFailed:[NSString stringWithFormat:@"%zd",userDataValue] ip:mHost port:@(mPort).description]; [FUSDataStatisticsManager fus_socketConnectFailed:[NSString stringWithFormat:@"%zd",userDataValue] ip:mHost port:@(mPort).description];
// 服务器掉线 // 服务器掉线或弱网异常断开
if (mReconnectCount < 100) { if (mReconnectCount < 100) {
// Socket状态回调 // Socket状态回调
if (mStatusBlock) mStatusBlock(SocketWillOfflineByServer); if (mStatusBlock) mStatusBlock(SocketWillOfflineByServer);
// Socket重连3次 // Socket重连3次
mReconnectCount ++; mReconnectCount ++;
[self performSelector:@selector(fus_socketReconnectWithBlock:) withObject:nil afterDelay:mReconnectCount <= 60 ? mReconnectCount : 60]; [self performSelector:@selector(fus_socketReconnectWithBlock:) withObject:nil afterDelay:mReconnectCount <= 60 ? mReconnectCount : 60];
FUSLogInfo(@"--->socket断开连接, 自动重连%d次", mReconnectCount); FUSLogInfo(@"--->socket断开连接, 自动重连%d次", mReconnectCount);
}else{ }else{
// Socket连接失败 // Socket连接失败
FUSLogInfo(@"--->socket断开连接, 自动重连失败"); FUSLogInfo(@"--->socket断开连接, 自动重连失败");
mReconnectCount = 0; // 重连次数归0 mReconnectCount = 0; // 重连次数归0
// Socket状态回调 // Socket状态回调
if (mStatusBlock) mStatusBlock(SocketOfflineByServer); if (mStatusBlock) mStatusBlock(SocketOfflineByServer);
} }
}else if(userDataValue == SocketOfflineByUser){
// 用户主动断开
FUSLogInfo(@"--->socket断开连接, 用户主动断开");
mReconnectCount = 0; // 重连次数归0
// Socket状态回调
if (mStatusBlock) mStatusBlock(SocketOfflineByUser);
} else {
FUSLogInfo(@"--->socket断开连接, 其他原因断开断开 %zd",userDataValue);
} }
} }
...@@ -273,12 +307,12 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调 ...@@ -273,12 +307,12 @@ typedef void(^StatusBlock) (SocketStatus status); // 状态回调
FUSLogInfo(@"-->接受Socket数据错误,接收到的Data为空"); FUSLogInfo(@"-->接受Socket数据错误,接收到的Data为空");
return; return;
} }
// 通过回调,将消息数据发送到消息中心 // 通过回调,将消息数据发送到消息中心
if ([self.delegate respondsToSelector:@selector(socketAcceptMessageWithData:tag:)]) { if ([self.delegate respondsToSelector:@selector(socketAcceptMessageWithData:tag:)]) {
[self.delegate socketAcceptMessageWithData:data tag:tag]; [self.delegate socketAcceptMessageWithData:data tag:tag];
} }
// 开始监听读取数据 // 开始监听读取数据
[mSocket readDataWithTimeout:MSG_TIMEOU tag:MSG_TAG]; [mSocket readDataWithTimeout:MSG_TIMEOU tag:MSG_TAG];
} }
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
static const NSInteger kFUSSocketMaxMissedHeartbeatCount = 2;
static const NSTimeInterval kFUSSocketMinHeartbeatTimeout = 60;
@interface FUSSocketMessageCenter() <FUSSocketDelegate> @interface FUSSocketMessageCenter() <FUSSocketDelegate>
@end @end
...@@ -27,16 +30,19 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -27,16 +30,19 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
@implementation FUSSocketMessageCenter @implementation FUSSocketMessageCenter
{ {
NSTimer *mConnectTimer; // 计时器 NSTimer *mConnectTimer; // 计时器
FUSSocketManager *mSocketManager; // Socket管理对象 FUSSocketManager *mSocketManager; // Socket管理对象
FUSSocketMessageQueue *mSocketQueue; // Socket消息队列对象 FUSSocketMessageQueue *mSocketQueue; // Socket消息队列对象
FUSPublicSocketMessageDBOperate *mSockeDBOperate; // 数据库操作助手 FUSPublicSocketMessageDBOperate *mSockeDBOperate; // 数据库操作助手
ConnectBlock mConnectBlock; // Socket连接回调 ConnectBlock mConnectBlock; // Socket连接回调
NSTimeInterval mHeartbeatInterval; NSTimeInterval mHeartbeatInterval;
NSInteger mMissedHeartbeatCount;
NSTimeInterval mLastSocketReceiveTime;
BOOL mIsReconnectingForHeartbeat;
} }
...@@ -171,7 +177,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -171,7 +177,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
{ {
// 取消心跳定时器 // 取消心跳定时器
[mConnectTimer invalidate]; [mConnectTimer invalidate];
// 参数空值判断 // 参数空值判断
if ([NSArray isNull:ipList]) { if ([NSArray isNull:ipList]) {
FUSLogInfo(@"--->Socket连接失败,host或port为空"); FUSLogInfo(@"--->Socket连接失败,host或port为空");
...@@ -186,7 +192,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -186,7 +192,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
if (block) block(NO); if (block) block(NO);
return; return;
} }
// 设置ConnectBlock // 设置ConnectBlock
mConnectBlock = block; mConnectBlock = block;
...@@ -205,6 +211,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -205,6 +211,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
*/ */
- (void)fus_socketReconnectWithBlock:(void (^)(BOOL isSuccess))block - (void)fus_socketReconnectWithBlock:(void (^)(BOOL isSuccess))block
{ {
mMissedHeartbeatCount = 0;
[mSocketManager fus_socketReconnectWithBlock:block]; [mSocketManager fus_socketReconnectWithBlock:block];
} }
...@@ -223,31 +230,34 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -223,31 +230,34 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
mSocketQueue = [FUSSocketMessageQueue fus_queue]; mSocketQueue = [FUSSocketMessageQueue fus_queue];
// 发送Socket验证消息 // 发送Socket验证消息
[FUSSocketMessageHelper fus_sendSocketVerifyMessageWithBlock:^(NSDictionary *dataDict) { [FUSSocketMessageHelper fus_sendSocketVerifyMessageWithBlock:^(NSDictionary *dataDict) {
int code = [[dataDict objectForKey:@"code"] intValue]; int code = [[dataDict objectForKey:@"code"] intValue];
if (code == 1 || code == 5) { if (code == 1 || code == 5) {
mMissedHeartbeatCount = 0;
mLastSocketReceiveTime = CFAbsoluteTimeGetCurrent();
mIsReconnectingForHeartbeat = NO;
// 发送消息队列中的离线消息 // 发送消息队列中的离线消息
[self sendMessageFromMessageQueue]; [self sendMessageFromMessageQueue];
// 每隔30s像服务器发送心跳包 // 每隔30s像服务器发送心跳包
[mConnectTimer invalidate]; [mConnectTimer invalidate];
mConnectTimer = [NSTimer scheduledTimerWithTimeInterval:[self heartbeatIntervalValue] target:[YYWeakProxy proxyWithTarget:self] selector:@selector(sendHeartbeatPacket) userInfo:nil repeats:YES]; mConnectTimer = [NSTimer scheduledTimerWithTimeInterval:[self heartbeatIntervalValue] target:[YYWeakProxy proxyWithTarget:self] selector:@selector(sendHeartbeatPacket) userInfo:nil repeats:YES];
[mConnectTimer fire]; [mConnectTimer fire];
if (mConnectBlock) mConnectBlock(YES); if (mConnectBlock) mConnectBlock(YES);
mConnectBlock = nil; mConnectBlock = nil;
if (block) block(status); if (block) block(status);
[[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(SocketOnline), @"code":@(code)}]; [[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(SocketOnline), @"code":@(code)}];
}else{ }else{
// // 取消发送心跳包 // // 取消发送心跳包
// [mConnectTimer invalidate]; // [mConnectTimer invalidate];
[self fus_cutOffSocket]; [self fus_cutOffSocket];
if (mConnectBlock) mConnectBlock(NO); if (mConnectBlock) mConnectBlock(NO);
mConnectBlock = nil; mConnectBlock = nil;
if (block) block(status); if (block) block(status);
[[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(SocketErrorByServer), @"code":@(code)}]; [[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(SocketErrorByServer), @"code":@(code)}];
} }
...@@ -256,10 +266,10 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -256,10 +266,10 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
// // 取消发送心跳包 // // 取消发送心跳包
// [mConnectTimer invalidate]; // [mConnectTimer invalidate];
[self fus_cutOffSocket]; [self fus_cutOffSocket];
if (mConnectBlock) mConnectBlock(NO); if (mConnectBlock) mConnectBlock(NO);
mConnectBlock = nil; mConnectBlock = nil;
if (block) block(status); if (block) block(status);
[[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(status), @"code":@(-1)}]; [[NSNotificationCenter defaultCenter] postNotificationName:FUSLiveNotificationKeys.fus_SOCKET_STATUS_CHANGE object:@{@"status":@(status), @"code":@(-1)}];
} }
...@@ -283,7 +293,10 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -283,7 +293,10 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
{ {
// 取消心跳定时器 // 取消心跳定时器
[mConnectTimer invalidate]; [mConnectTimer invalidate];
mMissedHeartbeatCount = 0;
mLastSocketReceiveTime = 0;
mIsReconnectingForHeartbeat = NO;
[mSocketManager fus_cutOffSocket]; [mSocketManager fus_cutOffSocket];
} }
...@@ -311,13 +324,13 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -311,13 +324,13 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
// 打印消息 // 打印消息
if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug && messageModel.cid) FUSLogInfo(@"--->发送消息:\n%@", [messageModel fus_getDictionary]); if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug && messageModel.cid) FUSLogInfo(@"--->发送消息:\n%@", [messageModel fus_getDictionary]);
// 将消息添加到消息队列中 // 将消息添加到消息队列中
[mSocketQueue fus_addSendMessageWithModel:messageModel]; [mSocketQueue fus_addSendMessageWithModel:messageModel];
// 添加到数据库中 // 添加到数据库中
[mSockeDBOperate fus_addSocketMessageWithModel:messageModel]; [mSockeDBOperate fus_addSocketMessageWithModel:messageModel];
// 判断当前Socket是否连接 // 判断当前Socket是否连接
if ([self isConnected]) { if ([self isConnected]) {
// 发送消息队列中的消息 // 发送消息队列中的消息
...@@ -356,7 +369,27 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -356,7 +369,27 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
FUSLogInfo(@"--->发送Socket心跳包失败, 当前Socket连接断开"); FUSLogInfo(@"--->发送Socket心跳包失败, 当前Socket连接断开");
return; return;
} }
mMissedHeartbeatCount++;
NSTimeInterval now = CFAbsoluteTimeGetCurrent();
NSTimeInterval heartbeatTimeout = MAX([self heartbeatIntervalValue] * (kFUSSocketMaxMissedHeartbeatCount + 1), kFUSSocketMinHeartbeatTimeout);
BOOL hasReceiveTimeout = mLastSocketReceiveTime > 0 && now - mLastSocketReceiveTime >= heartbeatTimeout;
if (mMissedHeartbeatCount > kFUSSocketMaxMissedHeartbeatCount && hasReceiveTimeout) {
if (mIsReconnectingForHeartbeat) {
return;
}
mIsReconnectingForHeartbeat = YES;
FUSLogInfo(@"--->Socket心跳超时,主动重连");
[mConnectTimer invalidate];
[self fus_socketReconnectWithBlock:^(BOOL isSuccess) {
mIsReconnectingForHeartbeat = NO;
if (!isSuccess) {
FUSLogInfo(@"--->Socket心跳超时重连失败");
}
}];
return;
}
// 发送心跳包 // 发送心跳包
[FUSSocketMessageHelper fus_sendSocketHeartbeatMessage]; [FUSSocketMessageHelper fus_sendSocketHeartbeatMessage];
} }
...@@ -369,7 +402,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -369,7 +402,7 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
[mConnectTimer invalidate]; [mConnectTimer invalidate];
mConnectTimer = [NSTimer scheduledTimerWithTimeInterval:[self heartbeatIntervalValue] target:[YYWeakProxy proxyWithTarget:self] selector:@selector(sendHeartbeatPacket) userInfo:nil repeats:YES]; mConnectTimer = [NSTimer scheduledTimerWithTimeInterval:[self heartbeatIntervalValue] target:[YYWeakProxy proxyWithTarget:self] selector:@selector(sendHeartbeatPacket) userInfo:nil repeats:YES];
[mConnectTimer fire]; [mConnectTimer fire];
// 先发送一次 // 先发送一次
[self sendHeartbeatPacket]; [self sendHeartbeatPacket];
} }
...@@ -394,30 +427,32 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -394,30 +427,32 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
*/ */
- (void)socketAcceptMessageWithData:(NSData *)data tag:(long)tag - (void)socketAcceptMessageWithData:(NSData *)data tag:(long)tag
{ {
mMissedHeartbeatCount = 0;
mLastSocketReceiveTime = CFAbsoluteTimeGetCurrent();
// 将消息添加到消息队列 // 将消息添加到消息队列
[mSocketQueue fus_addAcceptMessageWithData:data]; [mSocketQueue fus_addAcceptMessageWithData:data];
if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug) FUSLogInfo(@"--->收到消息:socketAcceptMessageWithData\n"); if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug) FUSLogInfo(@"--->收到消息:socketAcceptMessageWithData\n");
// 检测包的完整性 // 检测包的完整性
if (![mSocketQueue fus_checkDataAvailable]) { if (![mSocketQueue fus_checkDataAvailable]) {
FUSLogInfo(@"--->socket完整性欠缺:socketAcceptMessageWithData\n"); FUSLogInfo(@"--->socket完整性欠缺:socketAcceptMessageWithData\n");
[self fus_socketReconnectWithBlock:^(BOOL isSuccess) { [self fus_socketReconnectWithBlock:^(BOOL isSuccess) {
}]; }];
return; return;
} }
// 读取消息队列中的消息 // 读取消息队列中的消息
while ([mSocketQueue fus_isHaveAcceptMessage]) { while ([mSocketQueue fus_isHaveAcceptMessage]) {
// 读取队列中消息 // 读取队列中消息
FUSSocketMessageModel *messageModel = [mSocketQueue readAcceptMessage]; FUSSocketMessageModel *messageModel = [mSocketQueue readAcceptMessage];
NSDictionary *jsonDict = [messageModel fus_getJsonDict]; NSDictionary *jsonDict = [messageModel fus_getJsonDict];
NSString *showAppBinary = jsonDict[@"showAppBinary"]; NSString *showAppBinary = jsonDict[@"showAppBinary"];
if ([NSString isNull:showAppBinary] == NO) { if ([NSString isNull:showAppBinary] == NO) {
if (showAppBinary.length >= 2) { if (showAppBinary.length >= 2) {
if ([[showAppBinary substringWithRange:NSMakeRange(showAppBinary.length - 2, 1)] boolValue] == NO) { if ([[showAppBinary substringWithRange:NSMakeRange(showAppBinary.length - 2, 1)] boolValue] == NO) {
/// 如果传了showAppBinary, /// 如果传了showAppBinary,
/// 并且showAppBinary大于等于2位(因为fusi是第二位的布尔值表示,且这个数值是从右往左读的,所以要取倒数第二位的数值) /// 并且showAppBinary大于等于2位(因为fusi是第二位的布尔值表示,且这个数值是从右往左读的,所以要取倒数第二位的数值)
...@@ -430,13 +465,13 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -430,13 +465,13 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
} }
// 打印收到的消息 // 打印收到的消息
if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug /*&& messageModel.cid*/) FUSLogInfo(@"--->收到消息111:\n%@", [messageModel fus_getDictionary]); if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug /*&& messageModel.cid*/) FUSLogInfo(@"--->收到消息111:\n%@", [messageModel fus_getDictionary]);
// 判断消息是否为空 // 判断消息是否为空
if ([NSObject isNullWithObject:messageModel]) { if ([NSObject isNullWithObject:messageModel]) {
FUSLogInfo(@"--->接收SocketMessage数据错误,读取消息队列中数据为空"); FUSLogInfo(@"--->接收SocketMessage数据错误,读取消息队列中数据为空");
continue; continue;
} }
// 将消息发布通知到界面 // 将消息发布通知到界面
[self postNotificationWithMessage:messageModel]; [self postNotificationWithMessage:messageModel];
} }
...@@ -452,21 +487,21 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调 ...@@ -452,21 +487,21 @@ typedef void(^ConnectBlock)(BOOL isSuccess); // 连接回调
FUSLogInfo(@"--->接收SocketMessage数据错误,messageModel数据为空"); FUSLogInfo(@"--->接收SocketMessage数据错误,messageModel数据为空");
return; return;
} }
// 发送消息回执 // 发送消息回执
[FUSSocketMessageHelper fus_sendMessageRecept:messageModel]; [FUSSocketMessageHelper fus_sendMessageRecept:messageModel];
if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug) FUSLogInfo(@"--->postNotificationName:%@\n",STR(messageModel.cid)); if ([FUSConfig sharedInstanced].devConfigs.enableSocketDebug) FUSLogInfo(@"--->postNotificationName:%@\n",STR(messageModel.cid));
// 发送cid通知 // 发送cid通知
[[NSNotificationCenter defaultCenter] postNotificationName:STR(messageModel.cid) object:messageModel]; [[NSNotificationCenter defaultCenter] postNotificationName:STR(messageModel.cid) object:messageModel];
// 更新宝石 // 更新宝石
if ([[messageModel fus_getJsonDict][@"pushInfo"][@"type"] integerValue] == 15) { if ([[messageModel fus_getJsonDict][@"pushInfo"][@"type"] integerValue] == 15) {
[FUSRouter.userRouter fus_getUserInfosWithType:ReadServerBegin success:nil failure:nil]; [FUSRouter.userRouter fus_getUserInfosWithType:ReadServerBegin success:nil failure:nil];
} }
[FUSRouter.chatRouter fus_postNotificationWithMessage:messageModel]; [FUSRouter.chatRouter fus_postNotificationWithMessage:messageModel];
// 添加到数据库中 // 添加到数据库中
[mSockeDBOperate fus_addSocketMessageWithModel:messageModel]; [mSockeDBOperate fus_addSocketMessageWithModel:messageModel];
} }
......
...@@ -123,11 +123,13 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur ...@@ -123,11 +123,13 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur
isOfficial:(BOOL)isOfficial { isOfficial:(BOOL)isOfficial {
NSString *gotopage = isOfficial ? @"officialrecharge" : @"otherrecharge"; NSString *gotopage = isOfficial ? @"officialrecharge" : @"otherrecharge";
NSString *roomId = FUSConfig.sharedInstanced.liveConfigs.currentRoomId ?: @"";
NSString *userId = [FUSCacheDataShare shareStore].userDetailInfo.uid ?: @"";
if (from == FUSFromLiveRoom) { if (from == FUSFromLiveRoom) {
if (rechargePageFrom == FUSRechargePageFromGEMsLack) { if (rechargePageFrom == FUSRechargePageFromGEMsLack) {
[FUSTalkingData fus_trackEvent:FUSLiveEventTrackParams.fus_EVENT_ROOM_LACKGEM_RECHARGE label:@"" parameters:@{@"roomid":FUSConfig.sharedInstanced.liveConfigs.currentRoomId,@"userid":[FUSCacheDataShare shareStore].userDetailInfo.uid,@"gotopage":gotopage}]; [FUSTalkingData fus_trackEvent:FUSLiveEventTrackParams.fus_EVENT_ROOM_LACKGEM_RECHARGE label:@"" parameters:@{@"roomid":roomId,@"userid":userId,@"gotopage":gotopage}];
} else if (rechargePageFrom == FUSRechargePageFromRoomGiftGEMsLack) { } else if (rechargePageFrom == FUSRechargePageFromRoomGiftGEMsLack) {
[FUSTalkingData fus_trackEvent:FUSLiveEventTrackParams.fus_EVENT_ROOM_GIFT_SEND_LACKGEM_OFFICAL_RECHARGE label:@"" parameters:@{@"roomid":FUSConfig.sharedInstanced.liveConfigs.currentRoomId,@"userid":[FUSCacheDataShare shareStore].userDetailInfo.uid,@"gotopage":gotopage}]; [FUSTalkingData fus_trackEvent:FUSLiveEventTrackParams.fus_EVENT_ROOM_GIFT_SEND_LACKGEM_OFFICAL_RECHARGE label:@"" parameters:@{@"roomid":roomId,@"userid":userId,@"gotopage":gotopage}];
} }
} }
...@@ -152,7 +154,8 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur ...@@ -152,7 +154,8 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur
break; break;
} }
[FUSTalkingData fus_trackEvent:kEVENT_RECHARGE_OFFICIAL_PAGE label:@"" parameters:@{@"userid":[FUSCacheDataShare shareStore].userDetailInfo.uid,@"PKG":FUSConfig.sharedInstanced.appConfigs.appPKG,@"source":source}]; NSString *appPKG = FUSConfig.sharedInstanced.appConfigs.appPKG ?: @"";
[FUSTalkingData fus_trackEvent:kEVENT_RECHARGE_OFFICIAL_PAGE label:@"" parameters:@{@"userid":userId,@"PKG":appPKG,@"source":source}];
NSString *firebaseSource = @"others"; NSString *firebaseSource = @"others";
switch (from) { switch (from) {
...@@ -174,7 +177,7 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur ...@@ -174,7 +177,7 @@ NSString * const kEVENT_RECHARGE_OFFICIAL_PAGE_RETURN = @"officialrecharge_retur
} }
// Firebase 统计 // Firebase 统计
[FIRAnalytics logEventWithName:@"topuppage" parameters:@{@"useruid":[FUSCacheDataShare shareStore].userDetailInfo.uid,@"source":firebaseSource}]; [FIRAnalytics logEventWithName:@"topuppage" parameters:@{@"useruid":userId,@"source":firebaseSource}];
} }
} }
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ /* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
00E501FF2E0543A800579DB0 /* Exceptions for "NotificationService" folder in "NotificationService" target */ = { 00E501FF2E0543A800579DB0 /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet; isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = ( membershipExceptions = (
"NotificationService-Info.plist", "NotificationService-Info.plist",
...@@ -112,18 +112,7 @@ ...@@ -112,18 +112,7 @@
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ /* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
/* Begin PBXFileSystemSynchronizedRootGroup section */ /* Begin PBXFileSystemSynchronizedRootGroup section */
00E501F42E0543A800579DB0 /* NotificationService */ = { 00E501F42E0543A800579DB0 /* NotificationService */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (00E501FF2E0543A800579DB0 /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = NotificationService; sourceTree = "<group>"; };
isa = PBXFileSystemSynchronizedRootGroup;
exceptions = (
00E501FF2E0543A800579DB0 /* Exceptions for "NotificationService" folder in "NotificationService" target */,
);
explicitFileTypes = {
};
explicitFolders = (
);
path = NotificationService;
sourceTree = "<group>";
};
/* End PBXFileSystemSynchronizedRootGroup section */ /* End PBXFileSystemSynchronizedRootGroup section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
...@@ -444,10 +433,14 @@ ...@@ -444,10 +433,14 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-frameworks.sh\"\n";
...@@ -461,10 +454,14 @@ ...@@ -461,10 +454,14 @@
inputFileListPaths = ( inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources-${CONFIGURATION}-input-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources-${CONFIGURATION}-input-files.xcfilelist",
); );
inputPaths = (
);
name = "[CP] Copy Pods Resources"; name = "[CP] Copy Pods Resources";
outputFileListPaths = ( outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources-${CONFIGURATION}-output-files.xcfilelist", "${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources-${CONFIGURATION}-output-files.xcfilelist",
); );
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources.sh\"\n"; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-FuSiLive/Pods-FuSiLive-resources.sh\"\n";
...@@ -694,7 +691,7 @@ ...@@ -694,7 +691,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20260522; CURRENT_PROJECT_VERSION = 20260523;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
...@@ -729,7 +726,7 @@ ...@@ -729,7 +726,7 @@
"$(PROJECT_DIR)/FuSiLive/Classes/FUSModules/FUSLiveModule/NewLive/Main/View/StreamView/Beauty/ByteDanceBeauty", "$(PROJECT_DIR)/FuSiLive/Classes/FUSModules/FUSLiveModule/NewLive/Main/View/StreamView/Beauty/ByteDanceBeauty",
); );
LOCALIZATION_PREFERS_STRING_CATALOGS = NO; LOCALIZATION_PREFERS_STRING_CATALOGS = NO;
MARKETING_VERSION = 10.0.1; MARKETING_VERSION = 10.1.1;
OTHER_CFLAGS = ( OTHER_CFLAGS = (
"$(inherited)", "$(inherited)",
"-isystem", "-isystem",
...@@ -959,7 +956,7 @@ ...@@ -959,7 +956,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements; CODE_SIGN_ENTITLEMENTS = FuSiLive/FuSiLive.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 20260522; CURRENT_PROJECT_VERSION = 20260523;
DEFINES_MODULE = YES; DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 6GG26BHUMC; DEVELOPMENT_TEAM = 6GG26BHUMC;
ENABLE_ON_DEMAND_RESOURCES = NO; ENABLE_ON_DEMAND_RESOURCES = NO;
...@@ -994,7 +991,7 @@ ...@@ -994,7 +991,7 @@
"$(PROJECT_DIR)/FuSiLive/Classes/FUSModules/FUSLiveModule/NewLive/Main/View/StreamView/Beauty/ByteDanceBeauty", "$(PROJECT_DIR)/FuSiLive/Classes/FUSModules/FUSLiveModule/NewLive/Main/View/StreamView/Beauty/ByteDanceBeauty",
); );
LOCALIZATION_PREFERS_STRING_CATALOGS = NO; LOCALIZATION_PREFERS_STRING_CATALOGS = NO;
MARKETING_VERSION = 10.0.1; MARKETING_VERSION = 10.1.1;
OTHER_CFLAGS = ( OTHER_CFLAGS = (
"$(inherited)", "$(inherited)",
"-isystem", "-isystem",
......
...@@ -100,7 +100,10 @@ class FUSPKPunishTypesView: FUSBaseView { ...@@ -100,7 +100,10 @@ class FUSPKPunishTypesView: FUSBaseView {
var typesBtnList: [UIButton] = .init() var typesBtnList: [UIButton] = .init()
/// 最大选择个数 /// 最大选择个数
let vsPunishMaxLimit: Int = FUSCacheDataShare.shareStore().settingInitDataModel.vsPunishMaxLimit let vsPunishMaxLimit: Int = max(
FUSCacheDataShare.shareStore().settingInitDataModel?.vsPunishMaxLimit ?? 1,
1
)
override func makeUI() { override func makeUI() {
super.makeUI() super.makeUI()
......
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