From 111b639008c5588b3d1fdb208dde8438c49e1050 Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Fri, 27 May 2022 16:39:14 -0400 Subject: [PATCH 1/2] fix for auto reconnect on subscriber, using timers instead of async calls on main thread. --- .../SubscribeAutoReconnectTest.swift | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift b/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift index c04cacf..569b6b0 100644 --- a/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift +++ b/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift @@ -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. @@ -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!.finished) { + NSLog("Subscribing again!!") + self!.Subscribe() } - NSLog("Subscribing again!!") - self.Subscribe() + } } @@ -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!.finished) { + NSLog("Subscribing again!!") + self!.Subscribe() + } + } - NSLog("Subscribing again!!") - self.Subscribe() } } From c1b2bb5fee225a8fc8845a2dc9e38e976deea0ec Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Wed, 1 Jun 2022 09:21:02 -0400 Subject: [PATCH 2/2] Fix for RED5DEV-196 --- R5ProTestbed.xcodeproj/project.pbxproj | 8 ++++---- .../SubscribeReconnect/SubscribeAutoReconnectTest.swift | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R5ProTestbed.xcodeproj/project.pbxproj b/R5ProTestbed.xcodeproj/project.pbxproj index 04763ff..fef5282 100644 --- a/R5ProTestbed.xcodeproj/project.pbxproj +++ b/R5ProTestbed.xcodeproj/project.pbxproj @@ -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; @@ -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"; @@ -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", @@ -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", diff --git a/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift b/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift index 569b6b0..3fed946 100644 --- a/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift +++ b/R5ProTestbed/Tests/SubscribeReconnect/SubscribeAutoReconnectTest.swift @@ -98,7 +98,7 @@ class SubscribeAutoReconnectTest: BaseTest { } self.retryTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(SubscribeAutoReconnectTest.RETRY_TIMEOUT), repeats: false) { [weak self] timer in - if (!self!.finished) { + if (self != nil && !self!.finished) { NSLog("Subscribing again!!") self!.Subscribe() } @@ -122,7 +122,7 @@ class SubscribeAutoReconnectTest: BaseTest { } self.retryTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(SubscribeAutoReconnectTest.RETRY_TIMEOUT), repeats: false) { [weak self] timer in - if (!self!.finished) { + if (self != nil && !self!.finished) { NSLog("Subscribing again!!") self!.Subscribe() }