init
Some checks failed
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2025-09-02 14:49:16 +08:00
commit 38ba663466
2885 changed files with 391107 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/**
* The type of the action which signals document editing has stopped or started.
*
* {
* type: SET_DOCUMENT_EDITING_STATUS
* }
*/
export const SET_DOCUMENT_EDITING_STATUS = 'SET_DOCUMENT_EDITING_STATUS';
/**
* The type of the action which updates the shared document URL.
*
* {
* type: SET_DOCUMENT_URL
* }
*/
export const SET_DOCUMENT_URL = 'SET_DOCUMENT_URL';
/**
* The type of the action which signals to start or stop editing a shared
* document.
*
* {
* type: TOGGLE_DOCUMENT_EDITING
* }
*/
export const TOGGLE_DOCUMENT_EDITING = 'TOGGLE_DOCUMENT_EDITING';

View File

@@ -0,0 +1,51 @@
import {
SET_DOCUMENT_EDITING_STATUS,
SET_DOCUMENT_URL,
TOGGLE_DOCUMENT_EDITING
} from './actionTypes';
/**
* Dispatches an action to set whether document editing has started or stopped.
*
* @param {boolean} editing - Whether or not a document is currently being
* edited.
* @returns {{
* type: SET_DOCUMENT_EDITING_STATUS,
* editing: boolean
* }}
*/
export function setDocumentEditingState(editing: boolean) {
return {
type: SET_DOCUMENT_EDITING_STATUS,
editing
};
}
/**
* Dispatches an action to set the shared document URL.
*
* @param {string} documentUrl - The shared document URL.
* @returns {{
* type: SET_DOCUMENT_URL,
* documentUrl: string
* }}
*/
export function setDocumentUrl(documentUrl?: string) {
return {
type: SET_DOCUMENT_URL,
documentUrl
};
}
/**
* Dispatches an action to show or hide Etherpad.
*
* @returns {{
* type: TOGGLE_DOCUMENT_EDITING
* }}
*/
export function toggleDocument() {
return {
type: TOGGLE_DOCUMENT_EDITING
};
}

View File

@@ -0,0 +1,63 @@
import { connect } from 'react-redux';
import { createToolbarEvent } from '../../analytics/AnalyticsEvents';
import { sendAnalytics } from '../../analytics/functions';
import { IReduxState } from '../../app/types';
import { translate } from '../../base/i18n/functions';
import { IconShareDoc } from '../../base/icons/svg';
import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
import { navigate } from '../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
import { screen } from '../../mobile/navigation/routes';
/**
* Implements an {@link AbstractButton} to open the chat screen on mobile.
*/
class SharedDocumentButton extends AbstractButton<AbstractButtonProps> {
override accessibilityLabel = 'toolbar.accessibilityLabel.document';
override icon = IconShareDoc;
override label = 'toolbar.documentOpen';
override tooltip = 'toolbar.documentOpen';
/**
* Handles clicking / pressing the button, and opens / closes the appropriate dialog.
*
* @private
* @returns {void}
*/
override _handleClick() {
const { handleClick } = this.props;
if (handleClick) {
handleClick();
return;
}
sendAnalytics(createToolbarEvent(
'toggle.etherpad',
{
enable: true
}));
navigate(screen.conference.sharedDocument);
}
}
/**
* Maps part of the redux state to the component's props.
*
* @param {Object} state - The redux store/state.
* @param {Object} ownProps - The properties explicitly passed to the component
* instance.
* @returns {Object}
*/
function _mapStateToProps(state: IReduxState, ownProps: any) {
const { documentUrl } = state['features/etherpad'];
const { visible = Boolean(documentUrl) } = ownProps;
return {
visible
};
}
export default translate(connect(_mapStateToProps)(SharedDocumentButton));

View File

