iOS swift5 AWS直播 WebRTC SDK for iOS Kinesis Video Streams

文章目录

1.官方文档

WebRTC SDK for iOS - AWS

2.github地址

Amazon Kinesis Video iOS WebRTC Sample - github

3.具体操作(本人已调试成功,并成功集成到项目里)

3.1 下载官方demo,并且按官方文档的步骤来,跑通demo,在demo中可以正常直播

  • 注意
  • demo需要注册,登录,登录成功后再点击直播

3.2 看懂demo里的代码后,将demo里的代码移植到自己的项目里

  • 如下,可以将demo里的Podfile文件直接拷贝到自己项目的Podfile文件里
swift 复制代码
# Uncomment the next line to define a global platform for your project
 platform :ios, '13.0'

target 'XXX' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

    # Pods for XXX
    pod 'SnapKit'
    pod 'Moya'
    pod 'IQKeyboardManagerSwift'
    pod 'SmartCodable'
    # pod 'XHToastSwift'
  # AWS
    pod 'AWSCognitoIdentityProvider'
    pod 'AWSMobileClient'
    pod 'CommonCryptoModule'
    pod 'AWSKinesisVideo'
    pod 'AWSKinesisVideoSignaling'
    pod 'GoogleWebRTC', '~> 1.1'
    pod 'Starscream', '~> 3.0'

end

# AWS
post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
            end
        end
    end
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
        end
    end
    installer.pods_project.build_configurations.each do |config|
        config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        config.build_settings["ONLY_ACTIVE_ARCH"] = "YES"
        config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = $iOSVersion
    end
end
  • 如下,是demo能正常直播时的打印log,我选的是Connect as Viewer
swift 复制代码
经过:signalClientDidConnect(_:)
经过:present(self.vc
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Received remote candidate from []
经过:Received remote sdp from []
经过:WebRTC checking state
经过:Generated local candidate
经过:Generated local candidate
经过:Setting remote sdp and sending answer.
经过:Received remote candidate from []
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:Generated local candidate
经过:WebRTC connected/completed state
  • 需要signalClientDidConnect后再加载直播界面,所以下面的代码中要等2秒
swift 复制代码
        // Create the video view
        let seconds = 2.0
        DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
            self.updateConnectionLabel()
            self.vc = VideoViewController(webRTCClient: self.webRTCClient!, signalingClient: self.signalingClient!, localSenderClientID: self.localSenderId, isMaster: self.isMaster, mediaServerEndPoint: endpoints["WEBRTC"] ?? nil)
            print("经过:present(self.vc")
            self.present(self.vc!, animated: true, completion: nil)
        }
swift 复制代码
extension ChannelConfigurationViewController: SignalClientDelegate {
    func signalClientDidConnect(_: SignalingClient) {
        signalingConnected = true
        print("经过:\(#function)")
    }
  • 在我自己的项目里我没有等2秒,直接连上后再加载直播界面
swift 复制代码
extension VideoVC: SignalClientDelegate {
    func signalClientDidConnect(_: SignalingClient) {
        MyPrint("经过:\(#function)")
        signalingConnected = true
        //必须要连接上后再加载视频
        loadVideoView()
    }
相关推荐
幽夜落雨15 分钟前
ios老版本应用安装方法
ios
胖虎18 小时前
实现 iOS 自定义高斯模糊文字效果的 UILabel(文末有Demo)
ios·高斯模糊文字·模糊文字
佛州小李哥10 小时前
Agent群舞,在亚马逊云科技搭建数字营销多代理(Multi-Agent)(下篇)
人工智能·科技·ai·语言模型·云计算·aws·亚马逊云科技
云梦谭21 小时前
AWS 签名算法SigV4 的python实现
aws·sigv4
一只海星1 天前
webrtc入门系列(五)amazon-kinesis-video-streams-webrtc-sdk-c编译
webrtc·amazon-kinesis·webrtc编译
NoneCoder1 天前
JavaScript系列(38)-- WebRTC技术详解
开发语言·javascript·webrtc
_可乐无糖2 天前
Appium 检查安装的驱动
android·ui·ios·appium·自动化
佛州小李哥2 天前
在亚马逊云科技上用AI提示词优化功能写出漂亮提示词(下)
人工智能·科技·ai·语言模型·云计算·aws·亚马逊云科技
胖虎12 天前
iOS 网络请求: Alamofire 结合 ObjectMapper 实现自动解析
ios·alamofire·objectmapper·网络请求自动解析·数据自动解析模型
开发者如是说2 天前
破茧英语路:我的经验与自研软件
ios·创业·推广