webrtc - 如何使用 swiftUI 创建视频通话功能?
问题描述
我正在使用 SwiftUI 创建一个消息传递应用程序,并且我想向其中添加视频通话功能。我使用 SkyWay webRTC API ( https://webrtc.ecl.ntt.com/en/ ) 来实现这一点,我可以构建一个用 swift 代码编写的示例项目。现在我正在尝试将本地流与 SKWVideo 视图链接并将其包装到 UIViewRepresentable 中。但是我遇到了以下错误消息。
import SwiftUI
import SkyWay
import UIKit
struct ContentView: View {
@State var video = SKWVideo()
var body: some View {
VideoView(localStreamView: $video)
}
}
struct VideoView: UIViewRepresentable {
@Binding var localStreamView: SKWVideo
func makeUIView(context: Context) -> SKWVideo {
let option: SKWPeerOption = SKWPeerOption.init()
option.key = "xxxx"
option.domain = "localhost"
let peer = SKWPeer(options: option)
SKWNavigator.initialize(peer!)
let constraints: SKWMediaConstraints = SKWMediaConstraints()
let localStream = SKWNavigator.getUserMedia(constraints)
localStream?.addVideoRenderer(localStreamView, track: 0)
return localStreamView
}
func updateUIView(_ uiView: SKWVideo, context: Context) {
//
}
}
我收到了这个错误
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'
我在 iPhone 7 真实设备上运行它,并编写了 plist 设置。我现在完全不知道。请帮我..
iOS 13.0 xcode 11.0
解决方案
推荐阅读
- kotlin - 智能投射 Arrow-kt 选项
- javascript - 用于展开所有页面链接的 Chrome 小书签
- c++ - BLE 标头 Nordic nRF52832 中的连接句柄 ID 出错
- java - 线程“主”java.lang.NoClassDefFoundError 中的异常:fr/styygital/jmdesktoplib/GuiDrawer
- react-native - 如何在 Dynamic FlatList 中添加 React 本机弹出菜单
- visual-studio - 使用 Android 版本更改编译后出错
- qt - 不能在新的 qbs 版本 (1.12) 中包含静态库
- python - Tensorflow 从字符串句柄创建第二个迭代器 - GetNext() 失败,因为未初始化
- r - 使用 cloudml 训练 R Keras 模型失败
- python-3.x - 设置路径变量时,在 python 中的 F:drive 中导入 pytesseract 错误