diff --git a/src/App.tsx b/src/App.tsx index 212166d..3ce2ba4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,7 @@ import Meeting from '@/page/Meeting/index' import NotFound from '@/page/NotFound/index' import { storage } from '@/utils' import { message, Spin } from "antd"; -import { onInvitation, onReconnected, onStart, startSignalr } from "@/utils/package/signalr"; +import { onOtherSignalr, onReconnected, onStart, startSignalr } from "@/utils/package/signalr"; import JoinMeetingModal from "@/components/JoinMeetingModal"; import UpdateModal from "@/components/UpdateModal"; import * as CryptoJS from 'crypto-js'; @@ -32,19 +32,6 @@ const App: React.FC = () => { const [spinning, setSpinning] = useState(false); const [isState, setIsState] = useState(true); useEffect(() => { - function toLogin() { - try { - window.electron.setMainWindowSize({ - width: 752, - height: 520, - key: 'login' - }) - } catch { - } - storage.removeItem('user') - navigate('/login') - } - let userInfo = JSON.parse(storage.getItem('user') as string) let loginInfo = JSON.parse(storage.getItem('login') as string) if (userInfo) { @@ -54,16 +41,17 @@ const App: React.FC = () => { pwd: CryptoJS.MD5(loginInfo.password).toString(CryptoJS.enc.Hex) }).then(res => { if (res.code === 200) { + toSrc('/home') startSignalr() } else { - toLogin() + toSrc('/login') } }) } else { - toLogin() + toSrc('/login') } } else { - toLogin() + toSrc('/login') } if (import.meta.env.VITE_ENV !== 'development') { document.addEventListener('keydown', (event) => { @@ -118,17 +106,12 @@ const App: React.FC = () => { storage.setItem('setting', JSON.stringify(setting)) }) window.electron.quitAndInstall(async (_e: any) => { - if (location.hash.indexOf('/meeting') === 1) { - const data = JSON.parse(localStorage.stateInfo); - await GetLeave({ - roomNum: data.channelId, - }) - await agora.leaveChannel() - } + leaveChannel() }) }, []) + useEffect(() => { - onInvitation((item: any) => { + onOtherSignalr(async (item: any) => { switch (item.key) { case 'Invitation': window.electron.joinNotification({ @@ -137,9 +120,33 @@ const App: React.FC = () => { }) joinMeetingModalRef.current.changeModal(item) break; + case 'ForceLogout': + message.error(item.msg) + await leaveChannel() + toSrc('/login') + break; } }) - }, [navigate]) + }, []) + + useEffect(() => { + try { + if (location.hash.indexOf('/login') !== -1) { + window.electron.setMainWindowSize({ + width: 752, + height: 520, + key: 'login' + }) + } else { + window.electron.setMainWindowSize({ + width: 1200, + height: 800, + }) + } + } catch { + } + }, [location.hash]) + useEffect(() => { onReconnected(async () => { storage.setItem('reconnect', true) @@ -182,6 +189,7 @@ const App: React.FC = () => { } storage.setItem('stateInfo', JSON.stringify(state)) }, [state]) + const handleResize = (): void => { setWindowSize({ width: window.innerWidth, @@ -195,6 +203,28 @@ const App: React.FC = () => { } catch { } }; + + const toSrc = (path: string): void => { + switch (path) { + case '/login': + storage.removeItem('user') + navigate('/login') + break; + case '/home': + navigate('/home') + break; + + } + }; + const leaveChannel = async (): Promise => { + if (location.hash.indexOf('/meeting') === 1) { + const data = JSON.parse(localStorage.stateInfo); + await GetLeave({ + roomNum: data.channelId, + }) + await agora.leaveChannel() + } + }; const handleCustomStorageChange = (e: any): void => { if (e.key === 'loading') { setSpinning(Boolean(e.value)) diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index f1a4033..d0a01ca 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -894,7 +894,7 @@ const Meeting: React.FC = () => { : null} - + >全员看Ta : ''} {item.uid !== user.uid ?