像ios一样构建webRTC并创建webRTC.framework。
我在Google上搜索的信息很少,但是由于有一些更改,因此我在2017年4月2日之前进行了整理。
单击此处使Vol2实际连接
http://qiita.com/nakadoribooks/items/9f1b1cbe32f2fc6dec70
可交付成果
https://github.com/nakadoribooks/webrtc-ios/releases/tag/v0.0.1
参考
- http://www.utali.io/entry/2016/09/07/142102
- http://mike-neko.github.io/blog/webrtc-build/
创建webRTC.framework
创建一个适当的文件夹并将其移动
1 2 | mkdir webrtc-build cd webrtc-build |
安装depot_tools
http://dev.chromium.org/developers/how-tos/install-depot-tools
1 2 | git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git export PATH=`pwd`/depot_tools:"$PATH" |
下载WebRTC源代码
https://webrtc.org/native-code/ios/
1 2 | fetch --nohooks webrtc_ios gclient sync |
现在您有了一个
src目录,请检查您的提交
1 2 3 4 5 6 7 | cd src git log -- commit 76d9c9c3826f3c3622d3e8869fa54f7b39e70427 Author: stefan <[email protected]> Date: Sat Apr 1 06:51:09 2017 -0700 |
顺便说一句
76d9c9c3826f3c3622d3e8869fa54f7b39e70427
我会做这个
暂时剪切分支
1 | git checkout -b nakadoribooks-build |
GN GEN
构建设置很好吗?
目前,两个分别代表64和32。
如果需要模拟器,请更改target_cpu
target_os:
要为iOS进行构建,应在gn args中将其设置为target_os =" ios"。默认值是运行脚本的操作系统,因此在为macOS生成构建文件时可以将其省略。
target_cpu:
对于面向iOS设备的构建,应将其设置为" arm"或" arm64",具体取决于设备的体系结构;要在模拟器中运行的构建,则应将其设置为" x64"。
is_debug:
默认为Debug版本。要发布版本时,请指定false。
https://webrtc.org/native-code/ios/
1 2 | gn gen out/ios_64 --args='target_os="ios" target_cpu="arm64" is_debug=false ios_enable_code_signing=false' gn gen out/ios_32 --args='target_os="ios" target_cpu="arm" is_debug=false ios_enable_code_signing=false' |
忍者
构建
1 2 | ninja -C out/ios_64 AppRTCMobile ninja -C out/ios_32 AppRTCMobile |
适用于64和32
创建文件夹
1 | mkdir out/ios |
复制
1 | cp -R out/ios_64/WebRTC.framework/ out/ios/WebRTC.framework |
摩擦Gacchan
1 | lipo -create out/ios_64/WebRTC.framework/WebRTC out/ios_32/WebRTC.framework/WebRTC -output out/ios/WebRTC.framework/WebRTC |
由于某些原因,仅不包括" RTCVideoCapturer.h",因此将其复制
1 | cp webrtc/sdk/objc/Framework/Headers/WebRTC/RTCVideoCapturer.h out/ios/WebRTC.framework/Headers/ |
完成。
out / ios / WebRTC.framework
这个家伙
将其放在xcode项目中并使用
添加到项目
将在↑中创建的WebRTC.framework拖放到xcode中
已添加到"嵌入的二进制文件"
添加设置
启用位码NO
在Info.plist
中增加了隐私-相机使用说明
编写代码
webRTC
的一部分
WebRTC.swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | import UIKit class WebRTC: NSObject { private let factory = RTCPeerConnectionFactory() private var localRenderView = RTCEAGLVideoView() private var localStream:RTCMediaStream? private let _localView = UIView(frame:CGRect(x:20, y:40, width:140, height:200)) static let sharedInstance = WebRTC() private override init() { super.init() } // MARK: public func localView()->UIView{ return _localView } func setup(){ print("setup") setupLocalStream() } // MARK: private private func setupLocalStream(){ let streamId = WebRTCUtil.idWithPrefix(prefix: "stream") localStream = factory.mediaStream(withStreamId: streamId) setupLocalVideoTrack() } private func setupLocalVideoTrack(){ localRenderView.frame.size = _localView.frame.size _localView.addSubview(localRenderView) let localVideoSource = factory.avFoundationVideoSource(with: WebRTCUtil.mediaStreamConstraints()) let localVideoTrack = factory.videoTrack(with: localVideoSource, trackId: WebRTCUtil.idWithPrefix(prefix: "video")) localVideoTrack.add(localRenderView) localStream?.addVideoTrack(localVideoTrack) } } |
WebRTCUtil.swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import UIKit class WebRTCUtil: NSObject { static func idWithPrefix(prefix:String)->String{ return "\(prefix)_\(randomStringWithLength(len: 20))" } static func randomStringWithLength (len : Int) -> NSString { let letters : NSString = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" let randomString : NSMutableString = NSMutableString(capacity: len) for _ in 0..<len { let length = UInt32 (letters.length) let rand = arc4random_uniform(length) randomString.appendFormat("%C", letters.character(at: Int(rand))) } return randomString } static func mediaStreamConstraints()->RTCMediaConstraints{ return RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil) } } |
屏幕
ViewController.swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | import UIKit class ViewController: UIViewController { private let webRTC = WebRTC.sharedInstance override func viewDidLoad() { super.viewDidLoad() webRTC.setup() view.addSubview(webRTC.localView()) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } |
或更多。