Skip to content

Commit

Permalink
fix: 修复多线程下没有触发消息队列的flush方法
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtaoit committed Mar 18, 2024
1 parent c2f7278 commit 58f14ff
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion Example/WuKongIMSDK/WKDatasource.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ - (void)setup {
WKSyncChannelMessageModel *model = [WKSyncChannelMessageModel new];
model.startMessageSeq = (uint32_t)[dict[@"start_message_seq"] unsignedLongLongValue];
model.endMessageSeq = (uint32_t)[dict[@"end_message_seq"] unsignedLongLongValue];
model.more = [dict[@"more"] boolValue];
NSArray<NSDictionary*> *messageDicts = dict[@"messages"];
if(messageDicts && messageDicts.count>0) {
NSMutableArray *messages = [NSMutableArray array];
Expand Down
3 changes: 2 additions & 1 deletion Example/WuKongIMSDK/WKMessageTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ - (void)reload {
}
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self animated:YES];
__weak typeof(self) weakSelf = self;
[WKSDK.shared.chatManager pullLastMessages:self.channel limit:15 alwayRequest:true complete:^(NSArray<WKMessage *> * _Nonnull messages, NSError * _Nonnull error) {

[WKSDK.shared.chatManager pullLastMessages:self.channel limit:15 complete:^(NSArray<WKMessage *> * _Nonnull messages, NSError * _Nonnull error) {
if(error) {
NSLog(@"加载消息失败!->%@",error);
hud.mode = MBProgressHUDModeText;
Expand Down
1 change: 0 additions & 1 deletion Example/WuKongIMSDK/WKViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ -(void) initOptions {
WKOptions *options = [[WKOptions alloc] init];
options.host = self.ip;
options.port = self.port;
options.heartbeatInterval = 10;

// 设置连接信息
WKConnectInfo *connectInfo = [WKConnectInfo new];
Expand Down
5 changes: 5 additions & 0 deletions Example/WuKongIMSDK/WuKongIMSDK-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down
1 change: 0 additions & 1 deletion WuKongIMSDK/Classes/manager/WKChatManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ -(void) handleSendack:(NSArray<WKSendackPacket*> *)sendackArray {
if(clientIDs.count>0) {
NSArray<WKMessage*> *messages = [[WKMessageDB shared] getMessagesWithClientSeqs:clientIDs];
if(messages && messages.count>0) {
NSLog(@"messages--aaaa------->%lu",messages.count);
for (NSInteger i=0; i<messages.count; i++) {
WKMessage *message = messages[i];
[self callMessageUpdateDelegate:message left:messages.count-1-i total:messages.count];
Expand Down
2 changes: 0 additions & 2 deletions WuKongIMSDK/Classes/manager/WKConnectionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ -(void) handlePacketData:(NSArray<NSData*>*)dataList {
}

-(void) handlePackets:(NSArray<WKPacket*>*)packets {
NSLog(@"handlePackets----------------start---->%lu",packets.count);
NSDictionary<NSNumber*,NSArray<WKPacket*>*>* packetDict = [self packetGroup:packets];
for (NSNumber *packetTypeNum in packetDict.allKeys) {
NSArray<WKPacket*> *packetList = [packetDict objectForKey:packetTypeNum];
Expand All @@ -685,7 +684,6 @@ -(void) handlePackets:(NSArray<WKPacket*>*)packets {
break;
}
}
NSLog(@"handlePackets----------------end---->%lu",packets.count);
}

-( WKConnectStatus) connectStatus {
Expand Down
10 changes: 8 additions & 2 deletions WuKongIMSDK/Classes/manager/WKMessageQueueManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@ -(void) start {
self.timer = nil;
}
CGFloat delay = (double)WKSDK.shared.options.sendFrequency/1000.0f;
NSLog(@"delay--->%0.2f",delay);
self.timer = [NSTimer scheduledTimerWithTimeInterval:delay target:self selector:@selector(flushQueue) userInfo:nil repeats:YES];
NSLog(@"MessageQueue start delay: %0.2f",delay);

__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.timer = [NSTimer scheduledTimerWithTimeInterval:delay target:weakSelf selector:@selector(flushQueue) userInfo:nil repeats:YES];
});


}

-(void) stop {
NSLog(@"MessageQueue stop");
[self.sendPackets removeAllObjects];
if(self.timer) {
[self.timer invalidate];
Expand Down

0 comments on commit 58f14ff

Please sign in to comment.