@@ -0,0 +1,81 @@
import { connect } from 'react-redux';
import { createToolbarEvent } from '../../analytics/AnalyticsEvents';
import { sendAnalytics } from '../../analytics/functions';
import { IReduxState } from '../../app/types';
import { translate } from '../../base/i18n/functions';
import { IconShareDoc } from '../../base/icons/svg';
import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
import { setOverflowMenuVisible } from '../../toolbox/actions.web';
import { toggleDocument } from '../actions';
interface IProps extends AbstractButtonProps {
/**
* Whether the shared document is being edited or not.
*/
_editing: boolean;
}
/**
* Implements an {@link AbstractButton} to open the chat screen on mobile.
*/
class SharedDocumentButton extends AbstractButton<IProps> {
override accessibilityLabel = 'toolbar.accessibilityLabel.documentOpen';
override toggledAccessibilityLabel = 'toolbar.accessibilityLabel.documentClose';
override icon = IconShareDoc;
override label = 'toolbar.documentOpen';
override toggledLabel = 'toolbar.documentClose';
override tooltip = 'toolbar.documentOpen';
override toggledTooltip = 'toolbar.documentClose';
/**
* Handles clicking / pressing the button, and opens / closes the appropriate dialog.
*
* @private
* @returns {void}
*/
override _handleClick() {
const { _editing, dispatch } = this.props;
sendAnalytics(createToolbarEvent(
'toggle.etherpad',
{
enable: !_editing
}));
dispatch(toggleDocument());
dispatch(setOverflowMenuVisible(false));
}
/**
* Indicates whether this button is in toggled state or not.
*
* @override
* @protected
* @returns {boolean}
*/
override _isToggled() {
return this.props._editing;
}
}
/**
* Maps part of the redux state to the component's props.
*
* @param {Object} state - The redux store/state.
* @param {Object} ownProps - The properties explicitly passed to the component
* instance.
* @returns {Object}
*/
function _mapStateToProps(state: IReduxState, ownProps: any) {
const { documentUrl, editing } = state['features/etherpad'];
const { visible = Boolean(documentUrl) } = ownProps;
return {
_editing: editing,
visible
};
}
export default translate(connect(_mapStateToProps)(SharedDocumentButton));

View File

@@ -0,0 +1,101 @@
import React, { PureComponent } from 'react';
import { WithTranslation } from 'react-i18next';
import { View, ViewStyle } from 'react-native';
import { WebView } from 'react-native-webview';
import { connect } from 'react-redux';
import { IReduxState } from '../../../app/types';
import { translate } from '../../../base/i18n/functions';
import JitsiScreen from '../../../base/modal/components/JitsiScreen';
import LoadingIndicator from '../../../base/react/components/native/LoadingIndicator';
import { getSharedDocumentUrl } from '../../functions';
import styles, { INDICATOR_COLOR } from './styles';
/**
* The type of the React {@code Component} props of {@code ShareDocument}.
*/
interface IProps extends WithTranslation {
/**
* URL for the shared document.
*/
_documentUrl?: string;
/**
* Default prop for navigation between screen components(React Navigation).
*/
navigation: Object;
}
/**
* Implements a React native component that renders the shared document window.
*/
class SharedDocument extends PureComponent<IProps> {
/**
* Instantiates a new instance.
*
* @inheritdoc
*/
constructor(props: IProps) {
super(props);
this._renderLoading = this._renderLoading.bind(this);
}
/**
* Implements React's {@link Component#render()}.
*
* @inheritdoc
*/
override render() {
const { _documentUrl } = this.props;
return (
<JitsiScreen
style = { styles.sharedDocContainer }>
<WebView
hideKeyboardAccessoryView = { true }
incognito = { true }
renderLoading = { this._renderLoading }
source = {{ uri: _documentUrl ?? '' }}
startInLoadingState = { true }
style = { styles.sharedDoc }
webviewDebuggingEnabled = { true } />
</JitsiScreen>
);
}
/**
* Renders the loading indicator.
*
* @returns {React$Component<any>}
*/
_renderLoading() {
return (
<View style = { styles.indicatorWrapper as ViewStyle }>
<LoadingIndicator
color = { INDICATOR_COLOR }
size = 'large' />
</View>
);
}
}
/**
* Maps (parts of) the redux state to {@link SharedDocument} React {@code Component} props.
*
* @param {Object} state - The redux store/state.
* @param {any} _ownProps - Component's props.
* @private
* @returns {Object}
*/
export function _mapStateToProps(state: IReduxState, _ownProps: any) {
const documentUrl = getSharedDocumentUrl(state);
return {
_documentUrl: documentUrl
};
}
export default translate(connect(_mapStateToProps)(SharedDocument));

View File

@@ -0,0 +1,26 @@
import BaseTheme from '../../../base/ui/components/BaseTheme.native';
export const INDICATOR_COLOR = BaseTheme.palette.ui07;
export default {
indicatorWrapper: {
alignItems: 'center',
backgroundColor: BaseTheme.palette.ui10,
height: '100%',
justifyContent: 'center'
},
sharedDocContainer: {
backgroundColor: BaseTheme.palette.ui10,
flex: 1,
paddingRight: BaseTheme.spacing[3]
},
sharedDoc: {
marginBottom: BaseTheme.spacing[3]
},
webView: {
backgroundColor: BaseTheme.palette.ui10
}
};

