Web RTC 入门

WebRTC 是一项实时通讯技术,它允许网络应用或者站点,在不借助中间媒介的情况下,建立浏览器之间点对点的连接,实现视频流和(或)音频流或者其他任意数据的传输。

在最近的项目中使用了webRTC的一些功能比如获取客户端的IP地址和代理的IP地址,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
try{
var PeerConnection = Win.RTCPeerConnection || Win.mozRTCPeerConnection || Win.webkitRTCPeerConnection;
if (PeerConnection){
(function(pc){
var noop = function() {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/g,
localIPs = {},
res = [];

function ipIterate(ip) {
if(!localIPs[ip]) res.push(ip);
localIPs[ip] = true;
data.internalip = res.join(',')
}

pc.createDataChannel('__g__');
pc.onicecandidate= function(e){
if (e.candidate && e.candidate.candidate && !data.internalip){
new _Array(e.candidate.candidate.match(ipRegex))._forEach(ipIterate)
}
};
pc.createOffer(function(o){
new _Array(o.sdp.split('\n'))._forEach(function(line) {
if (line.indexOf('candidata') < 0) return;
new _Array(line.match(ipRegex))._forEach(ipIterate);
})

pc.setLocalDescription(o, noop, noop);
}, noop )
})(new PeerConnection({iceServers: [{urls: "stun:stun.l.google.com:19302"}]}))
}
}catch(e){}
hi you can see me