Kaynağa Gözat

Add safe check so collab stats dont show up for host apps

Aakansha Doshi 4 yıl önce
ebeveyn
işleme
98c16659c9
2 değiştirilmiş dosya ile 9 ekleme ve 3 silme
  1. 7 2
      src/components/App.tsx
  2. 2 1
      src/components/Stats.tsx

+ 7 - 2
src/components/App.tsx

@@ -207,6 +207,9 @@ const gesture: Gesture = {
   initialScale: null,
 };
 
+const shouldEnableNetworkStats = !!(
+  typeof process !== "undefined" && process.env?.REACT_APP_SOCKET_SERVER_URL
+);
 export type PointerDownState = Readonly<{
   // The first position at which pointerDown happened
   origin: Readonly<{ x: number; y: number }>;
@@ -474,6 +477,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
             elements={this.scene.getElements()}
             onClose={this.toggleStats}
             isCollaborating={this.props.isCollaborating}
+            shouldEnableNetworkStats={shouldEnableNetworkStats}
           />
         )}
         {this.state.toastMessage !== null && (
@@ -881,8 +885,9 @@ class App extends React.Component<ExcalidrawProps, AppState> {
       });
     }
     if (
-      prevState.showStats !== this.state.showStats ||
-      prevProps.isCollaborating !== this.props.isCollaborating
+      shouldEnableNetworkStats &&
+      (prevState.showStats !== this.state.showStats ||
+        prevProps.isCollaborating !== this.props.isCollaborating)
     ) {
       const navigator: Navigator & {
         connection?: {

+ 2 - 1
src/components/Stats.tsx

@@ -37,6 +37,7 @@ export const Stats = (props: {
   elements: readonly NonDeletedExcalidrawElement[];
   onClose: () => void;
   isCollaborating?: boolean;
+  shouldEnableNetworkStats: boolean;
 }) => {
   const isMobile = useIsMobile();
   const [storageSizes, setStorageSizes] = useState<StorageSizes>({
@@ -177,7 +178,7 @@ export const Stats = (props: {
                 </td>
               </tr>
             )}
-            {props.isCollaborating ? (
+            {props.shouldEnableNetworkStats && props.isCollaborating ? (
               <>
                 <tr>
                   <th colSpan={2}>{t("stats.collaboration")}</th>