RTCPeerConnection and createDataChannel not working for Edge

故事扮演 提交于 2019-12-13 17:24:38

问题


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.

The code snippet is as below.

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;
};

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


回答1:


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 ?




回答2:


It seems that there is no way to actually get the private ip in edge browser, so had to use a third party api to get public ip and use that.



来源:https://stackoverflow.com/questions/54528582/rtcpeerconnection-and-createdatachannel-not-working-for-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!