2020-09-04 07:35:57 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import Draggable from 'react-draggable';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2021-10-26 22:17:02 +08:00
|
|
|
import Styled from './styles';
|
2021-01-20 01:06:32 +08:00
|
|
|
import ChatLogger from '/imports/ui/components/chat/chat-logger/ChatLogger';
|
2020-09-04 07:35:57 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
modalClose: {
|
|
|
|
id: 'app.modal.close',
|
|
|
|
description: 'Close',
|
|
|
|
},
|
|
|
|
modalCloseDescription: {
|
|
|
|
id: 'app.modal.close.description',
|
|
|
|
description: 'Disregards changes and closes the modal',
|
|
|
|
},
|
|
|
|
debugWindowTitle: {
|
|
|
|
id: 'app.debugWindow.windowTitle',
|
|
|
|
description: 'Debug window title',
|
|
|
|
},
|
|
|
|
userAgentLabel: {
|
|
|
|
id: 'app.debugWindow.form.userAgentLabel',
|
|
|
|
description: 'User agent form label',
|
|
|
|
},
|
|
|
|
copyButtonLabel: {
|
|
|
|
id: 'app.debugWindow.form.button.copy',
|
|
|
|
description: 'User agent form copy button',
|
|
|
|
},
|
2021-06-15 05:08:39 +08:00
|
|
|
chatLoggerLabel: {
|
|
|
|
id: 'app.debugWindow.form.chatLoggerLabel',
|
|
|
|
description: 'Chat logger level form label',
|
|
|
|
},
|
|
|
|
applyButtonLabel: {
|
|
|
|
id: 'app.debugWindow.form.button.apply',
|
|
|
|
description: 'Chat logger level form apply button',
|
|
|
|
},
|
2021-05-11 04:41:52 +08:00
|
|
|
on: {
|
|
|
|
id: 'app.switch.onLabel',
|
|
|
|
description: 'label for toggle switch on state',
|
|
|
|
},
|
|
|
|
off: {
|
|
|
|
id: 'app.switch.offLabel',
|
|
|
|
description: 'label for toggle switch off state',
|
|
|
|
},
|
2020-09-04 07:35:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
class DebugWindow extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
showDebugWindow: false,
|
2021-01-20 01:06:32 +08:00
|
|
|
logLevel: ChatLogger.getLogLevel(),
|
2020-09-04 07:35:57 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const DEBUG_WINDOW_ENABLED = window.meetingClientSettings.public.app.enableDebugWindow;
|
|
|
|
const SHOW_DEBUG_WINDOW_ACCESSKEY = window.meetingClientSettings.public.app.shortcuts.openDebugWindow.accesskey;
|
|
|
|
|
2020-09-04 07:35:57 +08:00
|
|
|
document.addEventListener('keyup', (event) => {
|
2021-04-28 04:28:59 +08:00
|
|
|
const { key, code } = event;
|
2021-11-22 08:55:51 +08:00
|
|
|
const eventKey = key?.toUpperCase();
|
2021-04-28 04:28:59 +08:00
|
|
|
const eventCode = code;
|
2021-11-22 08:55:51 +08:00
|
|
|
if (DEBUG_WINDOW_ENABLED && event?.altKey && (eventKey === SHOW_DEBUG_WINDOW_ACCESSKEY || eventCode === `Key${SHOW_DEBUG_WINDOW_ACCESSKEY}`)) {
|
2020-09-04 07:35:57 +08:00
|
|
|
this.debugWindowToggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setShowDebugWindow(showDebugWindow) {
|
|
|
|
this.setState({ showDebugWindow });
|
|
|
|
}
|
|
|
|
|
|
|
|
debugWindowToggle() {
|
|
|
|
const { showDebugWindow } = this.state;
|
|
|
|
if (showDebugWindow) {
|
|
|
|
this.setShowDebugWindow(false);
|
|
|
|
} else {
|
|
|
|
this.setShowDebugWindow(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-11 04:41:52 +08:00
|
|
|
displaySettingsStatus(status) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
2021-10-26 22:17:02 +08:00
|
|
|
<Styled.ToggleLabel>
|
2021-05-11 04:41:52 +08:00
|
|
|
{status ? intl.formatMessage(intlMessages.on)
|
|
|
|
: intl.formatMessage(intlMessages.off)}
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.ToggleLabel>
|
2021-05-11 04:41:52 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-04 07:35:57 +08:00
|
|
|
render() {
|
2021-01-20 01:06:32 +08:00
|
|
|
const { showDebugWindow, logLevel } = this.state;
|
|
|
|
const chatLoggerLevelsNames = Object.keys(ChatLogger.levels);
|
2020-09-04 07:35:57 +08:00
|
|
|
|
2024-05-29 21:26:11 +08:00
|
|
|
const DEBUG_WINDOW_ENABLED = window.meetingClientSettings.public.app.enableDebugWindow;
|
|
|
|
|
2020-09-04 07:35:57 +08:00
|
|
|
if (!DEBUG_WINDOW_ENABLED || !showDebugWindow) return false;
|
|
|
|
|
2021-06-22 02:49:25 +08:00
|
|
|
const { intl } = this.props;
|
2021-05-11 04:41:52 +08:00
|
|
|
|
2020-09-04 07:35:57 +08:00
|
|
|
return (
|
|
|
|
<Draggable
|
|
|
|
handle="#debugWindowHeader"
|
|
|
|
bounds="body"
|
|
|
|
enableUserSelectHack={false}
|
|
|
|
>
|
2021-10-26 22:17:02 +08:00
|
|
|
<Styled.DebugWindowWrapper
|
2020-09-04 07:35:57 +08:00
|
|
|
minWidth={window.innerWidth * 0.2}
|
|
|
|
minHeight={window.innerHeight * 0.2}
|
|
|
|
enable={{
|
|
|
|
top: false,
|
|
|
|
bottom: false,
|
|
|
|
left: false,
|
|
|
|
right: false,
|
|
|
|
topLeft: false,
|
|
|
|
topRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
bottomRight: true,
|
|
|
|
}}
|
|
|
|
>
|
2021-10-26 22:17:02 +08:00
|
|
|
<Styled.DebugWindow>
|
|
|
|
<Styled.Header id="debugWindowHeader">
|
|
|
|
<Styled.MoveIcon iconName="fit_to_screen" />
|
|
|
|
<Styled.Title>
|
2020-09-04 07:35:57 +08:00
|
|
|
{intl.formatMessage(intlMessages.debugWindowTitle)}
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.Title>
|
|
|
|
<Styled.CloseButton
|
2020-09-04 07:35:57 +08:00
|
|
|
label={intl.formatMessage(intlMessages.modalClose)}
|
|
|
|
aria-label={`${intl.formatMessage(intlMessages.modalClose)} ${intl.formatMessage(intlMessages.debugWindowTitle)}`}
|
|
|
|
icon="close"
|
|
|
|
circle
|
|
|
|
hideLabel
|
|
|
|
onClick={() => this.setShowDebugWindow(false)}
|
|
|
|
/>
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.Header>
|
|
|
|
<Styled.DebugWindowContent>
|
|
|
|
<Styled.Table>
|
|
|
|
<Styled.TableRow>
|
|
|
|
<Styled.TableCell>
|
2020-09-04 07:35:57 +08:00
|
|
|
{`${intl.formatMessage(intlMessages.userAgentLabel)}:`}
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.TableCell>
|
|
|
|
<Styled.TableCell>
|
|
|
|
<Styled.UserAgentInput
|
2020-09-04 07:35:57 +08:00
|
|
|
id="debugModalUserAgent"
|
|
|
|
type="text"
|
|
|
|
value={window.navigator.userAgent}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
onClick={() => navigator.clipboard.writeText(window.navigator.userAgent)}
|
|
|
|
>
|
|
|
|
{`${intl.formatMessage(intlMessages.copyButtonLabel)}`}
|
|
|
|
</button>
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.TableCell>
|
|
|
|
</Styled.TableRow>
|
|
|
|
<Styled.TableRow>
|
|
|
|
<Styled.TableCell>
|
2021-06-15 05:08:39 +08:00
|
|
|
{`${intl.formatMessage(intlMessages.chatLoggerLabel)}:`}
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.TableCell>
|
|
|
|
<Styled.TableCell>
|
|
|
|
<Styled.CellContent>
|
2021-01-20 01:06:32 +08:00
|
|
|
<select
|
|
|
|
style={{ marginRight: '1rem' }}
|
|
|
|
onChange={(ev) => {
|
|
|
|
this.setState({
|
|
|
|
logLevel: ev.target.value,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
chatLoggerLevelsNames.map((i, index) => {
|
2021-08-09 22:24:02 +08:00
|
|
|
const idx = index;
|
|
|
|
return (<option key={`${i}-${idx}`}>{i}</option>);
|
2021-01-20 01:06:32 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
</select>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
disabled={logLevel === ChatLogger.getLogLevel()}
|
|
|
|
onClick={() => {
|
|
|
|
ChatLogger.setLogLevel(logLevel);
|
|
|
|
this.setState({
|
|
|
|
logLevel: ChatLogger.getLogLevel(),
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2021-06-15 05:08:39 +08:00
|
|
|
{`${intl.formatMessage(intlMessages.applyButtonLabel)}`}
|
2021-01-20 01:06:32 +08:00
|
|
|
</button>
|
2021-10-26 22:17:02 +08:00
|
|
|
</Styled.CellContent>
|
|
|
|
</Styled.TableCell>
|
|
|
|
</Styled.TableRow>
|
|
|
|
</Styled.Table>
|
|
|
|
</Styled.DebugWindowContent>
|
|
|
|
</Styled.DebugWindow>
|
|
|
|
</Styled.DebugWindowWrapper>
|
2020-09-04 07:35:57 +08:00
|
|
|
</Draggable>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-05 15:26:03 +08:00
|
|
|
export default injectIntl(DebugWindow);
|