bigbluebutton-Github/bigbluebutton-html5/imports/api/screenshare/client/bridge/kurento.js

107 lines
3.0 KiB
JavaScript
Raw Normal View History

import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
import BridgeService from './service';
import { fetchWebRTCMappedStunTurnServers } from '/imports/utils/fetchStunTurnServers';
import { log } from '/imports/ui/services/api';
const SFU_CONFIG = Meteor.settings.public.kurento;
const SFU_URL = SFU_CONFIG.wsUrl;
const CHROME_DEFAULT_EXTENSION_KEY = SFU_CONFIG.chromeDefaultExtensionKey;
const CHROME_CUSTOM_EXTENSION_KEY = SFU_CONFIG.chromeExtensionKey;
const CHROME_SCREENSHARE_SOURCES = SFU_CONFIG.chromeScreenshareSources;
const FIREFOX_SCREENSHARE_SOURCE = SFU_CONFIG.firefoxScreenshareSource;
const SCREENSHARE_VIDEO_TAG = 'screenshareVideo';
2018-04-27 06:52:46 +08:00
const CHROME_EXTENSION_KEY = CHROME_CUSTOM_EXTENSION_KEY === 'KEY' ? CHROME_DEFAULT_EXTENSION_KEY : CHROME_CUSTOM_EXTENSION_KEY;
2018-04-27 06:52:46 +08:00
const getUserId = () => Auth.userID;
2018-04-27 06:52:46 +08:00
const getMeetingId = () => Auth.meetingID;
const getUsername = () => Users.findOne({ userId: getUserId() }).name;
const getSessionToken = () => Auth.sessionToken;
const logFunc = (type, message, options) => {
const userId = getUserId();
const userName = getUsername();
log(type, message, Object.assign(options, {userId, userName, topic: options.topic || 'screenshare'}));
};
const logger = {
log: function (message, options = {}) {
logFunc('info', message, options);
},
error: function (message, options = {}) {
logFunc('error', message, options);
},
debug: function (message, options = {}) {
logFunc('debug', message, options);
},
};
export default class KurentoScreenshareBridge {
async kurentoWatchVideo() {
let iceServers = [];
try {
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
} catch (error) {
logger.error('Screenshare bridge failed to fetch STUN/TURN info, using default');
} finally {
const options = {
wsUrl: SFU_URL,
iceServers,
logger
};
window.kurentoWatchVideo(
SCREENSHARE_VIDEO_TAG,
BridgeService.getConferenceBridge(),
getUserId(),
getMeetingId(),
null,
null,
options
);
};
}
kurentoExitVideo() {
window.kurentoExitVideo();
}
2017-09-13 04:47:06 +08:00
async kurentoShareScreen() {
let iceServers = [];
try {
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
} catch (error) {
logger.error('Screenshare bridge failed to fetch STUN/TURN info, using default');
} finally {
const options = {
wsUrl: SFU_URL,
chromeExtension: CHROME_EXTENSION_KEY,
chromeScreenshareSources: CHROME_SCREENSHARE_SOURCES,
firefoxScreenshareSource: FIREFOX_SCREENSHARE_SOURCE,
iceServers,
logger,
};
window.kurentoShareScreen(
SCREENSHARE_VIDEO_TAG,
BridgeService.getConferenceBridge(),
getUserId(),
getMeetingId(),
null,
null,
options
);
}
2017-09-13 04:47:06 +08:00
}
kurentoExitScreenShare() {
window.kurentoExitScreenShare();
}
}