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, assign) BOOL enableCombo;
@property (nonatomic, strong) NSMutableArray *requestQueue;
// GiftReceiveInfoModel NSDictionary // GiftReceiveInfoModel NSDictionary
@property (nonatomic, strong) NSMutableArray *giftComboQueue; @property (nonatomic, strong) NSMutableArray *giftComboQueue;
@property (nonatomic, strong) NSMutableArray *comboFlagQueue; @property (nonatomic, strong) NSMutableArray *comboFlagQueue;
@property (nonatomic, strong) NSTimer *comboFlagTimer; @property (nonatomic, strong) NSTimer *comboFlagTimer;
@property (nonatomic, strong) UIView *containerView; @property (nonatomic, strong) UIView *containerView;
@@ -65,12 +66,13 @@
sharedInstance.giftComboQueue = [NSMutableArray array]; sharedInstance.giftComboQueue = [NSMutableArray array];
sharedInstance.activeViews = [NSMutableArray array]; sharedInstance.activeViews = [NSMutableArray array];
sharedInstance.comboFlagQueue = [NSMutableArray array]; sharedInstance.comboFlagQueue = [NSMutableArray array];
sharedInstance.requestQueue = [NSMutableArray array];
[sharedInstance startProcessingGiftComboFlagQueue]; [sharedInstance startProcessingGiftComboFlagQueue];
}); });
return sharedInstance; return sharedInstance;
} }
// GiftReceiveInfoModel metadata //// GiftReceiveInfoModel metadata
- (void)addGiftComboWithInfo:(GiftReceiveInfoModel *)info andMetadata:(NSDictionary *)metadata { - (void)addGiftComboWithInfo:(GiftReceiveInfoModel *)info andMetadata:(NSDictionary *)metadata {
if (info && metadata) { if (info && metadata) {
// //
@@ -286,6 +288,7 @@
// //
dispatch_source_set_event_handler(self.timer, ^{ dispatch_source_set_event_handler(self.timer, ^{
[self processGiftComboQueue]; [self processGiftComboQueue];
[self processRequestQueue];
}); });
// //
@@ -295,8 +298,10 @@
// //
- (void)stopProcessingQueue { - (void)stopProcessingQueue {
if (self.timer) { if (self.timer) {
dispatch_source_cancel(self.timer); if (self.requestQueue.count == 0 && self.giftComboQueue.count == 0) {
self.timer = nil; dispatch_source_cancel(self.timer);
self.timer = nil;
}
} }
} }
@@ -313,9 +318,6 @@
} else { } else {
// //
[self stopProcessingQueue]; [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; 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 #pragma mark - Gift meta data
- (void)enableToCombo:(BOOL)enable { - (void)enableToCombo:(BOOL)enable {
@@ -390,6 +406,50 @@
} }
allUIDs = [allUIDs stringByAppendingString:item]; 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); @kWeakify(self);
[Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { [Api requestSendGift:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
@kStrongify(self); @kStrongify(self);
@@ -398,8 +458,8 @@
} }
if (code == 200) { if (code == 200) {
GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data]; GiftReceiveInfoModel *receive = [GiftReceiveInfoModel modelWithJSON:data.data];
receive.sourceType = self.giftSourceType; receive.sourceType = [[dic objectForKey:@"giftSource"] integerValue];
receive.roomSendGiftType = self.roomSendGiftType; receive.roomSendGiftType = [[dic objectForKey:@"giftType"] integerValue];
[self handleSendGiftSuccess:data]; [self handleSendGiftSuccess:data];
} else { } else {
self.errorMessage = msg; self.errorMessage = msg;
@@ -409,11 +469,11 @@
} }
targetUids:allUIDs targetUids:allUIDs
giftNum:self.giftNumPerTimes giftNum:self.giftNumPerTimes
sendType:[NSString stringWithFormat:@"%ld", GiftSendType_OnMic] sendType:[dic objectForKey:@"sendType"]
giftId:[NSString stringWithFormat:@"%ld", self.giftInfo.giftId] giftId:[dic objectForKey:@"giftId"]
giftSource:[NSString stringWithFormat:@"%ld", self.giftSourceType] giftSource:[dic objectForKey:@"giftSource"]
giftType:[NSString stringWithFormat:@"%ld", self.roomSendGiftType] giftType:[dic objectForKey:@"giftType"]
roomUid:self.roomUID roomUid:[dic objectForKey:@"roomUid"]
msg:@"" msg:@""
uid:[AccountInfoStorage instance].getUid]; uid:[AccountInfoStorage instance].getUid];
} }

View File

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