From a4cf18e0b9bea6d90a677c5b243991d9b7cf3193 Mon Sep 17 00:00:00 2001 From: zonble Date: Thu, 5 Oct 2017 14:47:45 +0800 Subject: [PATCH] Prevent blocking UI while reconnecting. The _reconnect in LFStreamRtmpSocket method calls -RTMP264_Connect:cStringUsingEncoding:, and it must be called in a background thread, otherwise the UI is blocked. --- LFLiveKit/publish/LFStreamRtmpSocket.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/LFLiveKit/publish/LFStreamRtmpSocket.m b/LFLiveKit/publish/LFStreamRtmpSocket.m index 89118046..99157e98 100644 --- a/LFLiveKit/publish/LFStreamRtmpSocket.m +++ b/LFLiveKit/publish/LFStreamRtmpSocket.m @@ -489,7 +489,7 @@ - (void)reconnect { self.isConnecting = NO; self.isReconnecting = YES; dispatch_async(dispatch_get_main_queue(), ^{ - [self performSelector:@selector(_reconnect) withObject:nil afterDelay:self.reconnectInterval]; + [self performSelector:@selector(_delayedReconnect) withObject:nil afterDelay:self.reconnectInterval]; }); } else if (self.retryTimes4netWorkBreaken >= self.reconnectCount) { @@ -503,9 +503,16 @@ - (void)reconnect { }); } -- (void)_reconnect{ +- (void)_delayedReconnect { [NSObject cancelPreviousPerformRequestsWithTarget:self]; - + + dispatch_async(self.rtmpSendQueue, ^{ + [self _reconnect]; + }); +} + +- (void)_reconnect { + _isReconnecting = NO; if(_isConnected) return;