Add tryGenerateIceCandidates to verify and ask media permission if necessary
This commit is contained in:
parent
ec49bdfda2
commit
87b4306e7f
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
Loading…
Reference in New Issue
Block a user