2

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.

Harsh Khare
  • 507
  • 1
  • 3
  • 13

2 Answers2

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 ?

Şivā SankĂr
  • 1,966
  • 1
  • 18
  • 34
  • I went through another thread where they suggested to use adapter js which is the webrtc pollyfill. Any idea how to exactly use that to workaround the edge support? – Kishore Kumar A Feb 05 '19 at 07:00
  • I didn't worked with `adapter.js` yet, You can give a try with [official WebRTC polyfill](https://stackoverflow.com/a/36828313/5849770) – Şivā SankĂr Feb 05 '19 at 07:04
0

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.