【问题标题】:WebRTC Events in FirefoxFirefox 中的 WebRTC 事件
【发布时间】:2019-10-04 00:20:52
【问题描述】:

我在 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);
    })

该事件从未发生。任何想法为什么会这样?

事件应该是correct,但另一方面,MDN Web Docs 上缺少文档。

【问题讨论】:

    标签: javascript firefox events webrtc


    【解决方案1】:

    您应该使用 WebRTC 适配器,以便为您填充不受支持的事件: https://github.com/webrtc/adapter

    我在我的网页上使用它,并且 onconnectionstatechange 在 Firefox 中触发正常:

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

    【讨论】:

    猜你喜欢
    • 2015-06-09
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多