From 9e536d2291d179237abad93a0d7a04bed0ecc8db Mon Sep 17 00:00:00 2001 From: chenliming Date: Sat, 8 Oct 2016 17:02:21 +0800 Subject: [PATCH] add status refresh --- LFLiveKit/objects/LFLiveStreamInfo.h | 4 +- LFLiveKit/publish/LFStreamRtmpSocket.m | 99 +++++++----- .../project.pbxproj | 143 ++++++++++-------- .../LFLiveKitSwiftDemo/AppDelegate.swift | 12 +- .../LFLiveKitSwiftDemo/ViewController.swift | 60 ++++---- LFLiveKitSwiftDemo/Podfile | 6 + 6 files changed, 188 insertions(+), 136 deletions(-) create mode 100644 LFLiveKitSwiftDemo/Podfile diff --git a/LFLiveKit/objects/LFLiveStreamInfo.h b/LFLiveKit/objects/LFLiveStreamInfo.h index bcbe4476..04639f5e 100755 --- a/LFLiveKit/objects/LFLiveStreamInfo.h +++ b/LFLiveKit/objects/LFLiveStreamInfo.h @@ -29,7 +29,9 @@ typedef NS_ENUM (NSUInteger, LFLiveState){ /// 已断开 LFLiveStop = 3, /// 连接出错 - LFLiveError = 4 + LFLiveError = 4, + ///  正在刷新 + LFLiveRefresh = 5 }; typedef NS_ENUM (NSUInteger, LFLiveSocketErrorCode) { diff --git a/LFLiveKit/publish/LFStreamRtmpSocket.m b/LFLiveKit/publish/LFStreamRtmpSocket.m index d4472354..3dee8e32 100644 --- a/LFLiveKit/publish/LFStreamRtmpSocket.m +++ b/LFLiveKit/publish/LFStreamRtmpSocket.m @@ -16,7 +16,7 @@ #import "rtmp.h" #endif -static const NSInteger RetryTimesBreaken = 20; ///< 重连1分钟 3秒一次 一共20次 +static const NSInteger RetryTimesBreaken = 5; ///< 重连1分钟 3秒一次 一共20次 static const NSInteger RetryTimesMargin = 3; @@ -112,12 +112,24 @@ - (void)_start { self.debugInfo.streamId = self.stream.streamId; self.debugInfo.uploadUrl = self.stream.url; self.debugInfo.isRtmp = YES; + if (_isConnecting) return; + + _isConnecting = YES; + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLivePending]; + } + + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + } [self RTMP264_Connect:(char *)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]]; } - (void)stop { dispatch_async(self.rtmpSendQueue, ^{ [self _stop]; + [NSObject cancelPreviousPerformRequestsWithTarget:self]; }); } @@ -131,7 +143,6 @@ - (void)_stop { _rtmp = NULL; } [self clean]; - [NSObject cancelPreviousPerformRequestsWithTarget:self]; } - (void)sendFrame:(LFFrame *)frame { @@ -239,18 +250,6 @@ - (void)clean { - (NSInteger)RTMP264_Connect:(char *)push_url { //由于摄像头的timestamp是一直在累加,需要每次得到相对时间戳 //分配与初始化 - if (_isConnecting) return -1; - - _isConnecting = YES; - if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { - [self.delegate socketStatus:self status:LFLivePending]; - } - - if (_rtmp != NULL) { - PILI_RTMP_Close(_rtmp, &_error); - PILI_RTMP_Free(_rtmp); - } - _rtmp = PILI_RTMP_Alloc(); PILI_RTMP_Init(_rtmp); @@ -289,19 +288,13 @@ - (NSInteger)RTMP264_Connect:(char *)push_url { _isConnecting = NO; _isReconnecting = NO; _isSending = NO; - _retryTimes4netWorkBreaken = 0; return 0; Failed: PILI_RTMP_Close(_rtmp, &_error); PILI_RTMP_Free(_rtmp); _rtmp = NULL; - if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]) { - [self.delegate socketDidError:self errorCode:LFLiveSocketError_ConnectSocket]; - } - if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { - [self.delegate socketStatus:self status:LFLiveError]; - } + [self reconnect]; return -1; } @@ -493,36 +486,62 @@ - (void)sendAudio:(LFFrame *)frame { // 断线重连 - (void)reconnect { dispatch_async(self.rtmpSendQueue, ^{ - _isReconnecting = NO; - if (_isConnected) return; - - [self _stop]; - [self _start]; + if (self.retryTimes4netWorkBreaken++ < self.reconnectCount && !self.isReconnecting) { + self.isConnected = NO; + self.isConnecting = NO; + self.isReconnecting = YES; + dispatch_async(dispatch_get_main_queue(), ^{ + [self performSelector:@selector(_reconnect) withObject:nil afterDelay:self.reconnectInterval]; + }); + + } else if (self.retryTimes4netWorkBreaken >= self.reconnectCount) { + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveError]; + } + if (self.delegate && [self.delegate respondsToSelector:@selector(socketDidError:errorCode:)]) { + [self.delegate socketDidError:self errorCode:LFLiveSocketError_ReConnectTimeOut]; + } + } }); } +- (void)_reconnect{ + [NSObject cancelPreviousPerformRequestsWithTarget:self]; + + _isReconnecting = NO; + if(_isConnected) return; + + _isReconnecting = NO; + if (_isConnected) return; + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + _rtmp = NULL; + } + _sendAudioHead = NO; + _sendVideoHead = NO; + + if (self.delegate && [self.delegate respondsToSelector:@selector(socketStatus:status:)]) { + [self.delegate socketStatus:self status:LFLiveRefresh]; + } + + if (_rtmp != NULL) { + PILI_RTMP_Close(_rtmp, &_error); + PILI_RTMP_Free(_rtmp); + } + [self RTMP264_Connect:(char *)[_stream.url cStringUsingEncoding:NSASCIIStringEncoding]]; +} + #pragma mark -- CallBack void RTMPErrorCallback(RTMPError *error, void *userData) { LFStreamRTMPSocket *socket = (__bridge LFStreamRTMPSocket *)userData; if (error->code < 0) { - if (socket.retryTimes4netWorkBreaken++ < socket.reconnectCount && !socket.isReconnecting) { - socket.isConnected = NO; - socket.isConnecting = NO; - socket.isReconnecting = YES; - [socket performSelectorOnMainThread:@selector(reconnect) withObject:nil waitUntilDone:socket.reconnectInterval]; - } else if (socket.retryTimes4netWorkBreaken >= socket.reconnectCount) { - if (socket.delegate && [socket.delegate respondsToSelector:@selector(socketStatus:status:)]) { - [socket.delegate socketStatus:socket status:LFLiveError]; - } - if (socket.delegate && [socket.delegate respondsToSelector:@selector(socketDidError:errorCode:)]) { - [socket.delegate socketDidError:socket errorCode:LFLiveSocketError_ReConnectTimeOut]; - } - } + [socket reconnect]; } } void ConnectionTimeCallback(PILI_CONNECTION_TIME *conn_time, void *userData) { - //LFStreamRTMPSocket *socket = (__bridge LFStreamRTMPSocket*)userData; + LFStreamRTMPSocket *socket = (__bridge LFStreamRTMPSocket*)userData; } #pragma mark -- LFStreamingBufferDelegate diff --git a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj index c8d39f06..00f97fff 100644 --- a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj +++ b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj @@ -20,30 +20,13 @@ 84D8B4B11D757DBB00752B56 /* camra_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4A91D757DBB00752B56 /* camra_preview@3x.png */; }; 84D8B4B21D757DBB00752B56 /* close_preview@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */; }; 84D8B4B31D757DBB00752B56 /* close_preview@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */; }; - 84D8B4BA1D757DED00752B56 /* GPUImage.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4B81D757DED00752B56 /* GPUImage.framework */; }; 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */; }; - 84D8B5571D76824700752B56 /* pili-librtmp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B5561D76824700752B56 /* pili-librtmp.framework */; }; - 84D8B5FE1D768BBE00752B56 /* LFLiveKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84D8B5FB1D768BB200752B56 /* LFLiveKit.framework */; }; + 9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 84D8B5FA1D768BB200752B56 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 84D8B5F61D768BB200752B56 /* LFLiveKit.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 84D8B3901D7574D600752B56; - remoteInfo = LFLiveKit; - }; - 84D8B5FC1D768BB800752B56 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 84D8B5F61D768BB200752B56 /* LFLiveKit.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 84D8B38F1D7574D600752B56; - remoteInfo = LFLiveKit; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXFileReference section */ + 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitSwiftDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.debug.xcconfig"; sourceTree = ""; }; 84D8B4881D757D4000752B56 /* LFLiveKitSwiftDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LFLiveKitSwiftDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 84D8B48B1D757D4000752B56 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 84D8B48D1D757D4000752B56 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -59,10 +42,8 @@ 84D8B4A91D757DBB00752B56 /* camra_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_preview@3x.png"; sourceTree = ""; }; 84D8B4AA1D757DBB00752B56 /* close_preview@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@2x.png"; sourceTree = ""; }; 84D8B4AB1D757DBB00752B56 /* close_preview@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "close_preview@3x.png"; sourceTree = ""; }; - 84D8B4B81D757DED00752B56 /* GPUImage.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GPUImage.framework; path = ../Vendor/GPUImage.framework; sourceTree = ""; }; 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libstdc++.tbd"; path = "usr/lib/libstdc++.tbd"; sourceTree = SDKROOT; }; - 84D8B5561D76824700752B56 /* pili-librtmp.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "pili-librtmp.framework"; path = "../Vendor/pili-librtmp.framework"; sourceTree = ""; }; - 84D8B5F61D768BB200752B56 /* LFLiveKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = LFLiveKit.xcodeproj; path = ../FrameWork/LFLiveKit.xcodeproj; sourceTree = ""; }; + DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -70,25 +51,30 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 84D8B5FE1D768BBE00752B56 /* LFLiveKit.framework in Frameworks */, - 84D8B5571D76824700752B56 /* pili-librtmp.framework in Frameworks */, 84D8B4BD1D757E0E00752B56 /* libstdc++.tbd in Frameworks */, - 84D8B4BA1D757DED00752B56 /* GPUImage.framework in Frameworks */, + 9CA0546A1BD4E74670872B9B /* libPods-LFLiveKitSwiftDemo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 23FA2B0543E0C2A8E7C84D9E /* Frameworks */ = { + isa = PBXGroup; + children = ( + 4E0C4364E65B82DECF3326D9 /* libPods-LFLiveKitSwiftDemo.a */, + ); + name = Frameworks; + sourceTree = ""; + }; 84D8B47F1D757D4000752B56 = { isa = PBXGroup; children = ( - 84D8B5F61D768BB200752B56 /* LFLiveKit.xcodeproj */, - 84D8B5561D76824700752B56 /* pili-librtmp.framework */, 84D8B4BC1D757E0E00752B56 /* libstdc++.tbd */, - 84D8B4B81D757DED00752B56 /* GPUImage.framework */, 84D8B48A1D757D4000752B56 /* LFLiveKitSwiftDemo */, 84D8B4891D757D4000752B56 /* Products */, + B19B532AA669846CC85D50E3 /* Pods */, + 23FA2B0543E0C2A8E7C84D9E /* Frameworks */, ); sourceTree = ""; }; @@ -129,12 +115,13 @@ path = images; sourceTree = ""; }; - 84D8B5F71D768BB200752B56 /* Products */ = { + B19B532AA669846CC85D50E3 /* Pods */ = { isa = PBXGroup; children = ( - 84D8B5FB1D768BB200752B56 /* LFLiveKit.framework */, + 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */, + DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */, ); - name = Products; + name = Pods; sourceTree = ""; }; /* End PBXGroup section */ @@ -144,14 +131,16 @@ isa = PBXNativeTarget; buildConfigurationList = 84D8B49A1D757D4000752B56 /* Build configuration list for PBXNativeTarget "LFLiveKitSwiftDemo" */; buildPhases = ( + FC46EAD69B9F095AB7372DB6 /* 📦 Check Pods Manifest.lock */, 84D8B4841D757D4000752B56 /* Sources */, 84D8B4851D757D4000752B56 /* Frameworks */, 84D8B4861D757D4000752B56 /* Resources */, + 951756CA4F11963EE3622ADB /* 📦 Embed Pods Frameworks */, + 1D8289CE7990A09D5E67FA15 /* 📦 Copy Pods Resources */, ); buildRules = ( ); dependencies = ( - 84D8B5FD1D768BB800752B56 /* PBXTargetDependency */, ); name = LFLiveKitSwiftDemo; productName = LFLiveKitSwiftDemo; @@ -170,6 +159,8 @@ TargetAttributes = { 84D8B4871D757D4000752B56 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = G497YX6CBT; + LastSwiftMigration = 0800; }; }; }; @@ -184,12 +175,6 @@ mainGroup = 84D8B47F1D757D4000752B56; productRefGroup = 84D8B4891D757D4000752B56 /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 84D8B5F71D768BB200752B56 /* Products */; - ProjectRef = 84D8B5F61D768BB200752B56 /* LFLiveKit.xcodeproj */; - }, - ); projectRoot = ""; targets = ( 84D8B4871D757D4000752B56 /* LFLiveKitSwiftDemo */, @@ -197,16 +182,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 84D8B5FB1D768BB200752B56 /* LFLiveKit.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = LFLiveKit.framework; - remoteRef = 84D8B5FA1D768BB200752B56 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ 84D8B4861D757D4000752B56 /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -228,6 +203,54 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 1D8289CE7990A09D5E67FA15 /* 📦 Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "📦 Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 951756CA4F11963EE3622ADB /* 📦 Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "📦 Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + FC46EAD69B9F095AB7372DB6 /* 📦 Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "📦 Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 84D8B4841D757D4000752B56 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -240,14 +263,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - 84D8B5FD1D768BB800752B56 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = LFLiveKit; - targetProxy = 84D8B5FC1D768BB800752B56 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ 84D8B48F1D757D4000752B56 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -353,31 +368,41 @@ }; 84D8B49B1D757D4000752B56 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 7265B07B4B6CEE8ECE8F7A63 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/../Vendor\"/**"; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_VERSION = 3.0; }; name = Debug; }; 84D8B49C1D757D4000752B56 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = DAC498DB742E949DED005ECE /* Pods-LFLiveKitSwiftDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = "\"$(SRCROOT)/../Vendor\"/**"; + DEVELOPMENT_TEAM = G497YX6CBT; + FRAMEWORK_SEARCH_PATHS = "$(inherited)"; + HEADER_SEARCH_PATHS = "$(inherited)"; INFOPLIST_FILE = LFLiveKitSwiftDemo/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LIBRARY_SEARCH_PATHS = "$(inherited)"; OTHER_LDFLAGS = "-all_load"; PRODUCT_BUNDLE_IDENTIFIER = com.youku.LaiFeng; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift index 0918b4cc..cd6ef6ab 100644 --- a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift +++ b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift index 46e47985..5e871e4c 100644 --- a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift +++ b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift @@ -16,7 +16,7 @@ class ViewController: UIViewController, LFLiveSessionDelegate { // Do any additional setup after loading the view, typically from a nib. self.requestAccessForVideo() self.requestAccessForAudio() - self.view.backgroundColor = UIColor.clearColor() + self.view.backgroundColor = UIColor.clear self.view.addSubview(containerView) containerView.addSubview(stateLabel) containerView.addSubview(closeButton) @@ -79,15 +79,15 @@ class ViewController: UIViewController, LFLiveSessionDelegate { //MARK: - Callbacks // 回调 - func liveSession(session: LFLiveSession?, debugInfo: LFLiveDebug?) { + func liveSession(_ session: LFLiveSession?, debugInfo: LFLiveDebug?) { print("debugInfo: \(debugInfo?.currentBandwidth)") } - func liveSession(session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) { + func liveSession(_ session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) { print("errorCode: \(errorCode.rawValue)") } - func liveSession(session: LFLiveSession?, liveStateDidChange state: LFLiveState) { + func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) { print("liveStateDidChange: \(state.rawValue)") switch state { case LFLiveState.Ready: @@ -111,33 +111,33 @@ class ViewController: UIViewController, LFLiveSessionDelegate { //MARK: - Events // 开始直播 - func didTappedStartLiveButton(button: UIButton) -> Void { - startLiveButton.selected = !startLiveButton.selected; - if (startLiveButton.selected) { - startLiveButton.setTitle("结束直播", forState: UIControlState.Normal) + func didTappedStartLiveButton(_ button: UIButton) -> Void { + startLiveButton.isSelected = !startLiveButton.isSelected; + if (startLiveButton.isSelected) { + startLiveButton.setTitle("结束直播", for: UIControlState()) let stream = LFLiveStreamInfo() stream.url = "rtmp://live.hkstv.hk.lxdns.com:1935/live/stream153" session.startLive(stream) } else { - startLiveButton.setTitle("开始直播", forState: UIControlState.Normal) + startLiveButton.setTitle("开始直播", for: UIControlState()) session.stopLive() } } // 美颜 - func didTappedBeautyButton(button: UIButton) -> Void { + func didTappedBeautyButton(_ button: UIButton) -> Void { session.beautyFace = !session.beautyFace; beautyButton.selected = !session.beautyFace; } // 摄像头 - func didTappedCameraButton(button: UIButton) -> Void { + func didTappedCameraButton(_ button: UIButton) -> Void { let devicePositon = session.captureDevicePosition; session.captureDevicePosition = (devicePositon == AVCaptureDevicePosition.Back) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; } // 关闭 - func didTappedCloseButton(button: UIButton) -> Void { + func didTappedCloseButton(_ button: UIButton) -> Void { } @@ -157,8 +157,8 @@ class ViewController: UIViewController, LFLiveSessionDelegate { // 视图 lazy var containerView: UIView = { let containerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height)) - containerView.backgroundColor = UIColor.clearColor() - containerView.autoresizingMask = [UIViewAutoresizing.FlexibleHeight, UIViewAutoresizing.FlexibleHeight] + containerView.backgroundColor = UIColor.clear + containerView.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleHeight] return containerView }() @@ -166,33 +166,33 @@ class ViewController: UIViewController, LFLiveSessionDelegate { lazy var stateLabel: UILabel = { let stateLabel = UILabel(frame: CGRect(x: 20, y: 20, width: 80, height: 40)) stateLabel.text = "未连接" - stateLabel.textColor = UIColor.whiteColor() - stateLabel.font = UIFont.systemFontOfSize(14) + stateLabel.textColor = UIColor.white + stateLabel.font = UIFont.systemFont(ofSize: 14) return stateLabel }() // 关闭按钮 lazy var closeButton: UIButton = { let closeButton = UIButton(frame: CGRect(x: self.view.frame.width - 10 - 44, y: 20, width: 44, height: 44)) - closeButton.setImage(UIImage(named: "close_preview"), forState: UIControlState.Normal) - closeButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), forControlEvents: UIControlEvents.TouchUpInside) + closeButton.setImage(UIImage(named: "close_preview"), for: UIControlState()) + closeButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: UIControlEvents.touchUpInside) return closeButton }() // 摄像头 lazy var cameraButton: UIButton = { let cameraButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 2, y: 20, width: 44, height: 44)) - cameraButton.setImage(UIImage(named: "camra_preview"), forState: UIControlState.Normal) - cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), forControlEvents: UIControlEvents.TouchUpInside) + cameraButton.setImage(UIImage(named: "camra_preview"), for: UIControlState()) + cameraButton.addTarget(self, action: #selector(didTappedCameraButton(_:)), for: UIControlEvents.touchUpInside) return cameraButton }() // 摄像头 lazy var beautyButton: UIButton = { let beautyButton = UIButton(frame: CGRect(x: self.view.frame.width - 54 * 3, y: 20, width: 44, height: 44)) - beautyButton.setImage(UIImage(named: "camra_preview"), forState: UIControlState.Selected) - beautyButton.setImage(UIImage(named: "camra_beauty_close"), forState: UIControlState.Normal) - beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), forControlEvents: UIControlEvents.TouchUpInside) + beautyButton.setImage(UIImage(named: "camra_preview"), for: UIControlState.selected) + beautyButton.setImage(UIImage(named: "camra_beauty_close"), for: UIControlState()) + beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: UIControlEvents.touchUpInside) return beautyButton }() @@ -200,20 +200,20 @@ class ViewController: UIViewController, LFLiveSessionDelegate { lazy var startLiveButton: UIButton = { let startLiveButton = UIButton(frame: CGRect(x: 30, y: self.view.frame.height - 50, width: self.view.frame.width - 10 - 44, height: 44)) startLiveButton.layer.cornerRadius = 22 - startLiveButton.setTitleColor(UIColor.blackColor(), forState:UIControlState.Normal) - startLiveButton.setTitle("开始直播", forState: UIControlState.Normal) - startLiveButton.titleLabel!.font = UIFont.systemFontOfSize(14) + startLiveButton.setTitleColor(UIColor.black, for:UIControlState()) + startLiveButton.setTitle("开始直播", for: UIControlState()) + startLiveButton.titleLabel!.font = UIFont.systemFont(ofSize: 14) startLiveButton.backgroundColor = UIColor(colorLiteralRed: 50, green: 32, blue: 245, alpha: 1) - startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), forControlEvents: UIControlEvents.TouchUpInside) + startLiveButton.addTarget(self, action: #selector(didTappedStartLiveButton(_:)), for: UIControlEvents.touchUpInside) return startLiveButton }() // 转屏 - override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { - return UIInterfaceOrientationMask.Portrait + override var supportedInterfaceOrientations : UIInterfaceOrientationMask { + return UIInterfaceOrientationMask.portrait } - override func shouldAutorotate() -> Bool { + override var shouldAutorotate : Bool { return true } } diff --git a/LFLiveKitSwiftDemo/Podfile b/LFLiveKitSwiftDemo/Podfile new file mode 100644 index 00000000..30570b12 --- /dev/null +++ b/LFLiveKitSwiftDemo/Podfile @@ -0,0 +1,6 @@ +source 'https://github.com/CocoaPods/Specs.git' +platform :ios,'7.0' + +target “LFLiveKitSwiftDemo” do + pod 'LFLiveKit', :path => '../.' +end