RTCPeerConnection和createDataChannel对Edge不起作用 [英] RTCPeerConnection and createDataChannel not working for Edge

查看:131
本文介绍了RTCPeerConnection和createDataChannel对Edge不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个应用程序,当一个人登录一个帐户时,设备的IP地址存储在后端和本地存储中.然后,当某人从另一个浏览器左右登录同一帐户时,它将显示一个带有最后一个登录IP地址的弹出窗口.它似乎适用于chrome和Mozilla,但不适用于边缘浏览器.它始终返回null,因为它不在pc.createDataChannel之后输入代码.

I have been working on an application where when a person logs into an account, the IP address of the device is stored in the backend and local storage. Then when a person logs into the same account from another browser or so, it will show a popup with the last login IP address. It seems to work on chrome and Mozilla but not working in edge browser. It always returns null because it's not entering the code after pc.createDataChannel.

代码段如下.

const getIpAddress = state => {
    window.RTCPeerConnection = window.RTCPeerConnection || 
window.mozRTCPeerConnection || window.webkitRTCPeerConnection || false;
let ip = false;
if (window.RTCPeerConnection) {
    ip = [];
    var pc = new RTCPeerConnection({ iceServers: [] }), noop = function 
() {
    };
    pc.createDataChannel('');
    pc.createOffer(pc.setLocalDescription.bind(pc), noop);
    pc.onicecandidate = function (event) {
        if (event && event.candidate && event.candidate.candidate) {
            var s = event.candidate.candidate.split('\n');
            ip.push(s[0].split(' ')[4]);
            localStorage.setItem('ipV4Address', ip[0]);
        }
    };
}
return state;
};

我也尝试使用适配器js,但不确定如何正确使用它.

I also tried using adapter js but not sure how to exactly use it.

推荐答案

WebRTC对等连接尚未在Edge v18浏览器上完全支持.您可以在可以使用RTCPeerConnection吗?

WebRTC Peer-to-peer connections not yet supported fully on Edge v18 browser yet. You can check your browser compatible at Can I use RTCPeerConnection ?

这篇关于RTCPeerConnection和createDataChannel对Edge不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