Added support for alternative messenging service.
Ylian Saint-Hilaire committed
Feb 4, 2021 at 18:37 UTC
b53867ef93ceec184afbba949df3269c15d44a22
6 files changed
+54
-1
firebase.js
+5
-1
@@ -197,7 +197,10 @@ module.exports.CreateFirebaseRelay = function (parent, url, key) {
197
obj.connectWebSocket = function () {
198
if (obj.wsclient != null) return;
199
obj.wsclient = new WebSocket(relayUrl.href + (key ? ('?key=' + key) : ''), { rejectUnauthorized: false })
200
- obj.wsclient.on('open', function () { obj.wsopen = true; });
200
+ obj.wsclient.on('open', function () {
201
+ parent.debug('email', 'FBWS-Connected');
202
+ obj.wsopen = true;
203
+ });
204
obj.wsclient.on('message', function (msg) {
205
parent.debug('email', 'FBWS-Data(' + msg.length + '): ' + msg);
206
var data = null;
@@ -214,6 +217,7 @@ module.exports.CreateFirebaseRelay = function (parent, url, key) {
217
setTimeout(obj.connectWebSocket, 2000);
218
});
219
obj.wsclient.on('close', function () {
220
+ parent.debug('email', 'FBWS-Disconnected');
221
obj.wsclient = null;
222
obj.wsopen = false;
223
setTimeout(obj.connectWebSocket, 2000);
meshcentral-config-schema.json
+9
@@ -205,6 +205,15 @@
205
"footer": { "type": "string", "default": null, "description": "This is a HTML string displayed at the bottom of the web page when a user is logged in." },
206
"loginfooter": { "type": "string", "default": null, "description": "This is a HTML string displayed at the bottom of the web page when a user is not logged in." },
207
"guestDeviceSharing": { "type": "boolean", "default": true, "description": "When set to false, the desktop/terminal sharing link feature is not available." },
208
+ "altMessenging": {
209
+ "type": "object",
210
+ "properties": {
211
+ "name": { "type": "string", "description": "Name of the alternative messaging service, for example: \"Jitsi\" " },
212
+ "url": { "type": "string", "description": "URL to the alternative messaging services, for example: \"https://meet.jit.si/myserver-{0}\"" }
213
+ },
214
+ "additionalProperties": false,
215
+ "required": [ "name", "url" ]
216
+ },
217
"certUrl": {
218
"type": "string",
219
"format": "uri",
meshuser.js
+3
@@ -459,6 +459,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
459
}
460
if (matchingDomains.length > 0) { serverinfo.amtAcmFqdn = matchingDomains; }
461
}
462
+ if ((typeof domain.altmessenging == 'object') && (typeof domain.altmessenging.name == 'string') && (typeof domain.altmessenging.url == 'string')) { serverinfo.altmessenging = { name: domain.altmessenging.name, url: domain.altmessenging.url }; }
463
serverinfo.https = true;
464
serverinfo.redirport = args.redirport;
465
@@ -2716,7 +2717,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2717
2718
// Create the notification message
2719
var notification = { action: 'msg', type: 'notify', id: Math.random(), value: command.msg, title: user.name, icon: 8, userid: user._id, username: user.name };
2720
+ if (typeof command.url == 'string') { notification.url = command.url; }
2721
if ((typeof command.maxtime == 'number') && (command.maxtime > 0)) { notification.maxtime = command.maxtime; }
2722
+ if (command.msgid == 11) { notification.value = "Chat Request, Click here to accept."; notification.msgid = 11; } // Chat request
2723
2724
// Get the list of sessions for this user
2725
var sessions = parent.wssessions[command.userid];
sample-config-advanced.json
+4
@@ -143,6 +143,10 @@
143
"_footer": "<a href='https://twitter.com/mytwitter'>Twitter</a>",
144
"_loginfooter": "This is a private server.",
145
"_certUrl": "https://192.168.2.106:443/",
146
+ "_altMessenging": {
147
+ "name": "Jitsi",
148
+ "url": "https://meet.jit.si/myserver-{0}"
149
+ },
150
"myServer": {
151
"Backup": false,
152
"Restore": false,
views/default-mobile.handlebars
+6
@@ -1358,6 +1358,7 @@
1358
if (message.id != null) { n.id = message.id; }
1359
if (message.nodeid != null) { n.nodeid = message.nodeid; }
1360
if (message.tag != null) { n.tag = message.tag; }
1361
+ if (message.url != null) { n.url = message.url; }
1362
if (message.username != null) { n.username = message.username; }
1363
if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
1364
addNotification(n);
@@ -1384,6 +1385,7 @@
1385
var n = { text: message.value, title: message.title, icon: message.icon, titleid: message.titleid, msgid: message.msgid, args: message.args };
1386
if (message.id != null) { n.id = message.id; }
1387
if (message.tag != null) { n.tag = message.tag; }
1388
+ if (message.url != null) { n.url = message.url; }
1389
if (message.username != null) { n.username = message.username; }
1390
if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
1391
addNotification(n);
@@ -5171,6 +5173,9 @@
5173
if ((n.tag != null) && n.tag.startsWith('meshmessenger/')) {
5174
safeNewWindow('/messenger?id=' + n.tag + '&title=' + encodeURIComponentEx(n.username), n.tag.split('/')[2]);
5175
notificationDelete(id);
5176
+ } else if (n.url != null) {
5177
+ safeNewWindow(n.url);
5178
+ notificationDelete(id);
5179
}
5180
}
5181
}
@@ -5273,6 +5278,7 @@
5278
}
5279
notification.id = n.id;
5280
notification.xtag = n.tag;
5281
+ notification.url = n.url;
5282
notification.nodeid = n.nodeid;
5283
notification.username = n.username;
5284
notification.onclick = function (e) { notificationSelected(e.target.id, true); }
views/default.handlebars
+27
@@ -2199,6 +2199,7 @@
2199
if (message.id != null) { n.id = message.id; }
2200
if (message.nodeid != null) { n.nodeid = message.nodeid; }
2201
if (message.tag != null) { n.tag = message.tag; }
2202
+ if (message.url != null) { n.url = message.url; }
2203
if (message.username != null) { n.username = message.username; }
2204
if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
2205
addNotification(n);
@@ -2239,6 +2240,7 @@
2240
var n = { text: message.value, title: message.title, icon: message.icon, titleid: message.titleid, msgid: message.msgid, args: message.args };
2241
if (message.id != null) { n.id = message.id; }
2242
if (message.tag != null) { n.tag = message.tag; }
2243
+ if (message.url != null) { n.url = message.url; }
2244
if (message.username != null) { n.username = message.username; }
2245
if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
2246
addNotification(n);
@@ -5978,6 +5980,7 @@
5980
if ((meshrights & 8) && ((connectivity & 1) || ((node.pmt == 1) && ((features2 & 2) != 0)))) { x += '<input type=button value="' + "Message" + '" title="' + "Display a text message on the remote device" + '" onclick=deviceMessageFunction() />'; }
5981
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="' + "Display a text message of the remote device" + '" onclick=deviceToastFunction() />'; }
5982
if ((meshrights & 8) && (connectivity & 1) || ((node.pmt == 1) && ((features2 & 2) != 0))) { x += '<input type=button value="' + "Chat" + '" title="' + "Open chat window to this computer" + '" onclick=deviceChat(event) />'; }
5983
+ if ((serverinfo != null) && (serverinfo.altmessenging != null) && (meshrights & 8) && (connectivity & 1)) { x += '<input type=button value="' + EscapeHtml(serverinfo.altmessenging.name) + '" onclick=altDeviceChat(event) />'; }
5984
if ((serverinfo.guestdevicesharing !== false) && (node.agent != null) && (node.agent.caps & 3) && (connectivity & 1) && ((meshrights & 0x80008) == 0x80008) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 0x1000) == 0))) { x += '<input type=button value="' + "Share" + '" title="' + "Create a link to share this device with a guest" + '" onclick=showShareDevice() />'; }
5985
5986
// Custom UI
@@ -6312,6 +6315,13 @@
6315
meshserver.send({ action: 'meshmessenger', nodeid: decodeURIComponent(currentNode._id) });
6316
}
6317
6318
+ function altDeviceChat(e) {
6319
+ if (xxdialogMode) return;
6320
+ var url = serverinfo.altmessenging.url.split('{0}').join(currentNode._id.split('/').join('-'));
6321
+ meshserver.send({ action: 'msg', type: 'openUrl', nodeid: currentNode._id, url: url });
6322
+ safeNewWindow(url, 'altmessenger:' + currentNode._id, 'directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=560');
6323
+ }
6324
+
6325
function deviceToggleBackground() {
6326
if (xxdialogMode) return;
6327
meshserver.send({ action: 'msg', type: 'deskBackground', nodeid: currentNode._id, op: 1 }); // Toggle desktop background image
@@ -11800,6 +11810,7 @@
11810
}
11811
11812
function userChat(e, userid, name) {
11813
+ if (xxdialogMode) return;
11814
haltEvent(e);
11815
var url = '/messenger?id=meshmessenger/' + userid + '/' + encodeURIComponentEx(userinfo._id) + '&title=' + name;
11816
if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
@@ -11808,6 +11819,15 @@
11819
return false;
11820
}
11821
11822
+ function altUserChat(e, userid, name) {
11823
+ if (xxdialogMode) return;
11824
+ haltEvent(e);
11825
+ var url = serverinfo.altmessenging.url.split('{0}').join(userid.split('/').join('-'));
11826
+ safeNewWindow(url, 'altmessenger:' + userid);
11827
+ meshserver.send({ action: 'notifyuser', userid: decodeURIComponent(userid), msg: serverinfo.altmessenging.name, msgid: 11, url: url });
11828
+ return false;
11829
+ }
11830
+
11831
function showSendSMS(userid) {
11832
if (xxdialogMode) return;
11833
setDialogMode(2, "Send SMS", 3, showSendSMSEx, '<textarea id=d2smsText maxlength=160 style=background-color:#fcf3cf;width:100%;height:100px;resize:none onKeyUp=showSendSMSValidate()></textarea><span style=font-size:10px><span>', userid);
@@ -12712,6 +12732,7 @@
12732
if (!self && (activeSessions > 0)) {
12733
x += '<input type=button value="' + "Notify" + '" title="' + "Send user notification" + '" onclick=showUserAlertDialog(event,"' + encodeURIComponentEx(user._id) + '") />';
12734
x += '<input type=button value="' + "Chat" + '" title="' + "Chat" + '" onclick=userChat(event,"' + encodeURIComponentEx(user._id) + '","' + encodeURIComponentEx(user.name) + '") />';
12735
+ if ((serverinfo != null) && (serverinfo.altmessenging != null)) { x += '<input type=button value="' + EscapeHtml(serverinfo.altmessenging.name) + '" onclick=altUserChat(event,"' + encodeURIComponentEx(user._id) + '","' + encodeURIComponentEx(user.name) + '") />'; }
12736
}
12737
12738
// Setup the panel
@@ -13351,6 +13372,7 @@
13372
}
13373
13374
function notificationSelectedEx(n, id) {
13375
+ console.log(n);
13376
if (n.nodeid != null) {
13377
if (n.tag == 'desktop') gotoDevice(n.nodeid, 12); // Desktop
13378
else if (n.tag == 'terminal') gotoDevice(n.nodeid, 11); // Terminal
@@ -13362,6 +13384,9 @@
13384
if ((n.tag != null) && n.tag.startsWith('meshmessenger/')) {
13385
safeNewWindow('/messenger?id=' + n.tag + '&title=' + encodeURIComponentEx(n.username), n.tag.split('/')[2]);
13386
notificationDelete(id);
13387
+ } else if (n.url != null) {
13388
+ safeNewWindow(n.url);
13389
+ notificationDelete(id);
13390
}
13391
}
13392
}
@@ -13389,6 +13414,7 @@
13414
13415
// Add a new notification and play the notification sound
13416
function addNotification(n) {
13417
+ console.log('addNotification', n);
13418
// Perform message translation
13419
var translatedTitles = [
13420
null,
@@ -13464,6 +13490,7 @@
13490
}
13491
notification.id = n.id;
13492
notification.xtag = n.tag;
13493
+ notification.url = n.url;
13494
notification.nodeid = n.nodeid;
13495
notification.username = n.username;
13496
notification.onclick = function (e) { notificationSelected(e.target.id, true); }