Browse Source

Fix electron sockets problem

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 11 months ago
parent
commit
b6257e33bd
2 changed files with 9 additions and 3 deletions
  1. 8 2
      client/src/context/Data.tsx
  2. 1 1
      client/src/http/Axios.ts

+ 8 - 2
client/src/context/Data.tsx

@@ -8,7 +8,13 @@ import {
 } from 'react';
 } from 'react';
 import { io, Socket } from 'socket.io-client';
 import { io, Socket } from 'socket.io-client';
 import { authContext } from '@/context';
 import { authContext } from '@/context';
-import { CollectionService, MilvusService, DatabaseService } from '@/http';
+import {
+  CollectionService,
+  MilvusService,
+  DatabaseService,
+  isElectron,
+  url,
+} from '@/http';
 import {
 import {
   IndexCreateParam,
   IndexCreateParam,
   IndexManageParam,
   IndexManageParam,
@@ -396,7 +402,7 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
       setDatabase(authReq.database);
       setDatabase(authReq.database);
 
 
       // create socket
       // create socket
-      socket.current = io();
+      socket.current = isElectron ? io(url as string) : io();
       // register client
       // register client
       socket.current.emit(WS_EVENTS.REGISTER, clientId);
       socket.current.emit(WS_EVENTS.REGISTER, clientId);
 
 

+ 1 - 1
client/src/http/Axios.ts

@@ -8,7 +8,7 @@ const hostUrl: { [key: string]: string | undefined } = {
   electron: `http://127.0.0.1:3000`,
   electron: `http://127.0.0.1:3000`,
 };
 };
 
 
-const isElectron =
+export const isElectron =
   (window as any)._env_ && (window as any)._env_.IS_ELECTRON === 'yes';
   (window as any)._env_ && (window as any)._env_.IS_ELECTRON === 'yes';
 
 
 export const url = hostUrl[isElectron ? 'electron' : import.meta.env.MODE];
 export const url = hostUrl[isElectron ? 'electron' : import.meta.env.MODE];