Skip to content

Commit d181c5d

Browse files
authored
Merge pull request #551 from zapcannon87/master
RTM support goaway
2 parents 731d94f + 3bb8b4a commit d181c5d

File tree

7 files changed

+57
-4
lines changed

7 files changed

+57
-4
lines changed

AVOS/AVOSCloud/UserAgent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define SDK_VERSION @"v11.5.1"
1+
#define SDK_VERSION @"v11.5.2"

AVOS/AVOSCloudIM/WebSocket/AVIMWebSocketWrapper.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ - (void)webSocket:(AVIMWebSocket *)webSocket didReceiveMessage:(id)message
513513
LCIMProtobufCommandWrapper *commandWrapper = [LCIMProtobufCommandWrapper new];
514514
commandWrapper.inCommand = inCommand;
515515
[delegate webSocketWrapper:self didReceiveCommand:commandWrapper];
516+
if (!inCommand.hasPeerId) {
517+
[self handleGoawayWith:inCommand];
518+
}
516519
}
517520
}
518521

@@ -832,4 +835,25 @@ - (uint16_t)serialIndex
832835
return result;
833836
}
834837

838+
- (void)handleGoawayWith:(AVIMGenericCommand *)command
839+
{
840+
AssertRunInQueue(self->_internalSerialQueue);
841+
if (command.cmd != AVIMCommandType_Goaway) {
842+
return;
843+
}
844+
NSError *error;
845+
[[LCRouter sharedInstance] cleanCacheWithKey:RouterCacheKeyRTM error:&error];
846+
if (error) {
847+
AVLoggerError(AVLoggerDomainIM, @"%@", error);
848+
return;
849+
}
850+
error = ({
851+
AVIMErrorCode code = AVIMErrorCodeConnectionLost;
852+
LCError(code, @"Connection did close by local peer.", nil);
853+
});
854+
[self purgeWithError:error];
855+
[self pauseWithError:error];
856+
[self tryConnecting:false];
857+
}
858+
835859
@end

AVOS/AVOSCloudIMTests/Swift/AVIMClientTestCase.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,32 @@ class AVIMClientTestCase: LCIMTestBase {
340340
}, failure: { XCTFail("timeout") })
341341
}
342342

343+
func test_goaway() {
344+
AVOSCloudIM.defaultOptions().rtmServer = "wss://rtm51.leancloud.cn";
345+
346+
guard let client: AVIMClient = LCIMTestBase.newOpenedClient(clientId: String(#function[..<#function.index(of: "(")!])) else {
347+
XCTFail()
348+
return
349+
}
350+
let delegator = AVIMClientDelegateWrapper()
351+
client.delegate = delegator
352+
353+
AVOSCloudIM.defaultOptions().rtmServer = nil;
354+
355+
let exp = expectation(description: "test goaway")
356+
exp.expectedFulfillmentCount = 3
357+
LCRouter.sharedInstance().getRTMURLWithAppID(AVOSCloud.getApplicationId()) { (response, error) in
358+
XCTAssertNotNil(response)
359+
XCTAssertNil(error)
360+
exp.fulfill()
361+
}
362+
delegator.pausedClosure = { _ in
363+
exp.fulfill()
364+
}
365+
delegator.resumedClosure = { _ in
366+
exp.fulfill()
367+
}
368+
wait(for: [exp], timeout: 90)
369+
}
370+
343371
}

AVOS/AVOSCloudIMTests/Swift/AVOSCloudIM-iOSTests-Bridging-Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
#import "AVIMClientInternalConversationManager_Internal.h"
1414
#import "AVPaasClient.h"
1515
#import "AVIMClientPushManager.h"
16+
#import "LCRouter_Internal.h"

AVOSCloud.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AVOSCloud'
3-
s.version = '11.5.1'
3+
s.version = '11.5.2'
44
s.homepage = 'https://leancloud.cn/'
55
s.summary = 'LeanCloud Objective-C SDK'
66
s.authors = 'LeanCloud'

AVOSCloudIM.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AVOSCloudIM'
3-
s.version = '11.5.1'
3+
s.version = '11.5.2'
44
s.homepage = 'https://leancloud.cn/'
55
s.summary = 'LeanCloud IM Objective-C SDK'
66
s.authors = 'LeanCloud'

AVOSCloudLiveQuery.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AVOSCloudLiveQuery'
3-
s.version = '11.5.1'
3+
s.version = '11.5.2'
44
s.homepage = 'https://leancloud.cn/'
55
s.summary = 'LeanCloud LiveQuery Objective-C SDK'
66
s.authors = 'LeanCloud'

0 commit comments

Comments
 (0)