分享屏幕

This commit is contained in:
yj 2024-07-17 10:26:03 +08:00
parent 0bd4cb5840
commit 98ef1f62ba
4 changed files with 47 additions and 52 deletions

View File

@ -65,7 +65,7 @@ const App: React.FC = () => {
}); });
try { try {
window.electron.getIsMaximized().then((res: boolean) => { window.electron.getIsMaximized().then((res: boolean) => {
const dom = document.getElementById('root') as any; const dom = document.getElementById('root') as HTMLElement;
dom.style.borderRadius = res ? '0px' : '10px' dom.style.borderRadius = res ? '0px' : '10px'
}) })
} catch { } } catch { }

View File

@ -12,7 +12,6 @@ import ImageUrl from '@/utils/package/imageUrl'
const Login: React.FC = () => { const Login: React.FC = () => {
const navigate = useNavigate(); const navigate = useNavigate();
const [accountPasswordStatus, setAccountPasswordStatus] = useState<boolean>(false); const [accountPasswordStatus, setAccountPasswordStatus] = useState<boolean>(false);
const [accountStatus, setAccountStatus] = useState<boolean>(false);
const [operation, setOperation] = useState<{ const [operation, setOperation] = useState<{
isRememberPassword: boolean; isRememberPassword: boolean;
isAutoLogin: boolean; isAutoLogin: boolean;
@ -62,11 +61,6 @@ const Login: React.FC = () => {
...data, ...data,
}) })
} }
GetCheckUser(login.account).then(res => {
if (res.code === 200) {
setAccountStatus(res.data)
}
})
} }
}, []); }, []);
@ -86,7 +80,11 @@ const Login: React.FC = () => {
} }
// 继续 // 继续
const continueClick = (): void => { const continueClick = (): void => {
setAccountPasswordStatus(true); GetCheckUser(operation.account).then(res => {
if (res.code === 200) {
res.data ? setAccountPasswordStatus(true) : message.error('账号不存在!')
}
})
} }
// 设置勾选 // 设置勾选
@ -158,13 +156,6 @@ const Login: React.FC = () => {
...operation, ...operation,
account: e.target.value account: e.target.value
}) })
if (e.target.value) {
GetCheckUser(e.target.value).then(res => {
if (res.code === 200) {
setAccountStatus(res.data)
}
})
}
}} }}
className={`${styles.loginInputIcon} drag`} className={`${styles.loginInputIcon} drag`}
style={{ marginBottom: '12px' }} style={{ marginBottom: '12px' }}
@ -179,7 +170,7 @@ const Login: React.FC = () => {
} }
/> />
{operation.account && !accountPasswordStatus && accountStatus ? <div style={{ marginTop: '36px' }} className='drag'> {!accountPasswordStatus ? <div style={{ marginTop: '36px' }} className='drag'>
<Button type="primary" <Button type="primary"
onClick={continueClick} onClick={continueClick}
style={{ width: '100%' }} style={{ width: '100%' }}

View File

@ -14,6 +14,7 @@ import StupWizard from '@/components/StupWizard';
import { onInvoke, onSignalr } from '@/utils/package/signalr'; import { onInvoke, onSignalr } from '@/utils/package/signalr';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import durationPlugin from 'dayjs/plugin/duration'; import durationPlugin from 'dayjs/plugin/duration';
import { VideoSourceType } from 'agora-electron-sdk';
dayjs.extend(durationPlugin); dayjs.extend(durationPlugin);
const { Column } = Table const { Column } = Table
const Meeting: React.FC = () => { const Meeting: React.FC = () => {
@ -110,8 +111,6 @@ const Meeting: React.FC = () => {
const [currentVideoId, setCurrentVideoId] = useState('') const [currentVideoId, setCurrentVideoId] = useState('')
let [currentSeconds, setCurrentSeconds] = useState(0) let [currentSeconds, setCurrentSeconds] = useState(0)
const [currentEffective, setCurrentEffective] = useState(0) const [currentEffective, setCurrentEffective] = useState(0)
const [list] = useState<number[]>([1, 2, 3, 4, 5, 6, 7])
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
useEffect(() => { useEffect(() => {
let time = null as any; let time = null as any;
@ -123,6 +122,7 @@ const Meeting: React.FC = () => {
userid: userInfo.account, userid: userInfo.account,
token: state.token, token: state.token,
}) })
agora.setCameraCapture(VideoSourceType.VideoSourceCameraPrimary)
setCurrentVideoId(userInfo.account) setCurrentVideoId(userInfo.account)
setUser(userInfo) setUser(userInfo)
setIsInit(false) setIsInit(false)
@ -187,7 +187,7 @@ const Meeting: React.FC = () => {
}, []) }, [])
useEffect(() => { useEffect(() => {
console.log(currentVideoId);
}, [currentVideoId]) }, [currentVideoId])
// 加入房间时间 // 加入房间时间
@ -223,7 +223,7 @@ const Meeting: React.FC = () => {
setIsSharedScreenModal(true) setIsSharedScreenModal(true)
break; break;
case '停止共享': case '停止共享':
agora.stopScreenCapture() agora.setCameraCapture(VideoSourceType.VideoSourceCameraPrimary)
footerListTemplate[itemIndex][rowIndex].title = '共享屏幕' footerListTemplate[itemIndex][rowIndex].title = '共享屏幕'
break; break;
case '关闭声音': case '关闭声音':
@ -288,7 +288,7 @@ const Meeting: React.FC = () => {
const footerListTemplate = [...footerList] const footerListTemplate = [...footerList]
footerListTemplate[footerListIndex.itemIndex][footerListIndex.rowIndex].title = '停止共享' footerListTemplate[footerListIndex.itemIndex][footerListIndex.rowIndex].title = '停止共享'
setIsSharedScreenModal(false) setIsSharedScreenModal(false)
agora.setDesktopCapturerVideo(sharedScreenItem) agora.setDesktopCapturerVideo(sharedScreenItem, VideoSourceType.VideoSourceScreen)
} else { } else {
message.error('请选择应用!') message.error('请选择应用!')
} }

View File

@ -17,6 +17,7 @@ const option: any = {
token: '', token: '',
channelId: '', channelId: '',
userid: '', userid: '',
sourceType: VideoSourceType.VideoSourceCameraPrimary,
} }
let iMediaRecorder: any = ''; let iMediaRecorder: any = '';
let rtcEngine: any = ''; let rtcEngine: any = '';
@ -77,8 +78,7 @@ const agora = {
setupLocalVideo: (item: any) => { setupLocalVideo: (item: any) => {
rtcEngine.setupLocalVideo({ rtcEngine.setupLocalVideo({
renderMode: RenderModeType.RenderModeFit, renderMode: RenderModeType.RenderModeFit,
sourceType: VideoSourceType.VideoSourceCameraPrimary, sourceType: option.sourceType,
// sourceType: option.isCamera ? VideoSourceType.VideoSourceCameraPrimary : VideoSourceType.VideoSourceScreen,
uid: item.account, uid: item.account,
view: item.view, view: item.view,
setupMode: VideoViewSetupMode.VideoViewSetupAdd, setupMode: VideoViewSetupMode.VideoViewSetupAdd,
@ -116,29 +116,16 @@ const agora = {
storage.setItem('isJoin', false) storage.setItem('isJoin', false)
}, },
// 加入频道 // 加入频道
joinChannel: (bool: boolean) => { joinChannel: () => {
// false 摄像头 true 共享屏幕 rtcEngine.joinChannel(option.token, option.channelId, option.userid, {
if (bool) { channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting, //设置频道场景为直播场景
rtcEngine.joinChannel(option.token, option.channelId, option.userid, { clientRoleType: ClientRoleType.ClientRoleBroadcaster, //用户角色 1主播 2观众
channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting, //设置频道场景为直播场景 publishMicrophoneTrack: true, //设置是否发布麦克风采集到的音频
clientRoleType: ClientRoleType.ClientRoleBroadcaster, //用户角色 1主播 2观众 publishCameraTrack: true, //设置是否发布摄像头采集的视频
publishMicrophoneTrack: true, //设置是否发布麦克风采集到的音频 publishScreenTrack: true, //设置是否发布屏幕采集的视频
publishCameraTrack: false, //设置是否发布摄像头采集的视频 autoSubscribeAudio: true, //设置是否自动订阅所有音频流
publishScreenTrack: true, //设置是否发布屏幕采集的视频 autoSubscribeVideo: true, //设置是否自动订阅所有视频流
autoSubscribeAudio: true, //设置是否自动订阅所有音频流 });
autoSubscribeVideo: true, //设置是否自动订阅所有视频流
});
} else {
rtcEngine.joinChannel(option.token, option.channelId, option.userid, {
channelProfile: ChannelProfileType.ChannelProfileLiveBroadcasting, //设置频道场景为直播场景
clientRoleType: ClientRoleType.ClientRoleBroadcaster, //设置用户角色为主播;如果要将用户角色设置为观众,保持默认值即可
publishMicrophoneTrack: true, //发布麦克风采集的音频
publishCameraTrack: true, //发布摄像头采集的视频
publishScreenTrack: false, //设置是否发布屏幕采集的视频
autoSubscribeAudio: true, //自动订阅所有音频流
autoSubscribeVideo: true, //自动订阅所有视频流
});
}
}, },
// 停止共享屏幕 // 停止共享屏幕
stopScreenCapture: () => { stopScreenCapture: () => {
@ -153,25 +140,42 @@ const agora = {
rtcEngine.muteLocalVideoStream(mute) rtcEngine.muteLocalVideoStream(mute)
}, },
// 摄像头采集 // 摄像头采集
setCameraCapture: () => { setCameraCapture: (sourceType: number) => {
agora.stopScreenCapture()
if (sourceType !== option.sourceType) {
rtcEngine.destroyRendererByConfig(option.sourceType, option.channelId, option.account)
option.sourceType = sourceType
agora.setupLocalVideo({
account: Number(option.userid),
view: document.getElementById(`video-${option.userid}`),
channelId: option.channelId,
})
}
rtcEngine.startCameraCapture(VideoSourceType.VideoSourceCamera, {}) rtcEngine.startCameraCapture(VideoSourceType.VideoSourceCamera, {})
agora.joinChannel(false)
}, },
// 加入频道 // 加入频道
setJoinChannel: (data: any) => { setJoinChannel: (data: any) => {
option.token = data.token; option.token = data.token;
option.channelId = data.channelId; option.channelId = data.channelId;
option.userid = Number(data.userid); option.userid = Number(data.userid);
rtcEngine.startCameraCapture(VideoSourceType.VideoSourceCamera, {}) agora.joinChannel()
agora.joinChannel(false)
}, },
// 桌面捕获音频和视频的媒体源的信息 // 桌面捕获音频和视频的媒体源的信息
getDesktopCapturerVideo: async () => { getDesktopCapturerVideo: async () => {
return rtcEngine.getScreenCaptureSources({ width: 300, height: 300 }, { width: 300, height: 300 }, true); return rtcEngine.getScreenCaptureSources({ width: 300, height: 300 }, { width: 300, height: 300 }, true);
}, },
// 共享屏幕采集 // 共享屏幕采集
setDesktopCapturerVideo: (targetSource: any) => { setDesktopCapturerVideo: (targetSource: any, sourceType: number) => {
// rtcEngine.stopCameraCapture(VideoSourceType.VideoSourceCamera); if (sourceType !== option.sourceType) {
rtcEngine.stopCameraCapture(option.sourceType)
rtcEngine.destroyRendererByConfig(option.sourceType, option.channelId, option.account)
option.sourceType = sourceType
agora.setupLocalVideo({
account: Number(option.userid),
view: document.getElementById(`video-${option.userid}`),
channelId: option.channelId,
})
}
agora.stopScreenCapture(); agora.stopScreenCapture();
if ( if (
targetSource.type === targetSource.type ===