Commit 2ec7e932 by suolong

添加11038socket

parent 0a936b0b
...@@ -98,6 +98,9 @@ ...@@ -98,6 +98,9 @@
/// 付费房实时变化的业务数据推送 /// 付费房实时变化的业务数据推送
#define ROOM_CID_PAYROOM_REALTIME_DATA 11037 #define ROOM_CID_PAYROOM_REALTIME_DATA 11037
/// 限时表演(Ticket Show)实时业务数据推送:内部会再用 dataType 区分子类型
#define ROOM_CID_TICKET_SHOW_REALTIME_DATA 11038
// 更新直播间互动游戏开关状态socket // 更新直播间互动游戏开关状态socket
#define ROOM_CID_liveInteractionGameStateDidChanged 20204 #define ROOM_CID_liveInteractionGameStateDidChanged 20204
// 更新直播间礼物互动开关状态socket(主播/观众都会收到) // 更新直播间礼物互动开关状态socket(主播/观众都会收到)
...@@ -131,5 +134,3 @@ ...@@ -131,5 +134,3 @@
#define ROOM_CID_anchorDidCloseMic 20201 #define ROOM_CID_anchorDidCloseMic 20201
// 更新本场直播主题内容socket // 更新本场直播主题内容socket
#define ROOM_CID_LiveThemeDidChanged 20202 #define ROOM_CID_LiveThemeDidChanged 20202
...@@ -80,6 +80,8 @@ ...@@ -80,6 +80,8 @@
{ {
[[NSNotificationCenter defaultCenter]removeObserver:self]; [[NSNotificationCenter defaultCenter]removeObserver:self];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(recieveReceiptNotification:) name:STR(ROOM_CID_TEXT) object:nil]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(recieveReceiptNotification:) name:STR(ROOM_CID_TEXT) object:nil];
// 11038:限时表演实时推送(dataType 细分业务)
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fus_receiveTicketShowRealtimeDataNotification:) name:STR(ROOM_CID_TICKET_SHOW_REALTIME_DATA) object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fus_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
} }
...@@ -115,6 +117,138 @@ ...@@ -115,6 +117,138 @@
} }
} }
- (void)fus_receiveTicketShowRealtimeDataNotification:(NSNotification *)notification
{
FUSSocketMessageModel *socketModel = notification.object;
NSDictionary *jsonDict = [socketModel fus_getJsonDict];
if (![jsonDict isKindOfClass:NSDictionary.class] || jsonDict.count == 0) {
return;
}
if (FUSLiveHelper.shareInstance.liveType == FUSLiveTypeNone) {
return;
}
NSString *roomId = [NSString stringWithObject:jsonDict[@"roomId"]];
NSString *currentRoomId = FUSLiveHelper.shareInstance.roomInfoModel.roomId;
if (![NSString isNull:roomId] && ![NSString isNull:currentRoomId] && ![roomId isEqualToString:currentRoomId]) {
// 不是当前直播间的数据,直接丢弃,避免串房刷新
return;
}
// 兼容两种结构:
// 1) payload 直接平铺在 jsonDict
// 2) payload 放在 jsonDict.data 内
NSDictionary *payload = jsonDict;
NSDictionary *dataDict = payload[@"data"];
if ([dataDict isKindOfClass:NSDictionary.class] && dataDict.count > 0) {
payload = dataDict;
}
// 目前先只实现 dataType=1(主播开启集票/推送当前集票阶段信息)
NSInteger dataType = [payload[@"dataType"] integerValue];
if (dataType <= 0) {
dataType = [jsonDict[@"dataType"] integerValue];
}
if (dataType != 1) {
return;
}
// 复用 toggle 接口返回模型:字段与 socket 推送结构保持一致(targetTicketNum/finalTicketNum/stageData/mvpInfo 等)
FUSTicketShowCollectTicketToggleResultModel *model = [FUSTicketShowCollectTicketToggleResultModel fus_modelWithDict:payload];
dispatch_async(dispatch_get_main_queue(), ^{
// 优先复用已有磨砂条所在容器;否则按直播间层级兜底找一个合适的展示层
UIView *onView = self.showTimeFrostedView.superview;
if (!onView) {
onView = [[FUSLiveHelper shareInstance].currentFunctionView fus_viewWithLayer:FUSLiveFunctionLayerFunctionButtons];
}
if (!onView) {
onView = [FUSLiveHelper shareInstance].currentLiveVCView;
}
if (!onView) {
onView = [UIViewController fus_topViewController].view;
}
if (!onView) {
return;
}
FUSLiveShowTimeCollectFrostedView *bar = [FUSLiveShowTimeCollectFrostedView fus_showOnView:onView];
self.showTimeFrostedView = bar;
// roundId 用于主播端取消集票
self.showTimeRoundId = (model.stageData.roundId.length > 0 ? model.stageData.roundId : @"");
if (FUSLiveHelper.shareInstance.liveType == FUSLiveTypeAnchor) {
__weak typeof(self) weakSelf = self;
bar.cancelHandler = ^{
__strong typeof(weakSelf) cancelSelf = weakSelf;
if (!cancelSelf) {
return;
}
NSString *cancelRoundId = cancelSelf.showTimeRoundId;
if ([NSString isNull:cancelRoundId]) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"当前回合信息异常"]];
return;
}
FUSRoomInfoModel *roomInfoModel = FUSLiveHelper.shareInstance.roomInfoModel;
NSString *cancelRoomId = (model.stageData.roomId.length > 0 ? model.stageData.roomId : roomInfoModel.roomId);
NSString *cancelChannelId = (model.stageData.channelId.length > 0 ? model.stageData.channelId : roomInfoModel.channelId);
if ([NSString isNull:cancelRoomId] || [NSString isNull:cancelChannelId]) {
[FUSDialogView fus_showDialog:[NSString fus_localString:@"当前房间信息异常"]];
return;
}
[FUSLoadingView fus_showProgressViewWithMessage:@""];
[FUSLiveHttpHelper fus_ticketShowCollectTicketToggleWithRoomId:cancelRoomId channelId:cancelChannelId toggleType:-1 roundId:cancelRoundId ticketTargetNum:0 showTheme:nil succeed:^(FUSTicketShowCollectTicketToggleResultModel * _Nonnull cancelModel) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSLoadingView fus_dismissProgressView];
[cancelSelf fus_destroyShowTimeFrostedIfNeeded];
cancelSelf.showTimeRoundId = @"";
});
} failure:^(NSString * _Nonnull msg, NSInteger code) {
dispatch_async(dispatch_get_main_queue(), ^{
[FUSLoadingView fus_dismissProgressView];
[FUSDialogView fus_showDialog:([NSString isNull:msg] ? [NSString fus_localString:@"取消失败"] : msg)];
});
}];
};
} else {
bar.cancelHandler = nil;
}
NSInteger target = MAX(0, model.targetTicketNum);
NSInteger finalNum = MAX(0, model.finalTicketNum);
NSInteger remaining = MAX(0, target - finalNum);
CGFloat progress = (target > 0 ? ((CGFloat)finalNum / (CGFloat)target) : 0);
NSString *remainingText = [NSString stringWithFormat:[NSString fus_localString:@"还差 %zd 张!"], (NSInteger)remaining];
NSString *themeText = (model.showTheme.length > 0 ? model.showTheme : [NSString fus_localString:@"限时表演"]);
// 后端给的是“阶段总时长 showStatusTime”和“剩余时间 remaintime”(毫秒)
// 这里换算成开始时间戳(秒),用于磨砂条内部倒计时展示
NSTimeInterval nowSec = [[NSDate date] timeIntervalSince1970];
NSTimeInterval startTimestamp = nowSec;
NSInteger durationMs = model.stageData.showStatusTime;
NSInteger remainMs = model.stageData.remaintime;
if (durationMs > 0 && remainMs >= 0 && remainMs <= durationMs) {
NSTimeInterval elapsedSec = ((NSTimeInterval)(durationMs - remainMs)) / 1000.0;
startTimestamp = nowSec - MAX(0, elapsedSec);
}
// MVP 用户信息用于顶部展示(无则不展示)
FUSOnlineUserModel *mvpUser = model.mvpInfo.mvpUserInfo;
[bar fus_updateWithState:FUSLiveShowTimeCollectFrostedStateStarted
themeText:themeText
progress:progress
remainingText:remainingText
startTimestamp:startTimestamp
newTicketCount:0
userModel:mvpUser];
});
}
-(void)fus_keyboardWillHide:(NSNotification *)notifi{ -(void)fus_keyboardWillHide:(NSNotification *)notifi{
if (self.sendTextCount >= 10) { if (self.sendTextCount >= 10) {
// 发送超过10次。触发pingfen // 发送超过10次。触发pingfen
......
...@@ -395,6 +395,11 @@ static const NSInteger kFUSShowTimeCollectSeconds = 10 * 60; ...@@ -395,6 +395,11 @@ static const NSInteger kFUSShowTimeCollectSeconds = 10 * 60;
} }
} }
- (void)setCancelHandler:(void (^)(void))cancelHandler {
_cancelHandler = [cancelHandler copy];
self.cancelBtn.hidden = (_cancelHandler == nil);
}
/// 开始倒计时刷新(每秒刷新显示,触底自动停止) /// 开始倒计时刷新(每秒刷新显示,触底自动停止)
- (void)fus_startCountdownTimerIfNeeded { - (void)fus_startCountdownTimerIfNeeded {
if (self.startTimestamp <= 0) { if (self.startTimestamp <= 0) {
......
...@@ -340,7 +340,10 @@ static const NSInteger kFUSShowTimeTicketMax = 50; ...@@ -340,7 +340,10 @@ static const NSInteger kFUSShowTimeTicketMax = 50;
[self fus_refreshCountUI]; [self fus_refreshCountUI];
} }
/// 启动长按连发(首次立即触发,之后每 1 秒触发一次) /// 启动长按连发
/// - 为什么这里要“先触发一次”:系统 LongPress 会先经历 minimumPressDuration,再开始回调,
/// 如果不手动触发一次,会让用户感觉按住没反应;同时也避免首次因为多次回调导致跳到 20 的问题
/// - 行为:开始时先 +10/-10 一次,随后每 1 秒再连发一次,触到边界自动停止
- (void)fus_startLongPressTimerWithDelta:(NSInteger)delta { - (void)fus_startLongPressTimerWithDelta:(NSInteger)delta {
if (delta < 0 && self.ticketCount <= self.ticketMin) { if (delta < 0 && self.ticketCount <= self.ticketMin) {
[FUSDialogView fus_showDialog:[NSString stringWithFormat:[NSString fus_localString:@"最低%zd张"], self.ticketMin]]; [FUSDialogView fus_showDialog:[NSString stringWithFormat:[NSString fus_localString:@"最低%zd张"], self.ticketMin]];
...@@ -352,11 +355,12 @@ static const NSInteger kFUSShowTimeTicketMax = 50; ...@@ -352,11 +355,12 @@ static const NSInteger kFUSShowTimeTicketMax = 50;
} }
[self fus_stopLongPressTimer]; [self fus_stopLongPressTimer];
self.longPressDelta = delta; self.longPressDelta = delta;
[self fus_onLongPressTick];
__weak typeof(self) weakSelf = self; __weak typeof(self) weakSelf = self;
dispatch_queue_t queue = dispatch_get_main_queue(); dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
self.longPressTimer = timer; self.longPressTimer = timer;
dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, (uint64_t)(1.0 * NSEC_PER_SEC), (uint64_t)(0.05 * NSEC_PER_SEC)); dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), (uint64_t)(1.0 * NSEC_PER_SEC), (uint64_t)(0.05 * NSEC_PER_SEC));
dispatch_source_set_event_handler(timer, ^{ dispatch_source_set_event_handler(timer, ^{
[weakSelf fus_onLongPressTick]; [weakSelf fus_onLongPressTick];
}); });
......
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