如何使用swiftUI创建视频通话功能?

时间:2019-10-05 16:25:39

标签: webrtc swiftui

我正在使用SwiftUI创建一个消息传递应用程序,我想为此添加视频通话功能。我使用SkyWay webRTC API(https://webrtc.ecl.ntt.com/en/)实现了这一目标,并且可以构建一个用快速代码编写的示例项目。现在,我正在尝试将本地流与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

0 个答案:

没有答案