mirror of https://github.com/OpenVidu/openvidu.git
openvidu-browser: error callback added to getDisplayMedia
parent
67fdfb47e7
commit
7060597690
|
@ -455,7 +455,7 @@ export class Publisher extends StreamManager {
|
|||
resolve();
|
||||
};
|
||||
|
||||
const afterGetMedia = (mediaStream: MediaStream, definedAudioConstraint) => {
|
||||
const getMediaSuccess = (mediaStream: MediaStream, definedAudioConstraint) => {
|
||||
this.clearPermissionDialogTimer(startTime, timeForDialogEvent);
|
||||
if (this.stream.isSendScreen() && this.stream.isSendAudio()) {
|
||||
// When getting desktop as user media audio constraint must be false. Now we can ask for it if required
|
||||
|
@ -505,61 +505,8 @@ export class Publisher extends StreamManager {
|
|||
}
|
||||
};
|
||||
|
||||
// Check if new constraints need to be generated. No constraints needed if
|
||||
// - video track is given and no audio
|
||||
// - audio track is given and no video
|
||||
// - both video and audio tracks are given
|
||||
if ((typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack && !this.properties.audioSource)
|
||||
|| (typeof MediaStreamTrack !== 'undefined' && this.properties.audioSource instanceof MediaStreamTrack && !this.properties.videoSource)
|
||||
|| (typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack && this.properties.audioSource instanceof MediaStreamTrack)) {
|
||||
const mediaStream = new MediaStream();
|
||||
if (typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack) {
|
||||
mediaStream.addTrack((<MediaStreamTrack>this.properties.videoSource));
|
||||
}
|
||||
if (typeof MediaStreamTrack !== 'undefined' && this.properties.audioSource instanceof MediaStreamTrack) {
|
||||
mediaStream.addTrack((<MediaStreamTrack>this.properties.audioSource));
|
||||
}
|
||||
// MediaStreamTracks are handled within callback - just call callback with new MediaStream() and let it handle the sources
|
||||
successCallback(mediaStream);
|
||||
// Return as we do not need to process further
|
||||
return;
|
||||
}
|
||||
|
||||
this.openvidu.generateMediaConstraints(this.properties)
|
||||
.then(myConstraints => {
|
||||
|
||||
constraints = myConstraints;
|
||||
|
||||
const outboundStreamOptions = {
|
||||
mediaConstraints: constraints,
|
||||
publisherProperties: this.properties
|
||||
};
|
||||
|
||||
this.stream.setOutboundStreamOptions(outboundStreamOptions);
|
||||
|
||||
if (this.stream.isSendVideo() || this.stream.isSendAudio()) {
|
||||
const definedAudioConstraint = ((constraints.audio === undefined) ? true : constraints.audio);
|
||||
constraintsAux.audio = this.stream.isSendScreen() ? false : definedAudioConstraint;
|
||||
constraintsAux.video = constraints.video;
|
||||
startTime = Date.now();
|
||||
this.setPermissionDialogTimer(timeForDialogEvent);
|
||||
|
||||
if (this.stream.isSendScreen() && navigator.mediaDevices['getDisplayMedia']) {
|
||||
navigator.mediaDevices['getDisplayMedia']({ video: true })
|
||||
.then(mediaStream => {
|
||||
afterGetMedia(mediaStream, definedAudioConstraint);
|
||||
});
|
||||
} else {
|
||||
|
||||
let userMediaFunc = () => {
|
||||
navigator.mediaDevices.getUserMedia(constraintsAux)
|
||||
.then(mediaStream => {
|
||||
afterGetMedia(mediaStream, definedAudioConstraint);
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
const getMediaError = error => {
|
||||
console.error(error);
|
||||
|
||||
this.clearPermissionDialogTimer(startTime, timeForDialogEvent);
|
||||
if (error.name === 'Error') {
|
||||
// Safari OverConstrainedError has as name property 'Error' instead of 'OverConstrainedError'
|
||||
|
@ -629,8 +576,66 @@ export class Publisher extends StreamManager {
|
|||
errorMessage = error.toString();
|
||||
errorCallback(new OpenViduError(errorName, errorMessage));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Check if new constraints need to be generated. No constraints needed if
|
||||
// - video track is given and no audio
|
||||
// - audio track is given and no video
|
||||
// - both video and audio tracks are given
|
||||
if ((typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack && !this.properties.audioSource)
|
||||
|| (typeof MediaStreamTrack !== 'undefined' && this.properties.audioSource instanceof MediaStreamTrack && !this.properties.videoSource)
|
||||
|| (typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack && this.properties.audioSource instanceof MediaStreamTrack)) {
|
||||
const mediaStream = new MediaStream();
|
||||
if (typeof MediaStreamTrack !== 'undefined' && this.properties.videoSource instanceof MediaStreamTrack) {
|
||||
mediaStream.addTrack((<MediaStreamTrack>this.properties.videoSource));
|
||||
}
|
||||
if (typeof MediaStreamTrack !== 'undefined' && this.properties.audioSource instanceof MediaStreamTrack) {
|
||||
mediaStream.addTrack((<MediaStreamTrack>this.properties.audioSource));
|
||||
}
|
||||
// MediaStreamTracks are handled within callback - just call callback with new MediaStream() and let it handle the sources
|
||||
successCallback(mediaStream);
|
||||
// Return as we do not need to process further
|
||||
return;
|
||||
}
|
||||
|
||||
this.openvidu.generateMediaConstraints(this.properties)
|
||||
.then(myConstraints => {
|
||||
|
||||
constraints = myConstraints;
|
||||
|
||||
const outboundStreamOptions = {
|
||||
mediaConstraints: constraints,
|
||||
publisherProperties: this.properties
|
||||
};
|
||||
|
||||
this.stream.setOutboundStreamOptions(outboundStreamOptions);
|
||||
|
||||
if (this.stream.isSendVideo() || this.stream.isSendAudio()) {
|
||||
const definedAudioConstraint = ((constraints.audio === undefined) ? true : constraints.audio);
|
||||
constraintsAux.audio = this.stream.isSendScreen() ? false : definedAudioConstraint;
|
||||
constraintsAux.video = constraints.video;
|
||||
startTime = Date.now();
|
||||
this.setPermissionDialogTimer(timeForDialogEvent);
|
||||
|
||||
if (this.stream.isSendScreen() && navigator.mediaDevices['getDisplayMedia']) {
|
||||
|
||||
navigator.mediaDevices['getDisplayMedia']({ video: true })
|
||||
.then(mediaStream => {
|
||||
getMediaSuccess(mediaStream, definedAudioConstraint);
|
||||
})
|
||||
.catch(error => {
|
||||
getMediaError(error);
|
||||
});
|
||||
} else {
|
||||
|
||||
let userMediaFunc = () => {
|
||||
navigator.mediaDevices.getUserMedia(constraintsAux)
|
||||
.then(mediaStream => {
|
||||
getMediaSuccess(mediaStream, definedAudioConstraint);
|
||||
})
|
||||
.catch(error => {
|
||||
getMediaError(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue