01b53728f8
Add check to prevent re-handling autoplay multiple times for cams Screenshare viewer element muted by default
109 lines
3.6 KiB
JavaScript
Executable File
109 lines
3.6 KiB
JavaScript
Executable File
import Auth from '/imports/ui/services/auth';
|
|
import BridgeService from './service';
|
|
import { fetchWebRTCMappedStunTurnServers } from '/imports/utils/fetchStunTurnServers';
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
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';
|
|
|
|
const CHROME_EXTENSION_KEY = CHROME_CUSTOM_EXTENSION_KEY === 'KEY' ? CHROME_DEFAULT_EXTENSION_KEY : CHROME_CUSTOM_EXTENSION_KEY;
|
|
|
|
const getUserId = () => Auth.userID;
|
|
|
|
const getMeetingId = () => Auth.meetingID;
|
|
|
|
const getSessionToken = () => Auth.sessionToken;
|
|
|
|
export default class KurentoScreenshareBridge {
|
|
async kurentoWatchVideo() {
|
|
let iceServers = [];
|
|
|
|
try {
|
|
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
|
|
} catch (error) {
|
|
logger.error({ logCode: 'sfuviewscreen_fetchstunturninfo_error', extraInfo: { error } },
|
|
'Screenshare bridge failed to fetch STUN/TURN info, using default');
|
|
} finally {
|
|
const options = {
|
|
wsUrl: Auth.authenticateURL(SFU_URL),
|
|
iceServers,
|
|
logger,
|
|
};
|
|
|
|
const onSuccess = () => {
|
|
const { webRtcPeer } = window.kurentoManager.kurentoVideo;
|
|
if (webRtcPeer) {
|
|
const screenshareTag = document.getElementById(SCREENSHARE_VIDEO_TAG);
|
|
const stream = webRtcPeer.getRemoteStream();
|
|
screenshareTag.muted = true;
|
|
screenshareTag.pause();
|
|
screenshareTag.srcObject = stream;
|
|
screenshareTag.play().catch((error) => {
|
|
// NotAllowedError equals autoplay issues, fire autoplay handling event
|
|
if (error.name === 'NotAllowedError') {
|
|
const tagFailedEvent = new CustomEvent('screensharePlayFailed',
|
|
{ detail: { mediaElement: screenshareTag } });
|
|
window.dispatchEvent(tagFailedEvent);
|
|
}
|
|
logger.warn({
|
|
logCode: 'sfuscreenshareview_play_maybe_error',
|
|
extraInfo: { error },
|
|
}, `Screenshare viewer media play failed due to ${error.name}`);
|
|
});
|
|
}
|
|
};
|
|
|
|
window.kurentoWatchVideo(
|
|
SCREENSHARE_VIDEO_TAG,
|
|
BridgeService.getConferenceBridge(),
|
|
getUserId(),
|
|
getMeetingId(),
|
|
null,
|
|
onSuccess,
|
|
options,
|
|
);
|
|
}
|
|
}
|
|
|
|
kurentoExitVideo() {
|
|
window.kurentoExitVideo();
|
|
}
|
|
|
|
async kurentoShareScreen(onFail) {
|
|
let iceServers = [];
|
|
try {
|
|
iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
|
|
} catch (error) {
|
|
logger.error({ logCode: 'sfusharescreen_fetchstunturninfo_error' },
|
|
'Screenshare bridge failed to fetch STUN/TURN info, using default');
|
|
} finally {
|
|
const options = {
|
|
wsUrl: Auth.authenticateURL(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(),
|
|
onFail,
|
|
null,
|
|
options,
|
|
);
|
|
}
|
|
}
|
|
|
|
kurentoExitScreenShare() {
|
|
window.kurentoExitScreenShare();
|
|
}
|
|
}
|