[mirotalksfu] - welcome cloudron.io, add email notify/alerts, update dep

هذا الالتزام موجود في:
Miroslav Pejic
2024-04-16 14:33:17 +02:00
الأصل 1514f74267
التزام 298837abce
9 ملفات معدلة مع 173 إضافات و6 حذوفات

عرض الملف

@@ -41,7 +41,7 @@ dependencies: {
* @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
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.4.18
* @version 1.4.19
*
*/
@@ -73,6 +73,9 @@ const { CaptureConsole } = require('@sentry/integrations');
const restrictAccessByIP = require('./middleware/IpWhitelist.js');
const packageJson = require('../../package.json');
// Email alerts and notifications
const nodemailer = require('./lib/nodemailer');
// Slack API
const CryptoJS = require('crypto-js');
const qS = require('qs');
@@ -1015,6 +1018,11 @@ function startServer() {
return cb('isLobby');
}
// SCENARIO: Notify when the first user join room and is awaiting assistance...
if (room.getPeersCount() === 1) {
nodemailer.sendEmailAlert('join', { peer_name: peer_name, room_id: room.id }); // config.email.alert: true
}
cb(room.toJson());
});

عرض الملف

@@ -107,6 +107,19 @@ module.exports = {
],
join_first: true, // Set to true for traditional behavior, false to prioritize presenters
},
email: {
/*
Configure email settings for notifications or alerts
Refer to the documentation for Gmail configuration: https://support.google.com/mail/answer/185833?hl=en
*/
alert: false,
host: 'smtp.gmail.com',
port: 587,
username: 'your_username',
password: 'your_password',
sendTo: 'sfu.mirotalk@gmail.com',
domain: 'sfu.mirotalk.com',
},
ui: {
/*
Customize your MiroTalk instance

134
app/src/lib/nodemailer.js Normal file
عرض الملف

@@ -0,0 +1,134 @@
'use-strict';
const nodemailer = require('nodemailer');
const config = require('../config');
const Logger = require('../Logger');
const log = new Logger('NodeMailer');
// ####################################################
// EMAIL CONFIG
// ####################################################
const EMAIL_HOST = config.email ? config.email.host : false;
const EMAIL_PORT = config.email ? config.email.port : false;
const EMAIL_USERNAME = config.email ? config.email.username : false;
const EMAIL_PASSWORD = config.email ? config.email.password : false;
const EMAIL_SEND_TO = config.email ? config.email.sendTo : false;
const EMAIL_ALERT = config.email ? config.email.alert : false;
const DOMAIN = config.email ? config.email.domain : 'sfu.mirotlalk.com';
const ROOM_URL = `https://${DOMAIN}/join/`;
log.info('Email', {
alert: EMAIL_ALERT,
host: EMAIL_HOST,
port: EMAIL_PORT,
username: EMAIL_USERNAME,
password: EMAIL_PASSWORD,
});
const transport = nodemailer.createTransport({
host: EMAIL_HOST,
port: EMAIL_PORT,
auth: {
user: EMAIL_USERNAME,
pass: EMAIL_PASSWORD,
},
});
// ####################################################
// EMAIL SEND ALERTS AND NOTIFICATIONS
// ####################################################
function sendEmailAlert(event, data) {
if (!EMAIL_ALERT || !EMAIL_HOST || !EMAIL_PORT || !EMAIL_USERNAME || !EMAIL_PASSWORD || !EMAIL_SEND_TO) return;
log.info('sendEMailAlert', {
event: event,
data: data,
});
let subject = false;
let body = false;
switch (event) {
case 'join':
const { peer_name, room_id } = data;
subject = getJoinRoomSubject(room_id);
body = getJoinRoomBody(peer_name, room_id);
break;
// ...
default:
break;
}
if (subject && body) sendEmail(subject, body);
}
function sendEmail(subject, body) {
transport
.sendMail({
from: EMAIL_USERNAME,
to: EMAIL_SEND_TO,
subject: subject,
html: body,
})
.catch((err) => log.error(err));
}
// ####################################################
// EMAIL TEMPLATES
// ####################################################
function getJoinRoomSubject(room_id) {
return `MiroTalk SFU - New user Join to Room ${room_id}`;
}
function getJoinRoomBody(peer_name, room_id) {
const currentDataTime = getCurrentDataTime();
return `
<h1>New user join</h1>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
<table>
<tr>
<td>User</td>
<td>${peer_name}</td>
</tr>
<tr>
<td>Room</td>
<td>${ROOM_URL}${room_id}</td>
</tr>
<tr>
<td>Time</td>
<td>${currentDataTime}</td>
</tr>
</table>
`;
}
// ####################################################
// UTILITY
// ####################################################
function getCurrentDataTime() {
const currentTime = new Date().toLocaleString('en-US', log.tzOptions);
const milliseconds = String(new Date().getMilliseconds()).padStart(3, '0');
return `${currentTime}:${milliseconds}`;
}
module.exports = {
sendEmailAlert,
};