当启动addIceCandidate时,Webrtc错误。

问题描述 投票:0回答:1

我正试图在webrtc中发起点对点连接。我使用signalr作为信号服务器。当我添加冰候选人时,我在所有的浏览器中得到错误。下面是错误和代码行。请让我知道我如何能解决这个问题。

在Firefox中出现的错误。

InvalidStateError: 没有远程描述。

在Chrome中出错。

DOMException.Failed执行'addIceCandidate'on'RTCPeerConnection'。在'RTCPeerConnection'上执行'addIceCandidate'失败。处理ICE候选者时出错

编码。

if (signal.ice) {
       console.log(signal.ice);
       peerConnections.addIceCandidate(new RTCIceCandidate(signal.ice)).catch(errorHandler.message);
}
asp.net-mvc asp.net-core signalr webrtc
1个回答
0
投票

你不需要建立一个新的冰候选对象。只需要添加signal.ice作为冰候选对象就足够了。下面是一个例子 官方网站rtc指南

signalingChannel.addEventListener('message', async message => {
    if (message.iceCandidate) {
        try {
            await peerConnection.addIceCandidate(message.iceCandidate);
        } catch (e) {
            console.error('Error adding received ice candidate', e);
        }
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.