This commit is contained in:
parent
1ef2e0cac1
commit
e7dccbba69
53
src/App.tsx
53
src/App.tsx
|
|
@ -31,7 +31,6 @@ const App: React.FC = () => {
|
|||
});
|
||||
const [spinning, setSpinning] = useState(false);
|
||||
const [isState, setIsState] = useState(true);
|
||||
const [isSignalr, setIsSignalr] = useState(true);
|
||||
useEffect(() => {
|
||||
let userInfo = JSON.parse(storage.getItem('user') as string)
|
||||
let loginInfo = JSON.parse(storage.getItem('login') as string)
|
||||
|
|
@ -45,7 +44,6 @@ const App: React.FC = () => {
|
|||
storage.setItem('user', JSON.stringify(res.data))
|
||||
toSrc('/home')
|
||||
await startSignalr()
|
||||
onEventSignalr()
|
||||
} else {
|
||||
toSrc('/login')
|
||||
}
|
||||
|
|
@ -153,7 +151,6 @@ const App: React.FC = () => {
|
|||
}
|
||||
})
|
||||
}
|
||||
onEventSignalr()
|
||||
storage.setItem('stateInfo', JSON.stringify(state))
|
||||
}, [state])
|
||||
const handleResize = (): void => {
|
||||
|
|
@ -171,36 +168,32 @@ const App: React.FC = () => {
|
|||
};
|
||||
|
||||
const onEventSignalr = (): void => {
|
||||
if (isSignalr) {
|
||||
setIsSignalr(false)
|
||||
onOtherSignalr(async (item: any) => {
|
||||
switch (item.key) {
|
||||
case 'Invitation':
|
||||
window.electron.joinNotification({
|
||||
body: item.roomName,
|
||||
name: item.InviterName,
|
||||
})
|
||||
joinMeetingModalRef.current.changeModal(item)
|
||||
break;
|
||||
case 'ForceLogout':
|
||||
if (item.msg) {
|
||||
message.error(item.msg)
|
||||
}
|
||||
await leaveChannel(true)
|
||||
toSrc('/login')
|
||||
break;
|
||||
}
|
||||
})
|
||||
onReconnected(async () => {
|
||||
storage.setItem('reconnect', true)
|
||||
})
|
||||
}
|
||||
onOtherSignalr(async (item: any) => {
|
||||
switch (item.key) {
|
||||
case 'Invitation':
|
||||
window.electron.joinNotification({
|
||||
body: item.roomName,
|
||||
name: item.InviterName,
|
||||
})
|
||||
joinMeetingModalRef.current.changeModal(item)
|
||||
break;
|
||||
case 'ForceLogout':
|
||||
if (item.msg) {
|
||||
message.error(item.msg)
|
||||
}
|
||||
await leaveChannel(true)
|
||||
toSrc('/login')
|
||||
break;
|
||||
}
|
||||
})
|
||||
onReconnected(async () => {
|
||||
storage.setItem('reconnect', true)
|
||||
})
|
||||
}
|
||||
const toSrc = (path: string): void => {
|
||||
switch (path) {
|
||||
case '/login':
|
||||
onStop()
|
||||
setIsSignalr(true)
|
||||
window.electron.setMainWindowSize({
|
||||
width: 752,
|
||||
height: 520,
|
||||
|
|
@ -233,6 +226,10 @@ const App: React.FC = () => {
|
|||
const handleCustomStorageChange = (e: any): void => {
|
||||
if (e.key === 'loading') {
|
||||
setSpinning(Boolean(e.value))
|
||||
} else if (e.key === 'isSignalr') {
|
||||
if (Boolean(e.value)) {
|
||||
onEventSignalr()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export const startSignalr = async () => {
|
|||
})
|
||||
.build();
|
||||
onStart()
|
||||
storage.setItem('isSignalr', true)
|
||||
connection.onclose(async () => {
|
||||
await onStart()
|
||||
});
|
||||
|
|
@ -162,6 +163,7 @@ export const onInvoke = async (str: string, data: any) => {
|
|||
}
|
||||
export const onStop = async () => {
|
||||
if (connection) {
|
||||
storage.setItem('isSignalr', false)
|
||||
connection.off('Invitation');
|
||||
connection.off('ForceLogout');
|
||||
connection.stop()
|
||||
|
|
|
|||
Loading…
Reference in New Issue