1.0.18 feat:连击礼物请求加入到每 0.2s 执行一次的队列
This commit is contained in:
@@ -22,9 +22,10 @@
|
||||
|
||||
@property (nonatomic, assign) BOOL enableCombo;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *requestQueue;
|
||||
|
||||
// 用来存储 GiftReceiveInfoModel 和 NSDictionary 的元数据队列
|
||||
@property (nonatomic, strong) NSMutableArray *giftComboQueue;
|
||||
|
||||
@property (nonatomic, strong) NSMutableArray *comboFlagQueue;
|
||||
@property (nonatomic, strong) NSTimer *comboFlagTimer;
|
||||
@property (nonatomic, strong) UIView *containerView;
|
||||
@@ -65,12 +66,13 @@
|
||||
sharedInstance.giftComboQueue = [NSMutableArray array];
|
||||
sharedInstance.activeViews = [NSMutableArray array];
|
||||
sharedInstance.comboFlagQueue = [NSMutableArray array];
|
||||
sharedInstance.requestQueue = [NSMutableArray array];
|
||||
[sharedInstance startProcessingGiftComboFlagQueue];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
// 添加 GiftReceiveInfoModel 和 metadata 到队列
|
||||
//// 添加 GiftReceiveInfoModel 和 metadata 到队列
|
||||
- (void)addGiftComboWithInfo:(GiftReceiveInfoModel *)info andMetadata:(NSDictionary *)metadata {
|
||||
if (info && metadata) {
|
||||
// 将元数据打包成字典并添加到队列
|
||||
@@ -286,6 +288,7 @@
|
||||
// 定时器触发的事件处理
|
||||
dispatch_source_set_event_handler(self.timer, ^{
|
||||
[self processGiftComboQueue];
|
||||
[self processRequestQueue];
|
||||
});
|
||||
|
||||
// 启动定时器
|
||||
@@ -295,8 +298,10 @@
|
||||
// 停止处理队列
|
||||
- (void)stopProcessingQueue {
|
||||
if (self.timer) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
self.timer = nil;
|
||||
if (self.requestQueue.count == 0 && self.giftComboQueue.count == 0) {
|
||||
dispatch_source_cancel(self.timer);
|
||||
self.timer = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,9 +318,6 @@
|
||||
} else {
|
||||
// 如果队列为空,停止定时器
|
||||
[self stopProcessingQueue];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
NSLog(@"礼物处理完成");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -329,6 +331,20 @@
|
||||
return self.errorMessage;
|
||||
}
|
||||
|
||||
- (void)processRequestQueue {
|
||||
@synchronized (self) {
|
||||
if (self.requestQueue.count > 0) {
|
||||
// 获取并移除队列中的第一个元数据
|
||||
NSDictionary *dic = [self.requestQueue firstObject];
|
||||
[self handleSendGift:dic];
|
||||
[self.requestQueue removeObject:dic];
|
||||
} else {
|
||||
// 如果队列为空,停止定时器
|
||||
[self stopProcessingQueue];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Gift meta data
|
||||
|
||||
- (void)enableToCombo:(BOOL)enable {
|
||||
@@ -390,6 +406,50 @@
|
||||
}
|
||||
allUIDs = [allUIDs stringByAppendingString:item];
|
||||
}
|
||||
|
||||
NSDictionary *dic = @{
|
||||
@"targetUids":allUIDs,
|
||||
@"giftNum":self.giftNumPerTimes,
|
||||
@"sendType":[NSString stringWithFormat:@"%ld", GiftSendType_OnMic],
|
||||
@"giftId":[NSString stringWithFormat:@"%ld", self.giftInfo.giftId],
|
||||
@"giftSource":[NSString stringWithFormat:@"%ld", self.giftSourceType],
|
||||
@"giftType":[NSString stringWithFormat:@"%ld", self.roomSendGiftType],
|
||||
@"roomUid":self.roomUID
|
||||
};
|
||||
|
||||
[self.requestQueue addObject:dic];
|
||||
[self startProcessingQueue];
|
||||
|
||||
// @kWeakify(self);
|
||||
// [Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
// @kStrongify(self);
|
||||
// if (!self) {
|
||||
// return;
|
||||
// }
|
||||
// if (code == 200) {
|
||||
// GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
|
||||
// receive.sourceType = self.giftSourceType;
|
||||
// receive.roomSendGiftType = self.roomSendGiftType;
|
||||
// [self handleSendGiftSuccess:data];
|
||||
// } else {
|
||||
// self.errorMessage = msg;
|
||||
// self.actionCallback(ComboAction_RemovePanel);
|
||||
// self.actionCallback(ComboAction_Error);
|
||||
// }
|
||||
// }
|
||||
// targetUids:allUIDs
|
||||
// giftNum:self.giftNumPerTimes
|
||||
// sendType:[NSString stringWithFormat:@"%ld", GiftSendType_OnMic]
|
||||
// giftId:[NSString stringWithFormat:@"%ld", self.giftInfo.giftId]
|
||||
// giftSource:[NSString stringWithFormat:@"%ld", self.giftSourceType]
|
||||
// giftType:[NSString stringWithFormat:@"%ld", self.roomSendGiftType]
|
||||
// roomUid:self.roomUID
|
||||
// msg:@""
|
||||
// uid:[AccountInfoStorage instance].getUid];
|
||||
}
|
||||
|
||||
- (void)handleSendGift:(NSDictionary *)dic {
|
||||
NSString *allUIDs = [dic objectForKey:@"targetUids"];
|
||||
@kWeakify(self);
|
||||
[Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
||||
@kStrongify(self);
|
||||
@@ -398,8 +458,8 @@
|
||||
}
|
||||
if (code == 200) {
|
||||
GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
|
||||
receive.sourceType = self.giftSourceType;
|
||||
receive.roomSendGiftType = self.roomSendGiftType;
|
||||
receive.sourceType = [[dic objectForKey:@"giftSource"] integerValue];
|
||||
receive.roomSendGiftType = [[dic objectForKey:@"giftType"] integerValue];
|
||||
[self handleSendGiftSuccess:data];
|
||||
} else {
|
||||
self.errorMessage = msg;
|
||||
@@ -409,11 +469,11 @@
|
||||
}
|
||||
targetUids:allUIDs
|
||||
giftNum:self.giftNumPerTimes
|
||||
sendType:[NSString stringWithFormat:@"%ld", GiftSendType_OnMic]
|
||||
giftId:[NSString stringWithFormat:@"%ld", self.giftInfo.giftId]
|
||||
giftSource:[NSString stringWithFormat:@"%ld", self.giftSourceType]
|
||||
giftType:[NSString stringWithFormat:@"%ld", self.roomSendGiftType]
|
||||
roomUid:self.roomUID
|
||||
sendType:[dic objectForKey:@"sendType"]
|
||||
giftId:[dic objectForKey:@"giftId"]
|
||||
giftSource:[dic objectForKey:@"giftSource"]
|
||||
giftType:[dic objectForKey:@"giftType"]
|
||||
roomUid:[dic objectForKey:@"roomUid"]
|
||||
msg:@""
|
||||
uid:[AccountInfoStorage instance].getUid];
|
||||
}
|
||||
|
@@ -107,7 +107,6 @@
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// 1521 连续震动 3 次
|
||||
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
||||
|
||||
});
|
||||
|
||||
[[GiftComboManager sharedManager] sendGift];
|
||||
|
Reference in New Issue
Block a user