Skip to content

Commit

Permalink
Merge pull request #212 from mynaparrot/improvements
Browse files Browse the repository at this point in the history
fix: whiteboard wasn't refreshing
  • Loading branch information
jibon57 authored Oct 5, 2022
2 parents 03f7507 + 2235392 commit 8bbc5e8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
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

0 comments on commit 8bbc5e8

Please sign in to comment.