//获取音视频.
function getUserMedia() {
try {
navigator.getUserMedia({
'audio' : true,
'video' : pVideo
}, onUserMediaSuccess, onUserMediaError);
} catch (e) {
try {
navigator.getUserMedia("video,audio", onUserMediaSuccess, onUserMediaError);
} catch (e) {
alert(e.message);
console.log(e);
}
}
}
//加载本地 视频
function onUserMediaSuccess(stream) {
console.log("User has granted access to local media.");
var url = URL.createObjectURL(stream);
localVideo.style.opacity = 1;
localVideo.src = url;
localStream = stream;
if (initiator)
maybeStart();
}
//创建 PeerConnection
function createPeerConnection() {
try {
pc = new RTCPeerConnection(pc_config);
pc.onicecandidate = onIceCandidate;
} catch (e) {
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;
}