View File

@@ -0,0 +1,33 @@
import { IStateful } from '../base/app/types';
import { toState } from '../base/redux/functions';
const ETHERPAD_OPTIONS = {
showControls: 'true',
showChat: 'false',
showLineNumbers: 'true',
useMonospaceFont: 'false'
};
/**
* Retrieves the current sahred document URL.
*
* @param {Function|Object} stateful - The redux store or {@code getState} function.
* @returns {?string} - Current shared document URL or undefined.
*/
export function getSharedDocumentUrl(stateful: IStateful) {
const state = toState(stateful);
const { documentUrl } = state['features/etherpad'];
const { displayName } = state['features/base/settings'];
if (!documentUrl) {
return undefined;
}
const params = new URLSearchParams(ETHERPAD_OPTIONS);
if (displayName) {
params.append('userName', displayName);
}
return `${documentUrl}?${params.toString()}`;
}

View File

@@ -0,0 +1,24 @@
import { useSelector } from 'react-redux';
import { IReduxState } from '../app/types';
import SharedDocumentButtonWeb from './components/SharedDocumentButton';
const etherpad = {
key: 'etherpad',
Content: SharedDocumentButtonWeb,
group: 3
};
/**
* A hook that returns the etherpad button if it is enabled and undefined otherwise.
*
* @returns {Object | undefined}
*/
export function useEtherpadButton() {
const visible = useSelector((state: IReduxState) => Boolean(state['features/etherpad'].documentUrl));
if (visible) {
return etherpad;
}
}

View File

@@ -0,0 +1,73 @@
import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
import { getCurrentConference } from '../base/conference/functions';
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
import { sanitizeUrl } from '../base/util/uri';
import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
import { setDocumentUrl } from './actions';
const ETHERPAD_COMMAND = 'etherpad';
/**
* Middleware that captures actions related to collaborative document editing
* and notifies components not hooked into redux.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
// eslint-disable-next-line no-unused-vars
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
switch (action.type) {
case CONFERENCE_JOIN_IN_PROGRESS: {
const { conference } = action;
conference.addCommandListener(ETHERPAD_COMMAND,
({ value }: { value: string; }) => {
let url;
const { etherpad_base: etherpadBase } = getState()['features/base/config'];
const etherpadBaseUrl = sanitizeUrl(etherpadBase);
if (etherpadBaseUrl) {
const urlObj = new URL(value, etherpadBaseUrl.toString());
// Merge query string parameters on top of internal ones
if (etherpadBaseUrl.search) {
const searchParams = new URLSearchParams(urlObj.search);
for (const [ key, val ] of new URLSearchParams(etherpadBaseUrl.search)) {
searchParams.set(key, val);
}
urlObj.search = searchParams.toString();
}
url = urlObj.toString();
}
dispatch(setDocumentUrl(url));
}
);
break;
}
case TOGGLE_DOCUMENT_EDITING: {
if (typeof APP !== 'undefined') {
APP.UI.onEtherpadClicked();
}
break;
}
}
return next(action);
});
/**
* Set up state change listener to perform maintenance tasks when the conference
* is left or failed, e.g. Clear messages or close the chat modal if it's left
* open.
*/
StateListenerRegistry.register(
state => getCurrentConference(state),
(conference, { dispatch }, previousConference) => {
if (previousConference) {
dispatch(setDocumentUrl(undefined));
}
});

View File

@@ -0,0 +1,48 @@
import ReducerRegistry from '../base/redux/ReducerRegistry';
import { SET_DOCUMENT_EDITING_STATUS, SET_DOCUMENT_URL } from './actionTypes';
const DEFAULT_STATE = {
/**
* URL for the shared document.
*/
documentUrl: undefined,
/**
* Whether or not Etherpad is currently open.
*
* @public
* @type {boolean}
*/
editing: false
};
export interface IEtherpadState {
documentUrl?: string;
editing: boolean;
}
/**
* Reduces the Redux actions of the feature features/etherpad.
*/
ReducerRegistry.register<IEtherpadState>(
'features/etherpad',
(state = DEFAULT_STATE, action): IEtherpadState => {
switch (action.type) {
case SET_DOCUMENT_EDITING_STATUS:
return {
...state,
editing: action.editing
};
case SET_DOCUMENT_URL:
return {
...state,
documentUrl: action.documentUrl
};
default:
return state;
}
});