This commit is contained in:
parent
150cd2655c
commit
975678be84
82
src/App.tsx
82
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<void> => {
|
||||
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))
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ const Meeting: React.FC = () => {
|
|||
</div> : null}
|
||||
<Popover placement="bottom" title={''} content={
|
||||
<div className={styles.meetingContentSwiperCardPopover}>
|
||||
<Button
|
||||
{user.roleId === '1' ? <Button
|
||||
type="primary"
|
||||
className='m-ant-btn'
|
||||
size={'small'}
|
||||
|
|
@ -902,7 +902,7 @@ const Meeting: React.FC = () => {
|
|||
event.stopPropagation();
|
||||
setAllUserLook(item)
|
||||
}}
|
||||
>全员看Ta</Button>
|
||||
>全员看Ta</Button> : ''}
|
||||
{item.uid !== user.uid ? <Button
|
||||
type="primary"
|
||||
className='m-ant-btn'
|
||||
|
|
|
|||
|
|
@ -35,14 +35,22 @@ export const onReconnected = async (callBack: Function) => {
|
|||
});
|
||||
}
|
||||
}
|
||||
export const onInvitation = (callBack: Function) => {
|
||||
export const onOtherSignalr = (callBack: Function) => {
|
||||
if (connection) {
|
||||
// 邀请
|
||||
connection.on("Invitation", (roomNum: string, roomName: string, InviterName: string) => {
|
||||
callBack({
|
||||
key: 'Invitation',
|
||||
roomNum, roomName, InviterName
|
||||
})
|
||||
});
|
||||
// 退出
|
||||
connection.on("ForceLogout", (msg: string) => {
|
||||
callBack({
|
||||
key: 'ForceLogout',
|
||||
msg
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
export const onSignalr = (callBack: Function) => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue