bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/screenshare/service.js

102 lines
3.4 KiB
JavaScript
Raw Normal View History

import Screenshare from '/imports/api/screenshare';
import KurentoBridge from '/imports/api/screenshare/client/bridge';
import BridgeService from '/imports/api/screenshare/client/bridge/service';
import Settings from '/imports/ui/services/settings';
import logger from '/imports/startup/client/logger';
import { tryGenerateIceCandidates } from '/imports/utils/safari-webrtc';
import { stopWatching } from '/imports/ui/components/external-video-player/service';
import Meetings from '/imports/api/meetings';
import Auth from '/imports/ui/services/auth';
import UserListService from '/imports/ui/components/user-list/service';
import AudioService from '/imports/ui/components/audio/service';
// when the meeting information has been updated check to see if it was
// screensharing. If it has changed either trigger a call to receive video
// and display it, or end the call and hide the video
const isVideoBroadcasting = () => {
const screenshareEntry = Screenshare.findOne({ meetingId: Auth.meetingID },
{ fields: { 'screenshare.stream': 1 } });
if (!screenshareEntry) {
2017-07-26 04:56:40 +08:00
return false;
}
return !!screenshareEntry.screenshare.stream;
2019-03-09 03:41:19 +08:00
};
// if remote screenshare has been ended disconnect and hide the video stream
const presenterScreenshareHasEnded = () => {
// references a function in the global namespace inside kurento-extension.js
// that we load dynamically
KurentoBridge.kurentoExitVideo();
2019-03-09 03:41:19 +08:00
};
2020-08-20 08:36:13 +08:00
const viewScreenshare = (hasAudio) => {
const amIPresenter = UserListService.isUserPresenter(Auth.userID);
if (!amIPresenter) {
2020-08-20 08:36:13 +08:00
KurentoBridge.kurentoViewScreen(hasAudio);
} else {
KurentoBridge.kurentoViewLocalPreview();
}
};
const screenshareHasAudio = () => {
return Screenshare.findOne({ meetingId: Auth.meetingID },
{ fields: { 'screenshare.hasAudio': 1 } }).screenshare.hasAudio;
}
// if remote screenshare has been started connect and display the video stream
const presenterScreenshareHasStarted = () => {
const hasAudio = screenshareHasAudio();
2020-08-20 08:36:13 +08:00
// WebRTC restrictions may need a capture device permission to release
// useful ICE candidates on recvonly/no-gUM peers
tryGenerateIceCandidates().then(() => {
viewScreenshare(hasAudio);
}).catch((error) => {
logger.error({
logCode: 'screenshare_no_valid_candidate_gum_failure',
extraInfo: {
errorName: error.name,
errorMessage: error.message,
},
}, `Forced gUM to release additional ICE candidates failed due to ${error.name}.`);
// The fallback gUM failed. Try it anyways and hope for the best.
viewScreenshare(hasAudio);
});
2019-03-09 03:41:19 +08:00
};
const shareScreen = (onFail) => {
// stop external video share if running
const meeting = Meetings.findOne({ meetingId: Auth.meetingID });
if (meeting && meeting.externalVideoUrl) {
stopWatching();
}
BridgeService.getScreenStream().then(stream => {
KurentoBridge.kurentoShareScreen(onFail, stream);
}).catch(onFail);
2019-03-09 03:41:19 +08:00
};
2017-09-13 04:47:06 +08:00
const screenShareEndAlert = () => AudioService
.playAlertSound(`${Meteor.settings.public.app.cdn
+ Meteor.settings.public.app.basename}`
+ '/resources/sounds/ScreenshareOff.mp3');
const unshareScreen = () => {
KurentoBridge.kurentoExitScreenShare();
screenShareEndAlert();
2019-03-09 03:41:19 +08:00
};
const dataSavingSetting = () => Settings.dataSaving.viewScreenshare;
export {
2019-03-09 03:41:19 +08:00
isVideoBroadcasting,
presenterScreenshareHasEnded,
presenterScreenshareHasStarted,
shareScreen,
screenShareEndAlert,
unshareScreen,
dataSavingSetting,
};