[mirotalksfu] - #115 Added the ability to enable or disable stats from the config.js file

هذا الالتزام موجود في:
Miroslav Pejic
2023-08-01 08:52:58 +02:00
الأصل e983a371d2
التزام e2c97a01bc
4 ملفات معدلة مع 47 إضافات و7 حذوفات

عرض الملف

@@ -124,6 +124,13 @@ if (sentryEnabled) {
*/ */
} }
// Stats
const defaultStats = {
enabled: true,
src: 'https://stats.mirotalk.com/script.js',
id: '41d26670-f275-45bb-af82-3ce91fe57756',
};
// OpenAI/ChatGPT // OpenAI/ChatGPT
let chatGPT; let chatGPT;
if (config.chatGPT.enabled) { if (config.chatGPT.enabled) {
@@ -319,6 +326,13 @@ function startServer() {
res.sendFile(views.about); res.sendFile(views.about);
}); });
// Get stats endpoint
app.get(['/stats'], (req, res) => {
const stats = config.stats ? config.stats : defaultStats;
// log.debug('Send stats', stats);
res.send(stats);
});
// #################################################### // ####################################################
// API // API
// #################################################### // ####################################################

عرض الملف

@@ -117,6 +117,15 @@ module.exports = {
enabled: false, enabled: false,
url: '', url: '',
}, },
stats: {
/*
Umami: https://github.com/umami-software/umami
We use Umami to track aggregated usage statistics in order to improve our service.
*/
enabled: true,
src: 'https://stats.mirotalk.com/script.js',
id: '41d26670-f275-45bb-af82-3ce91fe57756',
},
mediasoup: { mediasoup: {
// Worker settings // Worker settings
numWorkers: Object.keys(os.cpus()).length, numWorkers: Object.keys(os.cpus()).length,

عرض الملف

@@ -1,9 +1,26 @@
'use strict'; 'use strict';
// https://github.com/mikecao/umami // const url = 'https://localhost:3010/stats';
const url = 'https://sfu.mirotalk.com/stats';
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => {
// console.log('STATS', data);
const { enabled, src, id } = data;
if (enabled) {
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('async', ''); script.setAttribute('async', '');
script.setAttribute('src', 'https://stats.mirotalk.com/script.js'); script.setAttribute('src', src);
script.setAttribute('data-website-id', '41d26670-f275-45bb-af82-3ce91fe57756'); script.setAttribute('data-website-id', id);
document.head.appendChild(script); document.head.appendChild(script);
}
})
.catch((error) => {
console.error('Stats fetch error:', error);
});