It's in a hurry! Webrtc jammed on the mobile browser and the code was interrupted.

using webrtc to get chrome on ip,PC is normal.

but mobile browsers can sometimes read ip,
and sometimes read the following sentence, which is directly stuck, and the following code is not executed.
var pc = new RTCPeerConnection (servers, mediaConstraints);

Boss, is there any way to return out if you can"t get here, and then PC and mobile phones that can get ip can still get ip normally?

online, etc. Very urgent.

Aug.04,2021

obtaining local ip, through webRTC is a security vulnerability. Some browsers have restrictions that support webRTC, but cannot get ip.


self-question and answer:

I found that browsers using UC browser kernels such as Xiaomi and Huawei, as well as UC browsers, do not support WEBRTC technology, and these browsers may get stuck when reading webRTC code, resulting in the following code can not be executed, which is very cheating.

my solution:

write a timer for 3 seconds. If you haven't got the user's ip, you can declare a failure (3 seconds is already a long time, so you can reduce it as appropriate), then you can only give a null value.


Let's first judge whether the next branch does not support it. Is there this variable under Window? if so, try catch it. No null value is given directly

if (window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection) {
    var Rtc = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
    try {
        var nrtc = new Rtc({
            iceServers: []
        });
        nrtc.createDataChannel('', {
            reliable: !1
        });
    } catch (e) {
        infoObj['ip'] = '0.0.0.0';
        return infoObj;
    }

    var e = false;
    nrtc.onicecandidate = function(Rtc) {
        ...
    };

    nrtc.createOffer(function(a) {
        nrtc.setLocalDescription(a, that.F(), that.F());
    }, that.F());

    infoObj.ip = window.currentIp || '0.0.0.0';

    return infoObj;
} else {
    infoObj['ip'] = '0.0.0.0';

    return infoObj;
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4875e-44cbb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4875e-44cbb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?