Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(whiteboard) compute serverUrl once to limit rerenders (#14600)

Mihaela Dumitru37024b4f1f33
diff --git a/react/features/whiteboard/actions.any.ts b/react/features/whiteboard/actions.any.ts
index 0aa86f30c0..2e13fa6a70 100644
--- a/react/features/whiteboard/actions.any.ts
+++ b/react/features/whiteboard/actions.any.ts
@@ -15,15 +15,18 @@ import { IWhiteboardAction } from './reducer';
* @param {Object} payload - The whiteboard settings.
* @returns {{
* type: SETUP_WHITEBOARD,
- * collabDetails: { roomId: string, roomKey: string }
+ * collabDetails: { roomId: string, roomKey: string },
+ * collabServerUrl: string
* }}
*/
-export const setupWhiteboard = ({ collabDetails }: {
+export const setupWhiteboard = ({ collabDetails, collabServerUrl }: {
collabDetails: { roomId: string; roomKey: string; };
+ collabServerUrl?: string;
}): IWhiteboardAction => {
return {
type: SETUP_WHITEBOARD,
- collabDetails
+ collabDetails,
+ collabServerUrl
};
};
diff --git a/react/features/whiteboard/components/native/Whiteboard.tsx b/react/features/whiteboard/components/native/Whiteboard.tsx
index 0c3206dc5d..8f06bf84e0 100644
--- a/react/features/whiteboard/components/native/Whiteboard.tsx
+++ b/react/features/whiteboard/components/native/Whiteboard.tsx
@@ -21,19 +21,14 @@ import {
} from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
import { setupWhiteboard } from '../../actions.native';
import { WHITEBOARD_ID } from '../../constants';
-import { getCollabServerUrl, getWhiteboardInfoForURIString } from '../../functions';
+import { getWhiteboardInfoForURIString } from '../../functions';
+import logger from '../../logger';
import WhiteboardErrorDialog from './WhiteboardErrorDialog';
import styles, { INDICATOR_COLOR } from './styles';
-
interface IProps extends WithTranslation {
- /**
- * The whiteboard collab server url.
- */
- collabServerUrl?: string;
-
/**
* The current Jitsi conference.
*/
@@ -188,11 +183,22 @@ class Whiteboard extends PureComponent<IProps> {
* @returns {void}
*/
_onMessage(event: any) {
- const { collabServerUrl, conference } = this.props;
- const collabDetails = JSON.parse(event.nativeEvent.data);
+ const { conference, dispatch } = this.props;
+ const collabData = JSON.parse(event.nativeEvent.data);
+
+ if (!collabData) {
+ logger.error('Message payload is missing whiteboard collaboration data');
+
+ return;
+ }
+
+ const { collabDetails, collabServerUrl } = collabData;
- if (collabDetails?.roomId && collabDetails?.roomKey) {
- this.props.dispatch(setupWhiteboard({ collabDetails }));
+ if (collabDetails?.roomId && collabDetails?.roomKey && collabServerUrl) {
+ dispatch(setupWhiteboard({
+ collabDetails,
+ collabServerUrl
+ }));
// Broadcast the collab details.
conference?.getMetadataHandler().setMetadata(WHITEBOARD_ID, {
@@ -232,7 +238,6 @@ function mapStateToProps(state: IReduxState) {
return {
conference: getCurrentConference(state),
- collabServerUrl: getCollabServerUrl(state),
locationHref: href
};
}
diff --git a/react/features/whiteboard/components/web/WhiteboardApp.tsx b/react/features/whiteboard/components/web/WhiteboardApp.tsx
index c9bc7daa89..6ddb0efa26 100644
--- a/react/features/whiteboard/components/web/WhiteboardApp.tsx
+++ b/react/features/whiteboard/components/web/WhiteboardApp.tsx
@@ -40,7 +40,10 @@ export default class WhiteboardApp extends BaseApp<any> {
if (window.ReactNativeWebView) {
setTimeout(() => {
- window.ReactNativeWebView.postMessage(JSON.stringify(collabDetails));
+ window.ReactNativeWebView.postMessage(JSON.stringify({
+ collabDetails,
+ collabServerUrl
+ }));
}, 0);
}
} catch (e: any) {
diff --git a/react/features/whiteboard/functions.ts b/react/features/whiteboard/functions.ts
index bef5ff6fee..5b7e9ba18b 100644
--- a/react/features/whiteboard/functions.ts
+++ b/react/features/whiteboard/functions.ts
@@ -83,12 +83,12 @@ export const isWhiteboardButtonVisible = (state: IReduxState): boolean =>
export const isWhiteboardPresent = (state: IReduxState): boolean => getRemoteParticipants(state).has(WHITEBOARD_ID);
/**
- * Returns the whiteboard collaboration server url.
+ * Builds the whiteboard collaboration server url.
*
* @param {IReduxState} state - The state from the Redux store.
* @returns {string}
*/
-export const getCollabServerUrl = (state: IReduxState): string | undefined => {
+export const generateCollabServerUrl = (state: IReduxState): string | undefined => {
const collabServerBaseUrl = getWhiteboardConfig(state).collabServerBaseUrl;
if (!collabServerBaseUrl) {
@@ -105,6 +105,15 @@ export const getCollabServerUrl = (state: IReduxState): string | undefined => {
return appendURLParam(collabServerBaseUrl, 'room', room);
};
+/**
+ * Returns the whiteboard collaboration server url.
+ *
+ * @param {IReduxState} state - The state from the Redux store.
+ * @returns {string}
+ */
+export const getCollabServerUrl = (state: IReduxState): string | undefined =>
+ getWhiteboardState(state).collabServerUrl;
+
/**
* Whether the whiteboard is visible on stage.
*
diff --git a/react/features/whiteboard/middleware.any.ts b/react/features/whiteboard/middleware.any.ts
index abd911c964..4250025c1a 100644
--- a/react/features/whiteboard/middleware.any.ts
+++ b/react/features/whiteboard/middleware.any.ts
@@ -16,6 +16,7 @@ import {
} from './actions';
import { WHITEBOARD_ID } from './constants';
import {
+ generateCollabServerUrl,
isWhiteboardOpen,
shouldEnforceUserLimit,
shouldNotifyUserLimit
@@ -43,7 +44,8 @@ MiddlewareRegistry.register((store: IStore) => next => action => {
if (metadata?.[WHITEBOARD_ID]) {
store.dispatch(setupWhiteboard({
- collabDetails: metadata[WHITEBOARD_ID].collabDetails
+ collabDetails: metadata[WHITEBOARD_ID].collabDetails,
+ collabServerUrl: generateCollabServerUrl(store.getState())
}));
store.dispatch(setWhiteboardOpen(true));
}
diff --git a/react/features/whiteboard/middleware.native.ts b/react/features/whiteboard/middleware.native.ts
index b04b7c8ebf..ec5a743cd8 100644
--- a/react/features/whiteboard/middleware.native.ts
+++ b/react/features/whiteboard/middleware.native.ts
@@ -17,14 +17,13 @@ import {
} from './actions';
import WhiteboardLimitDialog from './components/native/WhiteboardLimitDialog';
import {
+ generateCollabServerUrl,
getCollabDetails,
- getCollabServerUrl,
shouldEnforceUserLimit,
shouldNotifyUserLimit
} from './functions';
import './middleware.any';
-
/**
* Middleware which intercepts whiteboard actions to handle changes to the related state.
*
@@ -65,7 +64,7 @@ MiddlewareRegistry.register((store: IStore) => (next: Function) => async (action
}
const collabDetails = getCollabDetails(state);
- const collabServerUrl = getCollabServerUrl(state);
+ const collabServerUrl = generateCollabServerUrl(state);
const localParticipantName = getLocalParticipant(state)?.name;
navigate(screen.conference.whiteboard, {
diff --git a/react/features/whiteboard/middleware.web.ts b/react/features/whiteboard/middleware.web.ts
index 181d627292..ba5e85c89a 100644
--- a/react/features/whiteboard/middleware.web.ts
+++ b/react/features/whiteboard/middleware.web.ts
@@ -21,8 +21,8 @@ import {
import WhiteboardLimitDialog from './components/web/WhiteboardLimitDialog';
import { WHITEBOARD_ID, WHITEBOARD_PARTICIPANT_NAME } from './constants';
import {
+ generateCollabServerUrl,
getCollabDetails,
- getCollabServerUrl,
isWhiteboardPresent,
shouldEnforceUserLimit,
shouldNotifyUserLimit
@@ -79,19 +79,19 @@ MiddlewareRegistry.register((store: IStore) => (next: Function) => async (action
if (!existingCollabDetails) {
const collabLinkData = await generateCollaborationLinkData();
- const collabServerUrl = getCollabServerUrl(state);
+ const collabServerUrl = generateCollabServerUrl(state);
const roomId = getCurrentRoomId(state);
- const collabDetails = {
- roomId,
- roomKey: collabLinkData.roomKey
+ const collabData = {
+ collabDetails: {
+ roomId,
+ roomKey: collabLinkData.roomKey
+ },
+ collabServerUrl
};
focusWhiteboard(store);
- dispatch(setupWhiteboard({ collabDetails }));
- conference?.getMetadataHandler().setMetadata(WHITEBOARD_ID, {
- collabServerUrl,
- collabDetails
- });
+ dispatch(setupWhiteboard(collabData));
+ conference?.getMetadataHandler().setMetadata(WHITEBOARD_ID, collabData);
raiseWhiteboardNotification(WhiteboardStatus.INSTANTIATED);
return next(action);
diff --git a/react/features/whiteboard/reducer.ts b/react/features/whiteboard/reducer.ts
index f53cf49e83..b63849b92d 100644
--- a/react/features/whiteboard/reducer.ts
+++ b/react/features/whiteboard/reducer.ts
@@ -9,6 +9,11 @@ export interface IWhiteboardState {
*/
collabDetails?: { roomId: string; roomKey: string; };
+ /**
+ * The whiteboard collaboration url.
+ */
+ collabServerUrl?: string;
+
/**
* The indicator which determines whether the whiteboard is open.
*
@@ -19,7 +24,8 @@ export interface IWhiteboardState {
const DEFAULT_STATE: IWhiteboardState = {
isOpen: false,
- collabDetails: undefined
+ collabDetails: undefined,
+ collabServerUrl: undefined
};
export interface IWhiteboardAction extends Partial<IWhiteboardState> {
@@ -29,6 +35,11 @@ export interface IWhiteboardAction extends Partial<IWhiteboardState> {
*/
collabDetails?: { roomId: string; roomKey: string; };
+ /**
+ * The whiteboard collaboration url.
+ */
+ collabServerUrl?: string;
+
/**
* The action type.
*/
@@ -43,7 +54,8 @@ ReducerRegistry.register(
return {
...state,
isOpen: true,
- collabDetails: action.collabDetails
+ collabDetails: action.collabDetails,
+ collabServerUrl: action.collabServerUrl
};
}
case RESET_WHITEBOARD: