火狐浏览器中的WebRTC事件

5
我在Chrome中有一个可用的WebRTC连接。它作为聊天应用程序的一部分使用1个数据通道。
我想要支持Firefox,因此需要更改一些不受支持的事件:对于RTCPeerConnection以及DataChannel
数据通道的更改按预期工作:
    //chrome implenetation
    dc.onopen = this.conncectionStats.bind(this);
    dc.onmessage = onMessage;
    // chrome and firefox
    dc.addEventListener('open', (event) => {
        this.conncectionStats.bind(this)
    });
    dc.addEventListener('message', (event) => {
        onMessage(event)
    });

然而,当更改PeerConnection时问题就出现了:
    // chrome implenetation
    pc.onconnectionstatechange  = this.onConnectionStateChange.bind(this);
    // chrome and firefox
    pc.addEventListener('onconnectionstatechange', (event) => {
        console.log("onconnectionstatechange fired")
        this.onConnectionStateChange.bind(this);
    })

这个事件从未发生过。有什么想法为什么会这样?
这个事件应该是正确的,但另一方面,MDN Web Docs上缺少文档。
1个回答

5
你应该使用WebRTC适配器,这样不支持的事件将被自动替换: https://github.com/webrtc/adapter 我在我的网页上使用它,在Firefox中可以正常触发onconnectionstatechange事件:
...
pc.onconnectionstatechange = onConnStateChange;
...

function onConnStateChange(event) {
        if (pc.connectionState === "failed") {
            Terminate();
            alert("Connection failed; playback stopped");
        }
    }

使用adapter.js 与html + js一起与webpack一起 - Noah Studach

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接