2017-11-11 11:41:37 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-09-09 01:00:00 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import BridgeService from './service';
|
2018-07-10 05:29:27 +08:00
|
|
|
import { fetchWebRTCMappedStunTurnServers } from '/imports/utils/fetchStunTurnServers';
|
2018-07-27 02:26:56 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2018-08-23 02:10:08 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
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';
|
2017-11-18 02:55:59 +08:00
|
|
|
|
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;
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2018-08-23 02:51:25 +08:00
|
|
|
const ICE_CONNECTION_FAILED = "ICE connection failed";
|
2018-08-23 02:10:08 +08:00
|
|
|
|
2018-04-27 06:52:46 +08:00
|
|
|
const getUserId = () => Auth.userID;
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2018-04-27 06:52:46 +08:00
|
|
|
const getMeetingId = () => Auth.meetingID;
|
|
|
|
|
|
|
|
const getUsername = () => Users.findOne({ userId: getUserId() }).name;
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2018-07-10 05:29:27 +08:00
|
|
|
const getSessionToken = () => Auth.sessionToken;
|
|
|
|
|
2018-07-19 05:04:20 +08:00
|
|
|
const logFunc = (type, message, options) => {
|
|
|
|
const userId = getUserId();
|
|
|
|
const userName = getUsername();
|
|
|
|
|
2018-07-27 03:29:55 +08:00
|
|
|
const topic = options.topic || 'screenshare';
|
2018-07-27 02:26:56 +08:00
|
|
|
|
2018-07-27 03:29:55 +08:00
|
|
|
logger[type]({obj: Object.assign(options, {userId, userName, topic})}, `[${topic}] ${message}`);
|
2018-07-19 05:04:20 +08:00
|
|
|
};
|
|
|
|
|
2018-07-27 02:26:56 +08:00
|
|
|
const modLogger = {
|
|
|
|
info: function (message, options = {}) {
|
2018-07-19 05:04:20 +08:00
|
|
|
logFunc('info', message, options);
|
|
|
|
},
|
|
|
|
error: function (message, options = {}) {
|
|
|
|
logFunc('error', message, options);
|
|
|
|
},
|
|
|
|
debug: function (message, options = {}) {
|
|
|
|
logFunc('debug', message, options);
|
|
|
|
},
|
2018-07-27 02:26:56 +08:00
|
|
|
warn: (message, options = {}) => {
|
|
|
|
logFunc('warn', message, options);
|
|
|
|
},
|
2018-07-19 05:04:20 +08:00
|
|
|
};
|
|
|
|
|
2017-09-09 01:00:00 +08:00
|
|
|
export default class KurentoScreenshareBridge {
|
2018-07-10 05:29:27 +08:00
|
|
|
async kurentoWatchVideo() {
|
|
|
|
let iceServers = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
|
|
|
|
} catch (error) {
|
2018-07-19 05:04:20 +08:00
|
|
|
logger.error('Screenshare bridge failed to fetch STUN/TURN info, using default');
|
2018-07-10 05:29:27 +08:00
|
|
|
} finally {
|
|
|
|
const options = {
|
|
|
|
wsUrl: SFU_URL,
|
|
|
|
iceServers,
|
2018-07-27 02:26:56 +08:00
|
|
|
logger: modLogger
|
2018-07-10 05:29:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
window.kurentoWatchVideo(
|
|
|
|
SCREENSHARE_VIDEO_TAG,
|
|
|
|
BridgeService.getConferenceBridge(),
|
|
|
|
getUserId(),
|
|
|
|
getMeetingId(),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
options
|
|
|
|
);
|
|
|
|
};
|
2017-09-09 01:00:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kurentoExitVideo() {
|
|
|
|
window.kurentoExitVideo();
|
|
|
|
}
|
2017-09-13 04:47:06 +08:00
|
|
|
|
2018-08-23 02:10:08 +08:00
|
|
|
async kurentoShareScreen(onFail) {
|
2018-07-10 05:29:27 +08:00
|
|
|
let iceServers = [];
|
|
|
|
try {
|
|
|
|
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
|
|
|
|
} catch (error) {
|
2018-07-19 05:04:20 +08:00
|
|
|
logger.error('Screenshare bridge failed to fetch STUN/TURN info, using default');
|
2018-07-10 05:29:27 +08:00
|
|
|
} finally {
|
|
|
|
const options = {
|
|
|
|
wsUrl: SFU_URL,
|
|
|
|
chromeExtension: CHROME_EXTENSION_KEY,
|
|
|
|
chromeScreenshareSources: CHROME_SCREENSHARE_SOURCES,
|
|
|
|
firefoxScreenshareSource: FIREFOX_SCREENSHARE_SOURCE,
|
|
|
|
iceServers,
|
2018-07-27 02:26:56 +08:00
|
|
|
logger: modLogger,
|
2018-07-10 05:29:27 +08:00
|
|
|
};
|
|
|
|
window.kurentoShareScreen(
|
|
|
|
SCREENSHARE_VIDEO_TAG,
|
|
|
|
BridgeService.getConferenceBridge(),
|
|
|
|
getUserId(),
|
|
|
|
getMeetingId(),
|
2018-08-23 02:10:08 +08:00
|
|
|
onFail,
|
2018-07-10 05:29:27 +08:00
|
|
|
null,
|
|
|
|
options
|
|
|
|
);
|
|
|
|
}
|
2017-09-13 04:47:06 +08:00
|
|
|
}
|
2017-11-06 23:39:55 +08:00
|
|
|
|
|
|
|
kurentoExitScreenShare() {
|
|
|
|
window.kurentoExitScreenShare();
|
|
|
|
}
|
2017-09-09 01:00:00 +08:00
|
|
|
}
|