![
//创建 PeerConnection
function createPeerConnection() {
var pc_config = {"iceServers": [
{'url': 'turn:xxxxxx:3478?transport=udp',
'credential':'simon',
'username':'user'}
]};
try {
pc = new RTCPeerConnection(pc_config);
console.log("*********新建对象************");
pc.onicecandidate = onIceCandidate;
} catch (e) {
console.log("*********cat************");
try {
var stun_server = "";
if (pc_config.iceServers.length !== 0) {
stun_server = pc_config.iceServers[0].url.replace('stun:', 'STUN ');
}
pc = new RTCPeerConnection(stun_server, onIceCandidate);
isRTCPeerConnection = false;
console.log("Created webkitPeerConnnection00 with config \"" + stun_server + "\".");
} catch (e) {
alert("Failed to create PeerConnection, exception: " + e.message);
return;
}
}
pc.onconnecting = onSessionConnecting;
pc.onopen = onSessionOpened;
pc.onaddstream = onRemoteStreamAdded;
pc.onremovestream = onRemoteStreamRemoved;
}
图片说明](https://img-ask.csdn.net/upload/201811/05/1541414896_916360.png)
//创建 PeerConnection