Skip to content

Commit

Permalink
feat: upgrade wkproto
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtaoit committed Oct 9, 2023
1 parent 8adcc18 commit 040448e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion WuKongIMSDK/Classes/WKOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ -(id) init {


self.offlineMessageLimit = 300;
self.protoVersion = 0x3;
self.protoVersion = 0x4;
self.proto = WK_PROTO_WK;
self.messageFileRootDir =[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"files"];
self.dbPrefix = WK_DB_Prefix;
Expand Down
3 changes: 3 additions & 0 deletions WuKongIMSDK/Classes/coder/WKCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ -(WKPacket*) decodeLM:(NSData*)data {
header.noPersist = (flag & 0x01) > 0;
header.showUnread = ((flag >> 1) & 0x01) > 0;
header.syncOnce = ((flag >> 2) & 0x01) > 0;
if(packetType == WK_CONNACK) {
header.hasServerVersion = (flag & 0x01) > 0;
}

return [[[WKSDK shared].bodyCoderManager getBodyCoder:packetType] decode:reader.remainingData header:header];
}
Expand Down
3 changes: 3 additions & 0 deletions WuKongIMSDK/Classes/coder/WKHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
// 是否同步一次
@property(nonatomic,assign) BOOL syncOnce;

// 是否存在服务版本(connack包有效)
@property(nonatomic,assign) BOOL hasServerVersion;

@end

NS_ASSUME_NONNULL_END
6 changes: 4 additions & 2 deletions WuKongIMSDK/Classes/coder/proto/WKConnackPacket.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ -(WKPacket*) decode:(NSData*) body header:(WKHeader*)header {
-(WKPacket*) decodeLM:(NSData*) body header:(WKHeader*)header {
WKConnackPacket *packet = [WKConnackPacket new];
WKDataRead *reader = [[WKDataRead alloc] initWithData:body];
if(WKSDK.shared.options.protoVersion > 3) {
if(header.hasServerVersion) {
packet.serverVersion = [reader readUint8];
if(packet.serverVersion < WKSDK.shared.options.protoVersion) {
WKSDK.shared.options.protoVersion = packet.serverVersion;
NSLog(@"使用协议版本:%hhu",WKSDK.shared.options.protoVersion);
}
} else {
WKSDK.shared.options.protoVersion = 0x2; // 降级到expire字段之前的0x2版本
}
NSLog(@"使用协议版本:%hhu",WKSDK.shared.options.protoVersion);
packet.timeDiff = [reader readint64];
packet.reasonCode = [reader readUint8];
packet.serverKey = [reader readString];
Expand Down

0 comments on commit 040448e

Please sign in to comment.