Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: whiteboard wasn't refreshing #212

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions src/components/main-area/mainComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import React, {
useCallback,
useEffect,
useMemo,
useState,
useRef,
} from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { createSelector } from '@reduxjs/toolkit';
import { throttle } from 'lodash';

import { RootState, useAppDispatch, useAppSelector } from '../../store';
import ScreenShareElements from '../media-elements/screenshare';
Expand Down Expand Up @@ -60,15 +53,16 @@ const activateWebcamsViewSelector = createSelector(

const MainComponents = ({ currentConnection }: IMainComponentsProps) => {
const dispatch = useAppDispatch();
const refreshWhiteboard = useRef(
throttle(
() => {
dispatch(doRefreshWhiteboard(Date.now()));
},
2000,
{ leading: false, trailing: false },
),
);
// const refreshWhiteboard = useRef(
// throttle(
// () => {
// console.log("im here")
// dispatch(doRefreshWhiteboard(Date.now()));
// },
// 2000,
// { leading: false, trailing: false },
// ),
// );

const isActiveScreenSharing = useAppSelector(isActiveScreenSharingSelector);
const activeScreenSharingView = useAppSelector(
Expand All @@ -87,6 +81,7 @@ const MainComponents = ({ currentConnection }: IMainComponentsProps) => {
const [showVerticalVideoView, setShowVerticalVideoView] =
useState<boolean>(false);
const [hasVideoElms, setHasVideoElms] = useState<boolean>(false);
const [showVideoElms, setShowVideoElms] = useState<boolean>(false);

useEffect(() => {
if (
Expand Down Expand Up @@ -120,17 +115,27 @@ const MainComponents = ({ currentConnection }: IMainComponentsProps) => {
};
}, [currentConnection]);

const shouldShowVideoElms = useCallback(() => {
//without refreshing whiteboard in larger display it will be out of sync.
refreshWhiteboard.current();

useEffect(() => {
if (!activateWebcamsView) {
return false;
setShowVideoElms(false);
return;
}
return hasVideoElms;
//eslint-disable-next-line
setShowVideoElms(hasVideoElms);
}, [activateWebcamsView, hasVideoElms]);

useEffect(() => {
const timeout = setTimeout(() => {
if (isActiveWhiteboard) {
dispatch(doRefreshWhiteboard(Date.now()));
} else {
dispatch(doRefreshWhiteboard(0));
}
}, 1000);
return () => {
clearTimeout(timeout);
};
}, [showVideoElms, isActiveWhiteboard, dispatch]);

const shouldShowScreenSharing = useCallback(() => {
if (!activeScreenSharingView) {
return false;
Expand Down Expand Up @@ -188,7 +193,7 @@ const MainComponents = ({ currentConnection }: IMainComponentsProps) => {
) : (
<div
className={`middle-fullscreen-wrapper h-full flex ${
shouldShowVideoElms() ? 'verticalsWebcamsActivated' : ''
showVideoElms ? 'verticalsWebcamsActivated' : ''
}`}
>
{videoElms}
Expand Down
27 changes: 18 additions & 9 deletions src/components/whiteboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ const Whiteboard = () => {
}
}, [preScreenWidth, screenWidth, excalidrawAPI]);

// for refreshing in various reason
useEffect(() => {
const doRefresh = throttle(
() => {
excalidrawAPI?.refresh();
},
500,
{ trailing: false },
);

if (refreshWhiteboard > 0) {
if (excalidrawAPI) {
doRefresh();
}
}
//eslint-disable-next-line
}, [refreshWhiteboard]);

const handleExcalidrawAddFiles = useCallback(
async (files: Array<IWhiteboardFile>) => {
if (!excalidrawAPI) {
Expand Down Expand Up @@ -409,15 +427,6 @@ const Whiteboard = () => {
},
[excalidrawAPI, lastBroadcastOrReceivedSceneVersion],
);
// for refreshing in various reason
useEffect(() => {
if (refreshWhiteboard > 0) {
if (excalidrawAPI) {
excalidrawAPI.refresh();
}
}
//eslint-disable-next-line
}, [refreshWhiteboard]);

const handleRemoteSceneUpdate = (
elements: ReconciledElements,
Expand Down