This commit is contained in:
yj 2024-07-23 16:28:40 +08:00
parent 49419a136e
commit c324aa6fa2
2 changed files with 48 additions and 43 deletions

View File

@ -64,10 +64,11 @@ const Index: React.FC = () => {
} }
}) })
} }
const postRefresh = async (): Promise<void> => { const postRefresh = async (callBack: Function): Promise<void> => {
await PostRefresh(user.refresh_token).then(res => { await PostRefresh(user.refresh_token).then(res => {
if (res.code === 200) { if (res.code === 200) {
storage.setItem('user', JSON.stringify(res.data)) storage.setItem('user', JSON.stringify(res.data))
callBack(res.data)
} }
}) })
} }
@ -126,19 +127,20 @@ const Index: React.FC = () => {
{/* <Button type="primary" danger>设置</Button> */} {/* <Button type="primary" danger>设置</Button> */}
<Button type="primary" <Button type="primary"
iconPosition={'end'} iconPosition={'end'}
onClick={async () => { onClick={() => {
await postRefresh() postRefresh(() => {
await getRoomRtcToken(item.roomNum, (res: any) => { getRoomRtcToken(item.roomNum, (res: any) => {
if (res) { if (res) {
navigate(`/meeting`, { navigate(`/meeting`, {
state: { state: {
channelId: item.roomNum, channelId: item.roomNum,
token: res, token: res,
roomId: item.id, roomId: item.id,
roomName: item.roomName, roomName: item.roomName,
} }
}) })
} }
})
}) })
}} }}
icon={<img src={ImageUrl.icon9} alt="" />} icon={<img src={ImageUrl.icon9} alt="" />}
@ -267,33 +269,34 @@ const Index: React.FC = () => {
display: 'flex', justifyContent: 'center' display: 'flex', justifyContent: 'center'
}}> }}>
<Button type="primary" style={{ backgroundColor: '#31353A', marginRight: '14px' }} onClick={() => setJoinRoomModal(false)}></Button> <Button type="primary" style={{ backgroundColor: '#31353A', marginRight: '14px' }} onClick={() => setJoinRoomModal(false)}></Button>
<Button type="primary" className='m-ant-btn' onClick={async () => { <Button type="primary" className='m-ant-btn' onClick={() => {
if (!joinRoomFrom) { if (!joinRoomFrom) {
return message.error('请输入房间号!') return message.error('请输入房间号!')
} }
await postRefresh() postRefresh(() => {
await isGetCheckoutRoomNum(joinRoomFrom, (bool: boolean) => { isGetCheckoutRoomNum(joinRoomFrom, (bool: boolean) => {
if (bool) { if (bool) {
getRoomRtcToken(joinRoomFrom, (token: string) => { getRoomRtcToken(joinRoomFrom, (token: string) => {
if (token) { if (token) {
setJoinRoomModal(false) setJoinRoomModal(false)
GetRoomInfo(joinRoomFrom).then(res => { GetRoomInfo(joinRoomFrom).then(res => {
if (res.code === 200) { if (res.code === 200) {
navigate(`/meeting`, { navigate(`/meeting`, {
state: { state: {
channelId: joinRoomFrom, channelId: joinRoomFrom,
token, token,
roomId: res.data.id, roomId: res.data.id,
roomName: res.data.roomName, roomName: res.data.roomName,
} }
}) })
} }
}) })
} }
}) })
} else { } else {
message.error('房间号不存在!') message.error('房间号不存在!')
} }
})
}) })
}}></Button> }}></Button>
</div> </div>

View File

@ -330,10 +330,12 @@ const Meeting: React.FC = () => {
} }
} }
// 退出房间 // 退出房间
const leaveChannel = async (): Promise<void> => { const leaveChannel = async (bool?: boolean): Promise<void> => {
await onInvoke('levelChannel', { if (!bool) {
roomNum: state.channelId await onInvoke('levelChannel', {
}) roomNum: state.channelId
})
}
agora.leaveChannel() agora.leaveChannel()
navigate('/home/index') navigate('/home/index')
} }
@ -734,7 +736,7 @@ const Meeting: React.FC = () => {
roomNum: state.channelId, roomNum: state.channelId,
type: 1, type: 1,
}) })
leaveChannel() leaveChannel(true)
}}></div> }}></div>
<div onClick={() => leaveChannel()}></div> <div onClick={() => leaveChannel()}></div>
<div onClick={() => { setOpen(false) }}></div> <div onClick={() => { setOpen(false) }}></div>