1.0.18 feat:连击礼物请求加入到每 0.2s 执行一次的队列
This commit is contained in:
@@ -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];
|
||||||
}
|
}
|
||||||
|
@@ -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];
|
||||||
|
Reference in New Issue
Block a user