Merge pull request '代码格式化并添加类型' (#2) from yj into master

Reviewed-on: #2
This commit is contained in:
yj 2024-09-22 09:17:38 +08:00
commit 31e0e89c92
1 changed files with 60 additions and 67 deletions

View File

@ -1017,76 +1017,69 @@ const Meeting: React.FC = () => {
} }
}) })
break; break;
case '录制': case '录制':
const setting = await JSON.parse(storage.getItem('setting') as string); const setting = await JSON.parse(storage.getItem('setting') as string);
try { try {
await fs.access(setting.recordingFilesPath, fs.constants.F_OK); await fs.access(setting.recordingFilesPath, fs.constants.F_OK);
footerListTemplate[itemIndex][rowIndex].title = '录制中'; footerListTemplate[itemIndex][rowIndex].title = '录制中';
footerListTemplate[itemIndex][rowIndex].active = true; footerListTemplate[itemIndex][rowIndex].active = true;
setFooterList(footerListTemplate); setFooterList(footerListTemplate);
window.electron.getSources().then(async (sources: any) => {
const screenId = sources[0].id;
const stream = await navigator.mediaDevices.getUserMedia({
audio: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: screenId,
}
},
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: screenId,
}
}
});
// 获取所有音频输入设备 window.electron.getSources().then(async (sources: any) => {
const devices = await navigator.mediaDevices.enumerateDevices(); const screenId = sources[0].id;
const audioInputDevices = devices.filter(device => device.kind === 'audioinput' && const stream = await navigator.mediaDevices.getUserMedia({
device.deviceId !== 'default' && audio: {
device.deviceId !== 'communications' ); mandatory: {
chromeMediaSource: 'desktop',
// 使用Web Audio API来捕获系统声音和麦克风声音将它们合并到同一个MediaStream中。 chromeMediaSourceId: screenId,
const audioCtx = new (window.AudioContext || window.webkitAudioContext)(); }
const systemSoundSource = audioCtx.createMediaStreamSource(stream); } as any,
const systemSoundDestination = audioCtx.createMediaStreamDestination(); video: {
systemSoundSource.connect(systemSoundDestination); mandatory: {
chromeMediaSource: 'desktop',
// 录制所有音频输入设备 chromeMediaSourceId: screenId,
audioInputDevices.forEach( async device=>{ }
const micStream = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: device.deviceId } }}); } as any
const micSoundSource = audioCtx.createMediaStreamSource(micStream); });
micSoundSource.connect(systemSoundDestination); // 获取所有音频输入设备
}) const devices = await navigator.mediaDevices.enumerateDevices();
const audioInputDevices = devices.filter(device => device.kind === 'audioinput' &&
// 合并音频流与视频流 device.deviceId !== 'default' &&
const combinedSource = new MediaStream([...stream.getVideoTracks(), ...systemSoundDestination.stream.getAudioTracks()]); device.deviceId !== 'communications');
// 使用Web Audio API来捕获系统声音和麦克风声音将它们合并到同一个MediaStream中。
// 开始录制 const audioCtx = new (window.AudioContext || (window as any).webkitAudioContext)();
const recorder = new MediaRecorder(combinedSource, { const systemSoundSource = audioCtx.createMediaStreamSource(stream);
mimeType: 'video/webm;codecs=vp9,opus', const systemSoundDestination = audioCtx.createMediaStreamDestination();
videoBitsPerSecond: 1.5e6, systemSoundSource.connect(systemSoundDestination);
// 录制所有音频输入设备
audioInputDevices.forEach(async device => {
const micStream = await navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: device.deviceId } } });
const micSoundSource = audioCtx.createMediaStreamSource(micStream);
micSoundSource.connect(systemSoundDestination);
})
// 合并音频流与视频流
const combinedSource = new MediaStream([...stream.getVideoTracks(), ...systemSoundDestination.stream.getAudioTracks()]);
// 开始录制
const recorder = new MediaRecorder(combinedSource, {
mimeType: 'video/webm;codecs=vp9,opus',
videoBitsPerSecond: 1.5e6,
});
setMediaStream(combinedSource);
setRecorder(recorder);
}); });
} catch (error: any) {
setMediaStream(combinedSource); if (error.code === 'ENOENT') {
setRecorder(recorder); message.error({
}); content: <div> <span style={{ color: '#606fc7', cursor: 'pointer' }} onClick={() => {
} catch (error: any) { stupWizardRef.current.changeModal(3);
if (error.code === 'ENOENT') { }}></span></div>
message.error({ });
content: <div> <span style={{ color: '#606fc7', cursor: 'pointer' }} onClick={() => { return;
stupWizardRef.current.changeModal(3); } else {
}}></span></div> message.error(error);
}); }
return;
} else {
message.error(error);
} }
}
break; break;
case '录制中': case '录制中':
footerListTemplate[itemIndex][rowIndex].title = '录制' footerListTemplate[itemIndex][rowIndex].title = '录制'