1.0.18 feat:连击礼物请求加入到每 0.2s 执行一次的队列

This commit is contained in:
eggmanQQQ
2024-10-21 18:31:09 +08:00
parent b34e8ccb16
commit 8c64d6fdc0
2 changed files with 74 additions and 15 deletions

View File

@@ -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];
}

View File

@@ -107,7 +107,6 @@
dispatch_async(dispatch_get_main_queue(), ^{
// 1521 3
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
});
[[GiftComboManager sharedManager] sendGift];