2017-10-12 10:00:28 +08:00
|
|
|
import Meetings from '/imports/api/meetings';
|
2020-05-15 00:36:03 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
|
|
|
|
const {
|
|
|
|
constraints: GDM_CONSTRAINTS,
|
|
|
|
} = Meteor.settings.public.kurento.screenshare;
|
|
|
|
|
|
|
|
const hasDisplayMedia = (typeof navigator.getDisplayMedia === 'function'
|
|
|
|
|| (navigator.mediaDevices && typeof navigator.mediaDevices.getDisplayMedia === 'function'));
|
2017-07-25 03:29:34 +08:00
|
|
|
|
2017-07-26 21:18:15 +08:00
|
|
|
const getConferenceBridge = () => Meetings.findOne().voiceProp.voiceConf;
|
2017-07-25 03:29:34 +08:00
|
|
|
|
2020-05-15 00:36:03 +08:00
|
|
|
const getScreenStream = async () => {
|
|
|
|
const gDMCallback = (stream) => {
|
|
|
|
if (typeof stream.getVideoTracks === 'function'
|
|
|
|
&& typeof constraints.video === 'object') {
|
|
|
|
stream.getVideoTracks().forEach(track => {
|
|
|
|
if (typeof track.applyConstraints === 'function') {
|
|
|
|
track.applyConstraints(constraints.video).catch(error => {
|
|
|
|
logger.warn({
|
|
|
|
logCode: 'screenshare_videoconstraint_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
},
|
|
|
|
'Error applying screenshare video constraint');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof stream.getAudioTracks === 'function'
|
|
|
|
&& typeof constraints.audio === 'object') {
|
|
|
|
stream.getAudioTracks().forEach(track => {
|
|
|
|
if (typeof track.applyConstraints === 'function') {
|
2020-05-15 01:00:58 +08:00
|
|
|
track.applyConstraints(constraints.audio).catch(error => {
|
2020-05-15 00:36:03 +08:00
|
|
|
logger.warn({
|
|
|
|
logCode: 'screenshare_audioconstraint_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'Error applying screenshare audio constraint');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
const constraints = hasDisplayMedia ? GDM_CONSTRAINTS : null;
|
|
|
|
|
|
|
|
// getDisplayMedia isn't supported, generate no stream and let the legacy
|
|
|
|
// constraint fetcher work its way on kurento-extension.js
|
|
|
|
if (constraints == null) {
|
|
|
|
return Promise.resolve();
|
|
|
|
} else {
|
|
|
|
if (typeof navigator.getDisplayMedia === 'function') {
|
|
|
|
return navigator.getDisplayMedia(constraints)
|
|
|
|
.then(gDMCallback)
|
|
|
|
.catch(error => {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'screenshare_getdisplaymedia_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'getDisplayMedia call failed');
|
|
|
|
return Promise.resolve();
|
|
|
|
});
|
|
|
|
} else if (navigator.mediaDevices && typeof navigator.mediaDevices.getDisplayMedia === 'function') {
|
|
|
|
return navigator.mediaDevices.getDisplayMedia(constraints)
|
|
|
|
.then(gDMCallback)
|
|
|
|
.catch(error => {
|
|
|
|
logger.error({
|
|
|
|
logCode: 'screenshare_getdisplaymedia_failed',
|
|
|
|
extraInfo: { errorName: error.name, errorCode: error.code },
|
|
|
|
}, 'getDisplayMedia call failed');
|
|
|
|
return Promise.resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-25 03:29:34 +08:00
|
|
|
export default {
|
2020-05-15 00:36:03 +08:00
|
|
|
hasDisplayMedia,
|
2017-07-25 03:29:34 +08:00
|
|
|
getConferenceBridge,
|
2020-05-15 00:36:03 +08:00
|
|
|
getScreenStream,
|
2017-07-25 03:29:34 +08:00
|
|
|
};
|