pc_test_loop.html [190:376]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
return pc1.setLocalDescription(offer);
}
// pc1.setLocal finished, call pc2.setRemote
function offerSetRemote() {
pc1.onicecandidate = function(obj) {
if (obj.candidate) {
//log("pc1 found ICE candidate: " + JSON.stringify(obj.candidate));
pc2.addIceCandidate(obj.candidate);
} else {
//log("pc1 got end-of-candidates signal");
}
}
return pc2.setRemoteDescription(pc1_offer);
};
// pc2.setRemote finished, call pc2.createAnswer
function createAnswer() {
pc2.didSetRemote = true;
while (pc2.ice_queued.length > 0) {
pc2.addIceCandidate(pc2.ice_queued.shift());
}
return pc2.createAnswer(answer_constraints);
}
// pc2.createAnswer finished, call pc2.setLocal
function answerSetLocal(answer) {
//log("Answer: " + sdpPrettyPrint(answer.sdp));
pc2_answer = answer;
return pc2.setLocalDescription(answer);
}
// pc2.setLocal finished, call pc1.setRemote
function answerSetRemote() {
pc2.onicecandidate = function(obj) {
if (obj.candidate) {
//log("pc2 found ICE candidate: " + JSON.stringify(obj.candidate));
pc1.addIceCandidate(obj.candidate);
} else {
//log("pc2 got end-of-candidates signal");
}
}
return pc1.setRemoteDescription(pc2_answer);
}
// pc1.setRemote finished, media should be running!
function finished() {
pc1.didSetRemote = true;
while (pc1.ice_queued.length > 0) {
pc1.addIceCandidate(pc1.ice_queued.shift());
}
//log("Signaling done");
}
function connected() {
if ((pc1.iceConnectionState == 'connected') &&
(pc2.iceConnectionState == 'connected')){
log("call " + rounds + " connected");
setTimeout(stop, 5000);
}
}
function start() {
var pc1config = {};
var pc2config = {};
let idp;
var myrequest = {};
myrequest.video = true;
myrequest.audio = false;
myrequest_reverse = copy_dictionary(myrequest);
myrequest_reverse.fake = true;
offer_constraints = null;
answer_constraints = null;
pc1 = new RTCPeerConnection(pc1config);
pc2 = new RTCPeerConnection(pc2config);
pc1.didSetRemote = false;
pc2.didSetRemote = false;
pc1.ice_queued = [];
pc2.ice_queued = [];
pc2.onicecandidate = function(obj) {
if (obj.candidate) {
//log("pc2 found ICE candidate: " + JSON.stringify(obj.candidate));
if (pc1.didSetRemote) {
pc1.addIceCandidate(obj.candidate);
} else {
pc1.ice_queued.push(obj.candidate);
}
} else {
//log("pc2 got end-of-candidates signal");
}
}
pc1.onicecandidate = function(obj) {
if (obj.candidate) {
//log("pc1 found ICE candidate: " + JSON.stringify(obj.candidate));
if (pc2.didSetRemote) {
pc2.addIceCandidate(obj.candidate);
} else {
pc2.ice_queued.push(obj.candidate);
}
} else {
//log("pc1 got end-of-candidates signal");
}
}
pc1.oniceconnectionstatechange = function(obj) {
//log("pc1 ICE connection state: " + pc1.iceConnectionState);
if (pc1.iceConnectionState == 'connected') {
//log('PC1: HIP HIP HOORAY');
connected();
}
}
pc2.oniceconnectionstatechange = function(obj) {
//log("pc2 ICE connection state: " + pc2.iceConnectionState);
if (pc2.iceConnectionState == 'connected') {
//log('PC2: HIP HIP HOORAY');
connected();
}
}
pc1.ontrack = function(obj) {
//log("pc1 got remote tracks from pc2 " + obj.type);
pc1video.mozSrcObject = obj.streams[0];
}
pc2.ontrack = function(obj) {
//log("pc2 got remote tracks from pc1 " + obj.type);
pc2video.mozSrcObject = obj.streams[0];
}
if (idp) {
pc1.setIdentityProvider(idp.domain, idp.protocol, idp.usera);
pc1.peerIdentity.then(id => log('pc1 connected to "' + id.name + '"'));
pc2.setIdentityProvider(idp.domain, idp.protocol, idp.userb);
pc2.peerIdentity.then(id => log('pc2 connected to "' + id.name + '"'));
}
navigator.mediaDevices.getUserMedia(myrequest).then(function(video1) {
// Add stream obtained from gUM to