2023-03-25 04:48:00 +08:00
|
|
|
import React, { memo, useState } from 'react';
|
2018-07-10 03:04:24 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2021-03-12 02:49:14 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2021-04-01 01:13:36 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2021-04-01 19:14:24 +08:00
|
|
|
import browserInfo from '/imports/utils/browserInfo';
|
2018-08-23 02:10:08 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
|
|
|
import { notify } from '/imports/ui/services/notification';
|
2024-01-20 02:40:27 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
2021-10-26 03:49:51 +08:00
|
|
|
import Styled from './styles';
|
2020-05-15 00:36:03 +08:00
|
|
|
import ScreenshareBridgeService from '/imports/api/screenshare/client/bridge/service';
|
2020-12-10 06:00:54 +08:00
|
|
|
import {
|
|
|
|
shareScreen,
|
|
|
|
screenshareHasEnded,
|
|
|
|
} from '/imports/ui/components/screenshare/service';
|
2021-01-12 23:24:01 +08:00
|
|
|
import { SCREENSHARING_ERRORS } from '/imports/api/screenshare/client/bridge/errors';
|
2022-06-17 03:59:01 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2023-03-25 04:48:00 +08:00
|
|
|
import { parsePayloads } from 'sdp-transform';
|
2024-01-20 02:40:27 +08:00
|
|
|
import { EXTERNAL_VIDEO_STOP } from '../../external-video-player/mutations';
|
2021-01-12 23:24:01 +08:00
|
|
|
|
2021-04-01 01:13:36 +08:00
|
|
|
const { isMobile } = deviceInfo;
|
2022-11-09 09:50:16 +08:00
|
|
|
const { isSafari, isTabletApp } = browserInfo;
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2018-07-10 03:04:24 +08:00
|
|
|
const propTypes = {
|
2021-03-12 02:49:14 +08:00
|
|
|
intl: PropTypes.objectOf(Object).isRequired,
|
2020-12-10 06:00:54 +08:00
|
|
|
enabled: PropTypes.bool.isRequired,
|
2024-02-17 04:25:43 +08:00
|
|
|
amIPresenter: PropTypes.bool,
|
2023-03-28 05:40:08 +08:00
|
|
|
isScreenBroadcasting: PropTypes.bool.isRequired,
|
2019-06-27 00:29:34 +08:00
|
|
|
isMeteorConnected: PropTypes.bool.isRequired,
|
2019-05-29 04:46:29 +08:00
|
|
|
screenshareDataSavingSetting: PropTypes.bool.isRequired,
|
2018-07-10 03:04:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
desktopShareLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.desktopShareLabel',
|
|
|
|
description: 'Desktop Share option label',
|
|
|
|
},
|
|
|
|
stopDesktopShareLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.stopDesktopShareLabel',
|
|
|
|
description: 'Stop Desktop Share option label',
|
|
|
|
},
|
|
|
|
desktopShareDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.desktopShareDesc',
|
|
|
|
description: 'adds context to desktop share option',
|
|
|
|
},
|
|
|
|
stopDesktopShareDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.stopDesktopShareDesc',
|
|
|
|
description: 'adds context to stop desktop share option',
|
|
|
|
},
|
2020-05-15 21:10:52 +08:00
|
|
|
screenShareNotSupported: {
|
|
|
|
id: 'app.media.screenshare.notSupported',
|
|
|
|
descriptions: 'error message when trying share screen on unsupported browsers',
|
2020-04-13 23:31:16 +08:00
|
|
|
},
|
|
|
|
screenShareUnavailable: {
|
|
|
|
id: 'app.media.screenshare.unavailable',
|
|
|
|
descriptions: 'title for unavailable screen share modal',
|
|
|
|
},
|
2021-01-12 23:24:01 +08:00
|
|
|
finalError: {
|
|
|
|
id: 'app.screenshare.screenshareFinalError',
|
|
|
|
description: 'Screen sharing failures with no recovery procedure',
|
2019-09-11 00:20:40 +08:00
|
|
|
},
|
2021-01-12 23:24:01 +08:00
|
|
|
retryError: {
|
|
|
|
id: 'app.screenshare.screenshareRetryError',
|
|
|
|
description: 'Screen sharing failures where a retry is recommended',
|
2019-09-11 00:20:40 +08:00
|
|
|
},
|
2021-01-12 23:24:01 +08:00
|
|
|
retryOtherEnvError: {
|
|
|
|
id: 'app.screenshare.screenshareRetryOtherEnvError',
|
|
|
|
description: 'Screen sharing failures where a retry in another environment is recommended',
|
2019-09-11 00:20:40 +08:00
|
|
|
},
|
2021-01-12 23:24:01 +08:00
|
|
|
unsupportedEnvError: {
|
|
|
|
id: 'app.screenshare.screenshareUnsupportedEnv',
|
|
|
|
description: 'Screen sharing is not supported, changing browser or device is recommended',
|
2019-09-11 00:20:40 +08:00
|
|
|
},
|
2021-01-12 23:24:01 +08:00
|
|
|
permissionError: {
|
|
|
|
id: 'app.screenshare.screensharePermissionError',
|
|
|
|
description: 'Screen sharing failure due to lack of permission',
|
2019-09-11 00:20:40 +08:00
|
|
|
},
|
2018-07-10 03:04:24 +08:00
|
|
|
});
|
|
|
|
|
2021-01-12 23:24:01 +08:00
|
|
|
const getErrorLocale = (errorCode) => {
|
|
|
|
switch (errorCode) {
|
|
|
|
// Denied getDisplayMedia permission error
|
|
|
|
case SCREENSHARING_ERRORS.NotAllowedError.errorCode:
|
|
|
|
return intlMessages.permissionError;
|
|
|
|
// Browser is supposed to be supported, but a browser-related error happening.
|
|
|
|
// Suggest retrying in another device/browser/env
|
|
|
|
case SCREENSHARING_ERRORS.AbortError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.InvalidStateError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.OverconstrainedError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.TypeError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.NotFoundError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.NotReadableError.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.PEER_NEGOTIATION_FAILED.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.SCREENSHARE_PLAY_FAILED.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.MEDIA_NO_AVAILABLE_CODEC.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.MEDIA_INVALID_SDP.errorCode:
|
|
|
|
return intlMessages.retryOtherEnvError;
|
|
|
|
// Fatal errors where a retry isn't warranted. This probably means the server
|
|
|
|
// is misconfigured somehow or the provider is utterly botched, so nothing
|
|
|
|
// the end user can do besides requesting support
|
|
|
|
case SCREENSHARING_ERRORS.SIGNALLING_TRANSPORT_CONNECTION_FAILED.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.MEDIA_SERVER_CONNECTION_ERROR.errorCode:
|
|
|
|
case SCREENSHARING_ERRORS.SFU_INVALID_REQUEST.errorCode:
|
|
|
|
return intlMessages.finalError;
|
|
|
|
// Unsupported errors
|
|
|
|
case SCREENSHARING_ERRORS.NotSupportedError.errorCode:
|
|
|
|
return intlMessages.unsupportedEnvError;
|
2022-05-08 00:25:31 +08:00
|
|
|
// Errors that should be silent/ignored. They WILL NOT be LOGGED nor NOTIFIED via toasts.
|
|
|
|
case SCREENSHARING_ERRORS.ENDED_WHILE_STARTING.errorCode:
|
|
|
|
return null;
|
2021-01-12 23:24:01 +08:00
|
|
|
// Fall through: everything else is an error which might be solved with a retry
|
|
|
|
default:
|
|
|
|
return intlMessages.retryError;
|
|
|
|
}
|
2021-08-09 22:24:02 +08:00
|
|
|
};
|
2020-12-10 06:00:54 +08:00
|
|
|
|
|
|
|
const ScreenshareButton = ({
|
2018-07-10 03:04:24 +08:00
|
|
|
intl,
|
2020-12-10 06:00:54 +08:00
|
|
|
enabled,
|
2023-03-28 05:40:08 +08:00
|
|
|
isScreenBroadcasting,
|
2024-06-11 21:05:08 +08:00
|
|
|
amIPresenter = false,
|
2019-06-27 00:29:34 +08:00
|
|
|
isMeteorConnected,
|
2018-08-23 02:10:08 +08:00
|
|
|
}) => {
|
2024-01-20 02:40:27 +08:00
|
|
|
const [stopExternalVideoShare] = useMutation(EXTERNAL_VIDEO_STOP);
|
|
|
|
|
2019-09-11 00:20:40 +08:00
|
|
|
// This is the failure callback that will be passed to the /api/screenshare/kurento.js
|
|
|
|
// script on the presenter's call
|
2021-01-12 23:24:01 +08:00
|
|
|
const handleFailure = (error) => {
|
|
|
|
const {
|
|
|
|
errorCode = SCREENSHARING_ERRORS.UNKNOWN_ERROR.errorCode,
|
2023-02-16 22:37:00 +08:00
|
|
|
errorMessage = error.message,
|
2021-01-12 23:24:01 +08:00
|
|
|
} = error;
|
|
|
|
|
|
|
|
const localizedError = getErrorLocale(errorCode);
|
2022-05-08 00:25:31 +08:00
|
|
|
|
|
|
|
if (localizedError) {
|
|
|
|
notify(intl.formatMessage(localizedError, { 0: errorCode }), 'error', 'desktop');
|
|
|
|
logger.error({
|
|
|
|
logCode: 'screenshare_failed',
|
|
|
|
extraInfo: { errorCode, errorMessage },
|
|
|
|
}, `Screenshare failed: ${errorMessage} (code=${errorCode})`);
|
|
|
|
}
|
|
|
|
|
2020-12-16 01:45:57 +08:00
|
|
|
screenshareHasEnded();
|
2018-08-23 02:10:08 +08:00
|
|
|
};
|
2019-05-29 04:46:29 +08:00
|
|
|
|
2023-03-25 04:48:00 +08:00
|
|
|
const [isScreenshareUnavailableModalOpen, setScreenshareUnavailableModalIsOpen] = useState(false);
|
|
|
|
|
|
|
|
const RenderScreenshareUnavailableModal = (otherProps) =>
|
2021-10-26 03:49:51 +08:00
|
|
|
<Styled.ScreenShareModal
|
2021-08-09 22:24:02 +08:00
|
|
|
hideBorder
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.screenShareUnavailable)}
|
2023-03-25 04:48:00 +08:00
|
|
|
{...otherProps}
|
2021-08-09 22:24:02 +08:00
|
|
|
>
|
2021-10-26 03:49:51 +08:00
|
|
|
<Styled.Title>
|
2021-08-09 22:24:02 +08:00
|
|
|
{intl.formatMessage(intlMessages.screenShareUnavailable)}
|
2021-10-26 03:49:51 +08:00
|
|
|
</Styled.Title>
|
2021-08-09 22:24:02 +08:00
|
|
|
<p>{intl.formatMessage(intlMessages.screenShareNotSupported)}</p>
|
2023-03-25 04:48:00 +08:00
|
|
|
</Styled.ScreenShareModal>;
|
2020-12-10 06:00:54 +08:00
|
|
|
|
2022-06-23 21:05:11 +08:00
|
|
|
const screenshareLabel = intlMessages.desktopShareLabel;
|
2019-05-29 04:46:29 +08:00
|
|
|
|
2023-03-28 05:40:08 +08:00
|
|
|
const vLabel = isScreenBroadcasting
|
2022-06-23 21:05:11 +08:00
|
|
|
? intlMessages.stopDesktopShareLabel : screenshareLabel;
|
2019-05-29 04:46:29 +08:00
|
|
|
|
2023-03-28 05:40:08 +08:00
|
|
|
const vDescr = isScreenBroadcasting
|
2019-05-29 04:46:29 +08:00
|
|
|
? intlMessages.stopDesktopShareDesc : intlMessages.desktopShareDesc;
|
2023-03-28 05:40:08 +08:00
|
|
|
const amIBroadcasting = isScreenBroadcasting && amIPresenter;
|
2019-05-29 04:46:29 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
const shouldAllowScreensharing = enabled
|
2022-11-09 09:50:16 +08:00
|
|
|
&& ( !isMobile || isTabletApp)
|
2020-04-13 23:31:16 +08:00
|
|
|
&& amIPresenter;
|
2019-10-05 01:10:30 +08:00
|
|
|
|
2023-03-28 05:40:08 +08:00
|
|
|
const dataTest = isScreenBroadcasting ? 'stopScreenShare' : 'startScreenShare';
|
2022-01-20 21:03:18 +08:00
|
|
|
|
2023-03-25 04:48:00 +08:00
|
|
|
return <>
|
|
|
|
{
|
|
|
|
shouldAllowScreensharing
|
|
|
|
? (
|
|
|
|
<Button
|
2023-03-28 05:40:08 +08:00
|
|
|
disabled={(!isMeteorConnected && !isScreenBroadcasting)}
|
|
|
|
icon={amIBroadcasting ? 'desktop' : 'desktop_off'}
|
2023-03-25 04:48:00 +08:00
|
|
|
data-test={dataTest}
|
|
|
|
label={intl.formatMessage(vLabel)}
|
|
|
|
description={intl.formatMessage(vDescr)}
|
2023-03-28 05:40:08 +08:00
|
|
|
color={amIBroadcasting ? 'primary' : 'default'}
|
|
|
|
ghost={!amIBroadcasting}
|
2023-03-25 04:48:00 +08:00
|
|
|
hideLabel
|
|
|
|
circle
|
|
|
|
size="lg"
|
2023-03-28 05:40:08 +08:00
|
|
|
onClick={amIBroadcasting
|
2023-03-25 04:48:00 +08:00
|
|
|
? screenshareHasEnded
|
|
|
|
: () => {
|
|
|
|
if (isSafari && !ScreenshareBridgeService.HAS_DISPLAY_MEDIA) {
|
|
|
|
setScreenshareUnavailableModalIsOpen(true);
|
|
|
|
} else {
|
2024-01-20 02:40:27 +08:00
|
|
|
shareScreen(stopExternalVideoShare, amIPresenter, handleFailure);
|
2023-03-25 04:48:00 +08:00
|
|
|
}
|
|
|
|
}}
|
2023-03-28 05:40:08 +08:00
|
|
|
id={amIBroadcasting ? 'unshare-screen-button' : 'share-screen-button'}
|
2023-03-25 04:48:00 +08:00
|
|
|
/>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
{
|
|
|
|
isScreenshareUnavailableModalOpen ? <RenderScreenshareUnavailableModal
|
|
|
|
{...{
|
|
|
|
onRequestClose: () => setScreenshareUnavailableModalIsOpen(false),
|
|
|
|
priority: "low",
|
|
|
|
setIsOpen: setScreenshareUnavailableModalIsOpen,
|
|
|
|
isOpen: isScreenshareUnavailableModalOpen,
|
|
|
|
}}
|
|
|
|
/> : null
|
|
|
|
}
|
|
|
|
</>
|
2018-08-23 02:10:08 +08:00
|
|
|
};
|
2018-07-10 03:04:24 +08:00
|
|
|
|
2020-12-10 06:00:54 +08:00
|
|
|
ScreenshareButton.propTypes = propTypes;
|
2023-03-25 04:48:00 +08:00
|
|
|
export default injectIntl(memo(ScreenshareButton));
|