Add tryGenerateIceCandidates to verify and ask media permission if necessary

This commit is contained in:
Gustavo Trott 2019-01-10 21:22:14 -02:00
parent ec49bdfda2
commit 87b4306e7f

View File

@ -10,19 +10,37 @@ export function canGenerateIceCandidates() {
if(countIceCandidates) return;
if (e.candidate) {
countIceCandidates++;
resolve(true);
resolve();
}
}
pc.onicegatheringstatechange = function(e) {
if(e.currentTarget.iceGatheringState == 'complete' && countIceCandidates == 0) reject(true);
if(e.currentTarget.iceGatheringState == 'complete' && countIceCandidates == 0) reject();
}
setTimeout(function(){
if(!countIceCandidates) reject(true);
if(!countIceCandidates) reject();
}, 3000);
p = pc.createOffer({offerToReceiveVideo: true});
p.then( answer => {pc.setLocalDescription(answer) ; } )
});
};
export function tryGenerateIceCandidates() {
return new Promise((resolve, reject) => {
canGenerateIceCandidates().then(ok => {
resolve();
}).catch(e => {
navigator.mediaDevices.getUserMedia({audio: true, video: false}).then(function (stream) {
canGenerateIceCandidates().then(ok => {
resolve();
}).catch(e => {
reject();
});
}).catch(e => {
reject();
});
});
});
};