Compare commits

..

7 Commits

Author SHA1 Message Date
yangqiang ef2eb499ab Merge pull request 'video-info' (#7) from video-info into master
Reviewed-on: #7
2024-09-23 13:51:06 +08:00
youngq b86c4230bb 1 2024-09-23 13:37:53 +08:00
youngq c9362fc14d 1 2024-09-23 13:32:30 +08:00
youngq 1b7480cadc 完成mp4 2024-09-23 13:03:05 +08:00
youngq 606715ced6 1 2024-09-23 11:09:58 +08:00
yj e2615f846f 111 2024-09-23 11:05:31 +08:00
yj fc50a28504 恢复9.21号代码 2024-09-23 09:58:08 +08:00
3 changed files with 196 additions and 86 deletions

59
main.js
View File

@ -12,6 +12,7 @@ const {
} = require('electron');
const path = require('node:path')
const fs = require('fs');
const https = require('https');
const { autoUpdater, CancellationToken } = require('electron-updater');
const cancellationToken = new CancellationToken()
app.allowRendererProcessReuse = false;
@ -271,6 +272,25 @@ app.on('ready', () => {
const y = Math.round((display.workArea.height - mainWindow.getSize()[1]) / 2);
mainWindow.setPosition(x, y);
});
// 监听渲染进程请求应用数据目录
ipcMain.handle('get-user-data-path', () => {
return app.getPath('userData');
});
// 用户数据目录路径
const userDataPath = app.getPath('userData'); // 全局变量
console.log('User Data Path:', userDataPath);
// 检查并下载 ffmpeg
checkAndDownloadFFmpeg(userDataPath)
.then(() => {
console.log('FFmpeg is ready for use.');
// 在这里执行任何依赖于 ffmpeg 的操作
})
.catch(error => {
console.error('Failed to ensure ffmpeg is available:', error);
app.quit();
});
}
});
// 检测更新在你想要检查更新的时候执行renderer事件触发后的操作自行编写
@ -339,3 +359,42 @@ function cancleDownloadUpdate() {
function quitAndInstall() {
autoUpdater.quitAndInstall();
}
// 下载文件
function downloadFile(url, dest) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https.get(url, function (response) {
response.pipe(file);
file.on('finish', function () {
file.close(resolve);
});
}).on('error', function (err) {
fs.unlink(dest, () => reject(err));
});
});
}
// 检查并下载ffmpeg
function checkAndDownloadFFmpeg(appPath) {
const ffmpegPath = path.join(appPath, 'ffmpeg.exe');
return new Promise((resolve, reject) => {
if (!fs.existsSync(ffmpegPath)) {
console.log(`ffmpeg.exe not found at ${ffmpegPath}, downloading...`);
downloadFile('https://meeting-api.23544.com/meeting/update/ffmpeg.exe', ffmpegPath)
.then(() => {
console.log('ffmpeg.exe downloaded successfully.');
resolve();
})
.catch(error => {
console.error('Error downloading ffmpeg.exe:', error);
reject(error);
});
} else {
console.log(`ffmpeg.exe found at ${ffmpegPath}.`);
resolve();
}
});
}

View File

@ -1,7 +1,7 @@
{
"name": "WGShare.Metting",
"private": true,
"version": "0.1.14",
"version": "0.3.1",
"main": "main.js",
"authors": "yj",
"description": "智汇享",

View File

@ -21,8 +21,10 @@ import StupWizard from '@/components/StupWizard';
import EquipmentManagement from '@/components/EquipmentManagement';
import UserVideo from '@/components/UserVideo';
import { role } from '@/config/role';
import { fixWebmDuration } from "webm-duration-fix-buffer";
const { ipcRenderer } = require('electron');
import * as path from 'path';
const { confirm } = Modal;
const { exec } = require('child_process');
const fs = require('fs').promises;
dayjs.extend(durationPlugin);
@ -540,13 +542,53 @@ const Meeting: React.FC = () => {
useEffect(() => {
if (recorder) {
recorder.start();
recorder.ondataavailable = async (event: any) => {
const blob = await fixWebmDuration(event.data);
recorder.ondataavailable = (event: any) => {
const blob = new Blob([event.data], {
type: 'video/webm',
});
const reader = new FileReader() as any;
reader.onload = async () => {
try {
const userDataPath = await ipcRenderer.invoke('get-user-data-path');
// 获取当前日期并格式化
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth() + 1; // JavaScript月份从0开始
const day = date.getDate();
const hours = date.getHours();
const minutes = date.getMinutes();
const formattedDate = `${year}${month}${day}${hours}${minutes}`;
const setting = await JSON.parse(storage.getItem('setting') as string)
const buffer = Buffer.from(reader.result);
await fs.writeFile(`${setting.recordingFilesPath}会议录制_${state.roomName}_${state.channelId}_${+new Date()}.webm`, buffer, {});
const mp4Path=`${setting.recordingFilesPath}会议录制_${state.roomName}_${state.channelId}_${formattedDate}_beforehanlder.mp4`;
await fs.writeFile(mp4Path, buffer);
// 获取应用程序安装路径
const ffmpegPath = path.join(userDataPath, "ffmpeg.exe");
const inputFilePath = mp4Path; // 输入文件路径
const outputFilePath = mp4Path.replace('_beforehanlder',''); // 输出文件路径
const command = `${ffmpegPath} -i "${inputFilePath}" -vcodec copy -acodec copy "${outputFilePath}"`;
exec(command, (error:any, stdout:any, stderr:any) => {
if (error) {
console.error('Error executing ffmpeg command:', error);
return;
}
// 删除输入文件
fs.unlink(inputFilePath, (err:any) => {
if (err) {
console.error('Error deleting input file:', err);
} else {
console.log('Input file deleted successfully.');
}
});
confirm({
title: '提示',
icon: <ExclamationCircleFilled />,
@ -565,7 +607,14 @@ const Meeting: React.FC = () => {
onCancel() {
}
})
};
});
} catch (err) {
console.error('处理录制时出错:', err);
}
}
reader.readAsArrayBuffer(blob);
}
};
@ -1285,6 +1334,8 @@ const Meeting: React.FC = () => {
}
})
}
// 开关麦克风
const postOpenMicrApi = async (enableMicr: boolean, uid: string, isAll: boolean, isMessage: boolean = false): Promise<void> => {
if (isAll) {