From 28119cb8288cf26101d97ce3e350edf022e925de Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 14 Aug 2024 14:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 10 ++-- src/App.tsx | 29 ++++-------- src/components/JoinSetting/index.module.scss | 14 +++++- src/components/JoinSetting/index.tsx | 28 ++++++++++-- src/utils/package/agora.ts | 6 +-- src/utils/request/request.ts | 48 +++++++++++--------- 6 files changed, 82 insertions(+), 53 deletions(-) diff --git a/main.js b/main.js index 658b99a..ac6b73b 100644 --- a/main.js +++ b/main.js @@ -255,11 +255,11 @@ app.on('ready', () => { } // 设置窗口尺寸 mainWindow.setSize(config.width, config.height) - // // 设置窗口位置使其居中于当前屏幕 - // const display = screen.getDisplayMatching({...mainWindow.getBounds()}); - // const x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2); - // const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2); - // mainWindow.setPosition(x, y); + // 设置窗口位置使其居中于当前屏幕 + const display = screen.getDisplayMatching({...mainWindow.getBounds()}); + const x = Math.round((display.workArea.width - mainWindow.getSize()[0]) / 2); + const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2); + mainWindow.setPosition(x, y); }); }); diff --git a/src/App.tsx b/src/App.tsx index f42c764..3b3c3ad 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -134,25 +134,6 @@ const App: React.FC = () => { }, 3000); }, []) - useEffect(() => { - try { - if (location.hash.indexOf('/login') !== -1) { - onStop() - 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) @@ -217,10 +198,20 @@ const App: React.FC = () => { const toSrc = (path: string): void => { switch (path) { case '/login': + onStop() + window.electron.setMainWindowSize({ + width: 752, + height: 520, + key: 'login' + }) storage.removeItem('user') navigate('/login') break; case '/home': + window.electron.setMainWindowSize({ + width: 1200, + height: 800, + }) navigate('/home') break; diff --git a/src/components/JoinSetting/index.module.scss b/src/components/JoinSetting/index.module.scss index 140ca1f..5595f85 100644 --- a/src/components/JoinSetting/index.module.scss +++ b/src/components/JoinSetting/index.module.scss @@ -24,14 +24,26 @@ >div:nth-child(2) { margin: 10px 0; height: 260px; + width: 100%; background-color: #1E1E1F; + overflow: hidden; display: flex; justify-content: center; align-items: center; + position: relative; - >div { + >div:nth-child(1) { transform: scale(2); } + + >div:nth-child(2) { + position: absolute; + left: 0; + top: 0; + z-index: 1; + width: 100%; + height: 100%; + } } >div:nth-child(3) { diff --git a/src/components/JoinSetting/index.tsx b/src/components/JoinSetting/index.tsx index 1610699..1d9b518 100644 --- a/src/components/JoinSetting/index.tsx +++ b/src/components/JoinSetting/index.tsx @@ -3,10 +3,11 @@ import { storage } from '@/utils'; import ImageUrl from '@/utils/package/ImageUrl'; import { GetCheckoutRoomNum, GetRoomRtcToken, GetRoomInfo } from '@/api/Home/Index'; import { Button, Modal, message } from 'antd'; -import { useState, useImperativeHandle, forwardRef } from "react"; +import { useState, useImperativeHandle, forwardRef, useEffect } from "react"; import { PostRefresh } from '@/api/Login'; import Avatar from '@/components/Avatar'; import { useNavigate } from 'react-router-dom'; +import agora from '@/utils/package/agora'; const JoinSetting = forwardRef((_props: any, ref: any) => { useImperativeHandle(ref, () => ({ changeModal: (roomNum: string = '') => { @@ -17,6 +18,9 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { ...joinRoomSettingForm, roomNum, }) + if (location.hash.indexOf('/meeting') === -1) { + agora.init() + } } })) const navigate = useNavigate(); @@ -63,7 +67,14 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { } return ( <> - setJoinRoomSettingModal(false)}> + { + agora.release() + setJoinRoomSettingModal(false) + }}>
请输入会议号 @@ -84,18 +95,26 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
+ {joinRoomSettingForm.list[1].active ?
+ +
: null}
{ joinRoomSettingForm.list.map((item, index) => { - return
{ + return
{ const list = [...joinRoomSettingForm.list] list[index].active = !list[index].active setJoinRoomSettingForm({ ...joinRoomSettingForm, list }) + if (index === 1) { + if (list[index].active) { + await agora.startPreview('videoPreview', Number(user.account)) + } + } }}>
@@ -116,8 +135,9 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { if (token) { postRefresh(() => { setJoinRoomSettingModal(false) - GetRoomInfo(joinRoomSettingForm.roomNum).then(res => { + GetRoomInfo(joinRoomSettingForm.roomNum).then(async (res) => { if (res.code === 200) { + await agora.release() navigate(`/meeting`, { state: { channelId: joinRoomSettingForm.roomNum, diff --git a/src/utils/package/agora.ts b/src/utils/package/agora.ts index 0d8431c..801dd11 100644 --- a/src/utils/package/agora.ts +++ b/src/utils/package/agora.ts @@ -126,8 +126,8 @@ const agora = { ); }, // 销毁 - release: () => { - rtcEngine.release() + release: async () => { + await rtcEngine.release() }, // 离开频道 leaveChannel: async () => { @@ -264,7 +264,7 @@ const agora = { rtcEngine.startPreview(); await GetRoomRtcToken(`${+new Date()}`).then(async (res) => { await rtcEngine.joinChannelEx(res.data, { - channelId: `${+new Date()}`, + channelId: `${+new Date() + uid}`, localUid: uid, }, { channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting, diff --git a/src/utils/request/request.ts b/src/utils/request/request.ts index be79583..f762699 100644 --- a/src/utils/request/request.ts +++ b/src/utils/request/request.ts @@ -61,37 +61,21 @@ class Request { } } if (resData.code === 1403) { - storage.removeItem('user') - location.href = location.origin + '/#/login' + toLogin() } return resData }, (err: any) => { - function toLogin() { - let user = JSON.parse(storage.getItem('user') as string); - if (user) { - PostRefresh(user.refresh_token).then((res) => { - if (res.code == 200) { - storage.setItem('user', JSON.stringify(res.data)) - } else { - storage.removeItem('user') - location.href = location.origin + '/#/login' - } - }) - } else { - storage.removeItem('user') - location.href = location.origin + '/#/login' - } - } + // 根据自己业务/接口返回做相应调整 if (err.response) { const { status } = err.response switch (status) { case 401: - toLogin() + updatePostRefresh() break case 403: - toLogin() + updatePostRefresh() break default: message.error(err.message) @@ -127,5 +111,27 @@ class Request { }) } } - +function toLogin() { + window.electron.setMainWindowSize({ + width: 752, + height: 520, + key: 'login' + }) + storage.removeItem('user') + location.href = location.origin + '/#/login' +} +function updatePostRefresh() { + let user = JSON.parse(storage.getItem('user') as string); + if (user) { + PostRefresh(user.refresh_token).then((res) => { + if (res.code == 200) { + storage.setItem('user', JSON.stringify(res.data)) + } else { + toLogin() + } + }) + } else { + toLogin() + } +} export default Request