[mirotalk] - refactoring
This commit is contained in:
+30
-27
@@ -4,35 +4,37 @@ const nodemailer = require('nodemailer');
|
||||
const Logs = require('../logs');
|
||||
const log = new Logs('NodeMailer');
|
||||
|
||||
const HTTPS = process.env.HTTPS === 'true' || false;
|
||||
const LOCAL_PORT = process.env.PORT || 3000;
|
||||
|
||||
const EMAIL_HOST = process.env.EMAIL_HOST;
|
||||
const EMAIL_PORT = process.env.EMAIL_PORT;
|
||||
const EMAIL_USERNAME = process.env.EMAIL_USERNAME;
|
||||
const EMAIL_PASSWORD = process.env.EMAIL_PASSWORD;
|
||||
const EMAIL_SEND_TO = process.env.EMAIL_SEND_TO;
|
||||
const EMAIL_ALERT = process.env.EMAIL_ALERT === 'true' || false;
|
||||
|
||||
if (EMAIL_ALERT && EMAIL_HOST && EMAIL_PORT && EMAIL_USERNAME && EMAIL_PASSWORD && EMAIL_SEND_TO) {
|
||||
log.info('Email', {
|
||||
alert: EMAIL_ALERT,
|
||||
host: EMAIL_HOST,
|
||||
port: EMAIL_PORT,
|
||||
username: EMAIL_USERNAME,
|
||||
password: EMAIL_PASSWORD,
|
||||
});
|
||||
}
|
||||
// Email config
|
||||
const emailCfg = {
|
||||
alert: process.env.EMAIL_ALERT === 'true' || false,
|
||||
host: process.env.EMAIL_HOST,
|
||||
port: process.env.EMAIL_PORT,
|
||||
username: process.env.EMAIL_USERNAME,
|
||||
password: process.env.EMAIL_PASSWORD,
|
||||
send_to: process.env.EMAIL_SEND_TO,
|
||||
// Room join params
|
||||
https: process.env.HTTPS === 'true' || false,
|
||||
server_port: process.env.PORT || 3000,
|
||||
};
|
||||
|
||||
const transport = nodemailer.createTransport({
|
||||
host: EMAIL_HOST,
|
||||
port: EMAIL_PORT,
|
||||
host: emailCfg.host,
|
||||
port: emailCfg.port,
|
||||
auth: {
|
||||
user: EMAIL_USERNAME,
|
||||
pass: EMAIL_PASSWORD,
|
||||
user: emailCfg.username,
|
||||
pass: emailCfg.password,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if passed config is valid
|
||||
* @param {object} config
|
||||
* @returns bool
|
||||
*/
|
||||
function isConfigValid(config) {
|
||||
return config.alert && config.host && config.port && config.username && config.password && config.send_to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Email alert or notification from event
|
||||
* @param {string} event
|
||||
@@ -40,7 +42,7 @@ const transport = nodemailer.createTransport({
|
||||
* @returns void
|
||||
*/
|
||||
function sendEmailAlert(event, data) {
|
||||
if (!EMAIL_ALERT || !EMAIL_HOST || !EMAIL_PORT || !EMAIL_USERNAME || !EMAIL_PASSWORD || !EMAIL_SEND_TO) return;
|
||||
if (!isConfigValid(emailCfg)) return;
|
||||
|
||||
log.info('sendEMailAlert', {
|
||||
event: event,
|
||||
@@ -71,8 +73,8 @@ function sendEmailAlert(event, data) {
|
||||
function sendEmail(subject, body) {
|
||||
transport
|
||||
.sendMail({
|
||||
from: EMAIL_USERNAME,
|
||||
to: EMAIL_SEND_TO,
|
||||
from: emailCfg.username,
|
||||
to: emailCfg.send_to,
|
||||
subject: subject,
|
||||
html: body,
|
||||
})
|
||||
@@ -102,7 +104,7 @@ function getJoinRoomBody(data) {
|
||||
const localDomains = ['localhost', '127.0.0.1'];
|
||||
|
||||
const currentDomain = localDomains.some((localDomain) => domain.includes(localDomain))
|
||||
? `${HTTPS ? 'https' : 'http'}://${domain}:${LOCAL_PORT}`
|
||||
? `${emailCfg.https ? 'https' : 'http'}://${domain}:${emailCfg.server_port}`
|
||||
: domain;
|
||||
|
||||
const room_join = `${currentDomain}/join/`;
|
||||
@@ -161,4 +163,5 @@ function getCurrentDataTime() {
|
||||
|
||||
module.exports = {
|
||||
sendEmailAlert,
|
||||
emailCfg,
|
||||
};
|
||||
|
||||
+11
-24
@@ -9,32 +9,15 @@ const Logger = require('./logs');
|
||||
const log = new Logger('Mattermost');
|
||||
|
||||
class mattermost {
|
||||
constructor(app) {
|
||||
const {
|
||||
MATTERMOST_ENABLED,
|
||||
MATTERMOST_TOKEN,
|
||||
MATTERMOST_SERVER_URL,
|
||||
MATTERMOST_USERNAME,
|
||||
MATTERMOST_PASSWORD,
|
||||
API_DISABLED,
|
||||
} = process.env;
|
||||
|
||||
log.debug('Mattermost config', {
|
||||
enabled: MATTERMOST_ENABLED,
|
||||
token: MATTERMOST_TOKEN,
|
||||
server: MATTERMOST_SERVER_URL,
|
||||
username: MATTERMOST_USERNAME,
|
||||
password: MATTERMOST_PASSWORD,
|
||||
});
|
||||
|
||||
if (MATTERMOST_ENABLED !== 'true') return;
|
||||
constructor(app, mattermostCfg) {
|
||||
if (!this.isConfigValid(mattermostCfg)) return;
|
||||
|
||||
this.app = app;
|
||||
this.disabled = JSON.parse(API_DISABLED);
|
||||
this.token = MATTERMOST_TOKEN;
|
||||
this.serverUrl = MATTERMOST_SERVER_URL;
|
||||
this.username = MATTERMOST_USERNAME;
|
||||
this.password = MATTERMOST_PASSWORD;
|
||||
this.disabled = mattermostCfg.api_disabled;
|
||||
this.token = mattermostCfg.token;
|
||||
this.serverUrl = mattermostCfg.server_url;
|
||||
this.username = mattermostCfg.username;
|
||||
this.password = mattermostCfg.password;
|
||||
|
||||
this.client = new Client4();
|
||||
this.client.setUrl(this.serverUrl);
|
||||
@@ -42,6 +25,10 @@ class mattermost {
|
||||
this.setupEventHandlers();
|
||||
}
|
||||
|
||||
isConfigValid(config) {
|
||||
return config.enabled && config.server_url && config.token && config.username && config.password;
|
||||
}
|
||||
|
||||
async authenticate() {
|
||||
try {
|
||||
const user = await this.client.login(this.username, this.password);
|
||||
|
||||
+52
-24
@@ -11,7 +11,6 @@ dependencies: {
|
||||
@mattermost/client : https://www.npmjs.com/package/@mattermost/client
|
||||
@sentry/node : https://www.npmjs.com/package/@sentry/node
|
||||
axios : https://www.npmjs.com/package/axios
|
||||
body-parser : https://www.npmjs.com/package/body-parser
|
||||
compression : https://www.npmjs.com/package/compression
|
||||
colors : https://www.npmjs.com/package/colors
|
||||
cors : https://www.npmjs.com/package/cors
|
||||
@@ -40,7 +39,7 @@ dependencies: {
|
||||
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.3.83
|
||||
* @version 1.3.84
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -273,6 +272,16 @@ if (configChatGPT.enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
// Mattermost config
|
||||
const mattermostCfg = {
|
||||
enabled: process.env.MATTERMOST_ENABLED === 'true' || false,
|
||||
server_url: process.env.MATTERMOST_SERVER_URL,
|
||||
username: process.env.MATTERMOST_USERNAME,
|
||||
password: process.env.MATTERMOST_PASSWORD,
|
||||
token: process.env.MATTERMOST_TOKEN,
|
||||
api_disabled: api_disabled,
|
||||
};
|
||||
|
||||
// IP Whitelist
|
||||
const ipWhitelist = {
|
||||
enabled: getEnvBoolean(process.env.IP_WHITELIST_ENABLED),
|
||||
@@ -393,7 +402,7 @@ app.use((req, res, next) => {
|
||||
});
|
||||
|
||||
// Mattermost
|
||||
const mattermost = new mattermostCli(app);
|
||||
const mattermost = new mattermostCli(app, mattermostCfg);
|
||||
|
||||
// POST start from here...
|
||||
app.post('*', function (next) {
|
||||
@@ -849,35 +858,54 @@ app.get('*', function (req, res) {
|
||||
*/
|
||||
function getServerConfig(tunnel = false) {
|
||||
return {
|
||||
iceServers: iceServers,
|
||||
stats: statsData,
|
||||
oidc: OIDC.enabled ? OIDC : false,
|
||||
host: hostCfg,
|
||||
jwtCfg: jwtCfg,
|
||||
presenters: roomPresenters,
|
||||
ip_whitelist: ipWhitelist,
|
||||
ngrok: {
|
||||
ngrok_enabled: ngrokEnabled,
|
||||
ngrok_token: ngrokEnabled ? ngrokAuthToken : '',
|
||||
},
|
||||
cors: corsOptions,
|
||||
server_tunnel: tunnel,
|
||||
// General Server Information
|
||||
server: host,
|
||||
test_ice_servers: testStunTurn,
|
||||
server_tunnel: tunnel,
|
||||
api_docs: api_docs,
|
||||
|
||||
// Core Configurations
|
||||
jwtCfg: jwtCfg,
|
||||
cors: corsOptions,
|
||||
iceServers: iceServers,
|
||||
test_ice_servers: testStunTurn,
|
||||
email: nodemailer.emailCfg.alert ? nodemailer.emailCfg : false,
|
||||
|
||||
// Security, Authorization, and User Management
|
||||
oidc: OIDC.enabled ? OIDC : false,
|
||||
host_protected: hostCfg.protected || hostCfg.user_auth ? hostCfg : false,
|
||||
presenters: roomPresenters,
|
||||
ip_whitelist: ipWhitelist.enabled ? ipWhitelist : false,
|
||||
self_signed_certificate: isHttps,
|
||||
api_key_secret: api_key_secret,
|
||||
use_self_signed_certificate: isHttps,
|
||||
|
||||
// Media and Connection Settings
|
||||
turn_enabled: turnServerEnabled,
|
||||
ip_lookup_enabled: IPLookupEnabled,
|
||||
chatGPT_enabled: configChatGPT.enabled,
|
||||
|
||||
// Integrations
|
||||
chatGPT_enabled: configChatGPT.enabled ? configChatGPT : false,
|
||||
slack_enabled: slackEnabled,
|
||||
mattermost_enabled: mattermostCfg.enabled ? mattermostCfg : false,
|
||||
|
||||
// Monitoring and Logging
|
||||
sentry_enabled: sentryEnabled,
|
||||
survey_enabled: surveyEnabled,
|
||||
redirect_enabled: redirectEnabled,
|
||||
survey_url: surveyURL,
|
||||
redirect_url: redirectURL,
|
||||
node_version: process.versions.node,
|
||||
stats: statsData.enabled ? statsData : false,
|
||||
|
||||
// Ngrok Configuration
|
||||
ngrok: ngrokEnabled
|
||||
? {
|
||||
enabled: ngrokEnabled,
|
||||
token: ngrokAuthToken,
|
||||
}
|
||||
: false,
|
||||
|
||||
// URLs for Redirection and Survey
|
||||
survey: surveyEnabled ? surveyURL : false,
|
||||
redirect: redirectEnabled ? redirectURL : false,
|
||||
|
||||
// Versions information
|
||||
app_version: packageJson.version,
|
||||
node_version: process.versions.node,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mirotalk",
|
||||
"version": "1.3.83",
|
||||
"version": "1.3.84",
|
||||
"description": "A free WebRTC browser-based video call",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.3.83
|
||||
* @version 1.3.84
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -10569,7 +10569,7 @@ function showAbout() {
|
||||
Swal.fire({
|
||||
background: swBg,
|
||||
position: 'center',
|
||||
title: '<strong>WebRTC P2P v1.3.83</strong>',
|
||||
title: '<strong>WebRTC P2P v1.3.84</strong>',
|
||||
imageAlt: 'mirotalk-about',
|
||||
imageUrl: images.about,
|
||||
customClass: { image: 'img-about' },
|
||||
|
||||
Reference in New Issue
Block a user