[mirotalksfu] - add cloud, update dep
هذا الالتزام موجود في:
27
cloud/README.md
Normal file
27
cloud/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Cloud Recording
|
||||
|
||||

|
||||
|
||||
To save `recordings` on a different `server` or `cloud service` copy this `cloud folder` to the desired server.
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Start the server
|
||||
npm start
|
||||
```
|
||||
|
||||
## Edit config.js
|
||||
|
||||
In the MiroTalk SFU `app/src/config.js` file, change the endpoint to send recording chunks:
|
||||
|
||||
```js
|
||||
recording: {
|
||||
endpoint: 'http://localhost:8080', // Change it with your Server endpoint
|
||||
dir: 'rec',
|
||||
enabled: true,
|
||||
},
|
||||
```
|
||||
ثنائية
cloud/assets/cloud.png
Normal file
ثنائية
cloud/assets/cloud.png
Normal file
ملف ثنائي غير معروض.
|
بعد العرض: | الارتفاع: | الحجم: 6.9 KiB |
23
cloud/package.json
Normal file
23
cloud/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "cloud",
|
||||
"version": "1.0.0",
|
||||
"description": "Cloud server to handle MiroTalk SFU recording uploads",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js",
|
||||
"start-dev": "nodemon server.js"
|
||||
},
|
||||
"keywords": [
|
||||
"cloud",
|
||||
"recording"
|
||||
],
|
||||
"author": "Miroslav Pejic",
|
||||
"license": "AGPLv3",
|
||||
"dependencies": {
|
||||
"cors": "2.8.5",
|
||||
"express": "^4.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^3.1.3"
|
||||
}
|
||||
}
|
||||
77
cloud/server.js
Normal file
77
cloud/server.js
Normal file
@@ -0,0 +1,77 @@
|
||||
'use strict';
|
||||
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const app = express();
|
||||
const port = process.env.PORT || 8080;
|
||||
|
||||
// Replace with your actual logging mechanism
|
||||
const log = {
|
||||
error: console.error,
|
||||
debug: console.log,
|
||||
};
|
||||
|
||||
// Directory where recordings will be stored
|
||||
const recordingDirectory = path.join(__dirname, 'rec');
|
||||
|
||||
// Flag to enable/disable server recording
|
||||
const isServerRecordingEnabled = true;
|
||||
|
||||
// CORS options
|
||||
const corsOptions = {
|
||||
origin: '*',
|
||||
methods: ['POST'],
|
||||
};
|
||||
|
||||
// Middleware
|
||||
app.use(express.json());
|
||||
app.use(cors(corsOptions));
|
||||
|
||||
// Ensure the recording directory exists
|
||||
function ensureRecordingDirectoryExists() {
|
||||
if (!fs.existsSync(recordingDirectory)) {
|
||||
fs.mkdirSync(recordingDirectory, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
// Endpoint to handle recording uploads
|
||||
app.post('/recSync', (req, res) => {
|
||||
if (!isServerRecordingEnabled) {
|
||||
return res.status(403).send('Server recording is disabled');
|
||||
}
|
||||
|
||||
const { fileName } = req.query;
|
||||
|
||||
if (!fileName) {
|
||||
return res.status(400).send('Filename not provided');
|
||||
}
|
||||
|
||||
ensureRecordingDirectoryExists();
|
||||
|
||||
const filePath = path.join(recordingDirectory, fileName);
|
||||
const writeStream = fs.createWriteStream(filePath, { flags: 'a' });
|
||||
|
||||
req.pipe(writeStream);
|
||||
|
||||
writeStream.on('error', (err) => {
|
||||
log.error('Error writing to file:', err.message);
|
||||
res.status(500).send('Internal Server Error');
|
||||
});
|
||||
|
||||
writeStream.on('finish', () => {
|
||||
log.debug('File saved successfully:', fileName);
|
||||
res.status(200).send('File uploaded successfully');
|
||||
});
|
||||
|
||||
req.on('error', (err) => {
|
||||
log.error('Error processing request:', err.message);
|
||||
res.status(500).send('Internal Server Error');
|
||||
});
|
||||
});
|
||||
|
||||
// Start the server
|
||||
app.listen(port, () => {
|
||||
log.debug(`Server is running on http://localhost:${port}`);
|
||||
});
|
||||
المرجع في مشكلة جديدة
حظر مستخدم