Audio-only also works if camera access is blocked but mic is allowed

pull/20/head
pabloFuente 2017-08-22 12:09:44 +02:00
parent ea78653374
commit 1754101d52
5 changed files with 67 additions and 40 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -374,32 +374,46 @@ export class Stream {
private requestCameraAccesAux(constraints, callback) { private requestCameraAccesAux(constraints, callback) {
navigator.mediaDevices.getUserMedia(constraints) navigator.mediaDevices.getUserMedia(constraints)
.then(userStream => { .then(userStream => {
this.accessIsAllowed = true; this.cameraAccessSuccess(userStream, callback);
this.accessIsDenied = false;
this.ee.emitEvent('access-allowed-by-publisher');
if (userStream.getAudioTracks()[0] != null) {
userStream.getAudioTracks()[0].enabled = this.sendAudio;
}
if (userStream.getVideoTracks()[0] != null) {
userStream.getVideoTracks()[0].enabled = this.sendVideo;
}
this.wrStream = userStream;
this.emitSrcEvent(this.wrStream);
callback(undefined, this);
}) })
.catch(error => { .catch(error => {
this.accessIsDenied = true; // Try to ask for microphone only
this.accessIsAllowed = false; navigator.mediaDevices.getUserMedia({ audio: true, video: false })
this.ee.emitEvent('access-denied-by-publisher'); .then(userStream => {
constraints.video = false;
this.sendVideo = false;
this.audioOnly = true;
this.cameraAccessSuccess(userStream, callback);
})
.catch(error => {
this.accessIsDenied = true;
this.accessIsAllowed = false;
this.ee.emitEvent('access-denied-by-publisher');
console.error("Access denied", error); console.error("Access denied", error);
callback(error, this); callback(error, this);
});
}); });
} }
private cameraAccessSuccess(userStream, callback) {
this.accessIsAllowed = true;
this.accessIsDenied = false;
this.ee.emitEvent('access-allowed-by-publisher');
if (userStream.getAudioTracks()[0] != null) {
userStream.getAudioTracks()[0].enabled = this.sendAudio;
}
if (userStream.getVideoTracks()[0] != null) {
userStream.getVideoTracks()[0].enabled = this.sendVideo;
}
this.wrStream = userStream;
this.emitSrcEvent(this.wrStream);
callback(undefined, this);
}
private userMediaHasVideo(callback) { private userMediaHasVideo(callback) {
navigator.mediaDevices.enumerateDevices().then(function (mediaDevices) { navigator.mediaDevices.enumerateDevices().then(function (mediaDevices) {
var videoInput = mediaDevices.filter(function (deviceInfo) { var videoInput = mediaDevices.filter(function (deviceInfo) {