[mirotalksfu] - add chokidar
هذا الالتزام موجود في:
@@ -1,5 +1,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const chokidar = require('chokidar');
|
||||||
|
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
|
|
||||||
const log = new Logger('HtmlInjector');
|
const log = new Logger('HtmlInjector');
|
||||||
@@ -10,6 +12,7 @@ class HtmlInjector {
|
|||||||
this.cache = {}; // Object to store cached files
|
this.cache = {}; // Object to store cached files
|
||||||
this.config = config; // Configuration containing metadata (OG, title, etc.)
|
this.config = config; // Configuration containing metadata (OG, title, etc.)
|
||||||
this.injectData = this.getInjectData(); // Initialize dynamic injection data
|
this.injectData = this.getInjectData(); // Initialize dynamic injection data
|
||||||
|
this.watcher = null; // File watcher instance
|
||||||
this.preloadPages(filesPath); // Preload pages at startup
|
this.preloadPages(filesPath); // Preload pages at startup
|
||||||
this.watchFiles(filesPath); // Watch files for changes
|
this.watchFiles(filesPath); // Watch files for changes
|
||||||
log.info('filesPath cached', this.filesPath);
|
log.info('filesPath cached', this.filesPath);
|
||||||
@@ -45,20 +48,26 @@ class HtmlInjector {
|
|||||||
filePaths.forEach((filePath) => this.loadFileToCache(filePath));
|
filePaths.forEach((filePath) => this.loadFileToCache(filePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to watch a file for changes and reload the cache
|
// Function to watch files for changes using chokidar
|
||||||
watchFileForChanges(filePath) {
|
watchFiles(filePaths) {
|
||||||
fs.watch(filePath, (eventType) => {
|
if (this.watcher) {
|
||||||
if (eventType === 'change') {
|
this.watcher.close(); // Close existing watcher if any
|
||||||
|
}
|
||||||
|
|
||||||
|
this.watcher = chokidar.watch(filePaths, {
|
||||||
|
persistent: true,
|
||||||
|
ignoreInitial: true, // Ignore initial 'add' events
|
||||||
|
});
|
||||||
|
|
||||||
|
this.watcher
|
||||||
|
.on('change', (filePath) => {
|
||||||
log.debug(`File changed: ${filePath}`);
|
log.debug(`File changed: ${filePath}`);
|
||||||
this.loadFileToCache(filePath);
|
this.loadFileToCache(filePath);
|
||||||
log.debug(`Reload the file ${filePath} into cache`);
|
log.debug(`Reloaded file ${filePath} into cache`);
|
||||||
}
|
})
|
||||||
});
|
.on('error', (error) => {
|
||||||
}
|
log.error(`Watcher error: ${error.message}`);
|
||||||
|
});
|
||||||
// Function to watch all files for changes
|
|
||||||
watchFiles(filePaths) {
|
|
||||||
filePaths.forEach((filePath) => this.watchFileForChanges(filePath));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to inject dynamic data (e.g., OG, TITLE, etc.) into a given file
|
// Function to inject dynamic data (e.g., OG, TITLE, etc.) into a given file
|
||||||
@@ -90,6 +99,13 @@ class HtmlInjector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup watcher when the instance is no longer needed
|
||||||
|
cleanup() {
|
||||||
|
if (this.watcher) {
|
||||||
|
this.watcher.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = HtmlInjector;
|
module.exports = HtmlInjector;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ prod dependencies: {
|
|||||||
@mattermost/client : https://www.npmjs.com/package/@mattermost/client
|
@mattermost/client : https://www.npmjs.com/package/@mattermost/client
|
||||||
@sentry/node : https://www.npmjs.com/package/@sentry/node
|
@sentry/node : https://www.npmjs.com/package/@sentry/node
|
||||||
axios : https://www.npmjs.com/package/axios
|
axios : https://www.npmjs.com/package/axios
|
||||||
|
chokidar : https://www.npmjs.com/package/chokidar
|
||||||
colors : https://www.npmjs.com/package/colors
|
colors : https://www.npmjs.com/package/colors
|
||||||
compression : https://www.npmjs.com/package/compression
|
compression : https://www.npmjs.com/package/compression
|
||||||
cors : https://www.npmjs.com/package/cors
|
cors : https://www.npmjs.com/package/cors
|
||||||
@@ -58,7 +59,7 @@ dev dependencies: {
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.87
|
* @version 1.7.88
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -1315,7 +1316,7 @@ function startServer() {
|
|||||||
const tunnel = list.tunnels[0].public_url;
|
const tunnel = list.tunnels[0].public_url;
|
||||||
log.info('Server config', getServerConfig(tunnel));
|
log.info('Server config', getServerConfig(tunnel));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error('Ngrok Start error: ', err.body);
|
log.error('Ngrok Start error: ', err);
|
||||||
await ngrok.kill();
|
await ngrok.kill();
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@@ -3555,3 +3556,13 @@ function startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
process.on('SIGINT', () => {
|
||||||
|
htmlInjector.cleanup();
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('SIGTERM', () => {
|
||||||
|
htmlInjector.cleanup();
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mirotalksfu",
|
"name": "mirotalksfu",
|
||||||
"version": "1.7.87",
|
"version": "1.7.88",
|
||||||
"description": "WebRTC SFU browser-based video calls",
|
"description": "WebRTC SFU browser-based video calls",
|
||||||
"main": "Server.js",
|
"main": "Server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -60,6 +60,7 @@
|
|||||||
"@mattermost/client": "10.6.0",
|
"@mattermost/client": "10.6.0",
|
||||||
"@sentry/node": "^9.8.0",
|
"@sentry/node": "^9.8.0",
|
||||||
"axios": "^1.8.4",
|
"axios": "^1.8.4",
|
||||||
|
"chokidar": "^4.0.3",
|
||||||
"colors": "1.4.0",
|
"colors": "1.4.0",
|
||||||
"compression": "1.8.0",
|
"compression": "1.8.0",
|
||||||
"cors": "2.8.5",
|
"cors": "2.8.5",
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ let BRAND = {
|
|||||||
},
|
},
|
||||||
about: {
|
about: {
|
||||||
imageUrl: '../images/mirotalk-logo.gif',
|
imageUrl: '../images/mirotalk-logo.gif',
|
||||||
title: '<strong>WebRTC SFU v1.7.87</strong>',
|
title: '<strong>WebRTC SFU v1.7.88</strong>',
|
||||||
html: `
|
html: `
|
||||||
<button
|
<button
|
||||||
id="support-button"
|
id="support-button"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ if (location.href.substr(0, 5) !== 'https') location.href = 'https' + location.h
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.87
|
* @version 1.7.88
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -5290,7 +5290,7 @@ function showAbout() {
|
|||||||
position: 'center',
|
position: 'center',
|
||||||
imageUrl: BRAND.about?.imageUrl && BRAND.about.imageUrl.trim() !== '' ? BRAND.about.imageUrl : image.about,
|
imageUrl: BRAND.about?.imageUrl && BRAND.about.imageUrl.trim() !== '' ? BRAND.about.imageUrl : image.about,
|
||||||
customClass: { image: 'img-about' },
|
customClass: { image: 'img-about' },
|
||||||
title: BRAND.about?.title && BRAND.about.title.trim() !== '' ? BRAND.about.title : 'WebRTC SFU v1.7.87',
|
title: BRAND.about?.title && BRAND.about.title.trim() !== '' ? BRAND.about.title : 'WebRTC SFU v1.7.88',
|
||||||
html: `
|
html: `
|
||||||
<br />
|
<br />
|
||||||
<div id="about">
|
<div id="about">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
||||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.87
|
* @version 1.7.88
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم