RTCPeerConnection.onicecandidate 无效

RTCPeerConnection.onicecandidate does not work

我已连接到 stun turn 服务器,但 onicecandidate 不工作。我是来自本地文件的 运行 应用程序。

脚本:

const pc = new RTCPeerConnection({
        iceServers:[{
            urls:"stun:stun.l.google.com:19302",
        },
        {
            url: 'turn:turn.bistri.com:80',
            credential: 'homeo',
            username: 'homeo'
        }]
    })
    const dc = pc.createDataChannel("channel")
    pc.onicecandidate = (e) => {
        console.log("ok")
    }
    dc.onopen = () => {
        console.log("Data Channel Opened")
    }
    dc.onmessage = (data) => {
        console.log("Message:"+data)
    }

调用 pc.setLocalDescription.

时会发生 onicecandidate 事件

您还没有调用 setLocalDescription。