Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for auto reconnect on subscriber, using timers instead of async c… #208

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R5ProTestbed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -655,7 +655,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -676,7 +676,7 @@
"$(PROJECT_DIR)/R5ProTestbed",
);
INFOPLIST_FILE = R5ProTestbed/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -703,7 +703,7 @@
"$(PROJECT_DIR)/R5ProTestbed",
);
INFOPLIST_FILE = R5ProTestbed/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ import R5Streaming
class SubscribeAutoReconnectTest: BaseTest {

var finished = false
var retryTimer: Timer?
static let RETRY_TIMEOUT: Float = 2.0

override func viewWillDisappear(_ animated: Bool) {
self.finished = true
if (self.retryTimer != nil) {
self.retryTimer?.invalidate()
}
super.viewWillDisappear(animated)
}

override func viewDidLoad() {
self.finished = false
if (self.retryTimer != nil) {
self.retryTimer?.invalidate()
}
super.viewDidLoad()

// Do any additional setup after loading the view.
Expand Down Expand Up @@ -79,18 +87,22 @@ class SubscribeAutoReconnectTest: BaseTest {
super.onR5StreamStatus(stream, withStatus: statusCode, withMessage: msg)

if(statusCode == Int32(r5_status_connection_error.rawValue) ||
statusCode == Int32(r5_status_connection_close.rawValue)) {
statusCode == Int32(r5_status_connection_close.rawValue) ||
statusCode == Int32(r5_status_disconnected.rawValue)) {

//we can assume it failed here!

NSLog("Connection error")

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
if self.finished {
return
if let timer = self.retryTimer {
timer.invalidate()
}
self.retryTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(SubscribeAutoReconnectTest.RETRY_TIMEOUT), repeats: false) { [weak self] timer in

if (self != nil && !self!.finished) {
NSLog("Subscribing again!!")
self!.Subscribe()
}
NSLog("Subscribing again!!")
self.Subscribe()

}

}
Expand All @@ -100,16 +112,22 @@ class SubscribeAutoReconnectTest: BaseTest {
let view = currentView
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
if(self.subscribeStream != nil) {
view?.attach(nil)
// view?.attach(nil)
self.subscribeStream!.stop()
self.subscribeStream = nil
}

if self.finished {
return
if let timer = self.retryTimer {
timer.invalidate()
}
self.retryTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(SubscribeAutoReconnectTest.RETRY_TIMEOUT), repeats: false) { [weak self] timer in

if (self != nil && !self!.finished) {
NSLog("Subscribing again!!")
self!.Subscribe()
}

}
NSLog("Subscribing again!!")
self.Subscribe()
}
}

Expand Down