WebRTC 抽象层 (WAL)
该库目前仅用于演示目的,呈现了 iOS 上 WebRTC 连接的基本机制。使用仅限于视频通话。尚无旨在创建仅音频通话的 API。请记住,它不提供安全或授权!
使用 CocoaPods 进行安装
将以下内容添加到您的 Podfile 中
pod 'WAL'
运行 pod install
先决条件
- Swift 4.1
- Xcode 9
- 设置摄像头的隐私通知和麦克风
- 用于信令服务器的 Docker
信令服务器
如你所知,创建 WebRTC 连接需要某种信令。该库使用名为 Spreed 的信令服务器。幸运的是,他们提供了一个用于其 Web 服务的 docker 镜像,你可以用以下方式启动:
docker run --rm --name my-spreed-webrtc -p 8080:8080 -p 8443:8443
或者创建一个 docker-compose.yml
文件
version: '3'
services:
spreed:
image: "spreed/webrtc"
ports:
- "8080:8080"
- "8443:8443"
然后你可以简单地运行 docker-compose up
使用说明
import WebRTC
import WAL
创建连接
let currentConnection = WebRTCConnection(with: WebRTConnection.Config(...), delegate: self)
// Join room on signaling server
currentConnection.join(roomName: "Whale")
实现WebRTCConnectionDelegate
func webRTCConnection(_ sender: WebRTCConnection, didReceiveLocalCapturer localCapturer: RTCCameraVideoCapturer)
func webRTCConnection(_ sender: WebRTCConnection, didReceiveRemoteVideoTrack remoteTrack: RTCVideoTrack)
func webRTCConnection(_ sender: WebRTCConnection, didReceiveLocalAudioTrack remoteTrack: RTCAudioTrack)
func webRTCConnection(_ sender: WebRTCConnection, didReceiveRemoteAudioTrack remoteTrack: RTCAudioTrack)
func webRTCConnection(_ sender: WebRTCConnection, userDidJoin userId: String)
func webRTCConnection(_ sender: WebRTCConnection, didChange state: WebRTCConnection.State)
func didOpenDataChannel(_ sender: WebRTCConnection)
func webRTCConnection(_ sender: WebRTCConnection, didReceiveDataChannelData data: Data)
func didReceiveIncomingCall(_ sender: WebRTCConnection, from userId: String)i
发起通话
currentConnection.connect(toUserId: userId)
应答来电
currentConnection.answerIncomingCall(userId: userId)
通过数据通道发送数据
currentConnection.send(data: data)
支持
如果您发现错误或有任何建议,请通过问题或拉取请求告知我们。