Added browser notification support to MeshMessenger

This commit is contained in:
Ylian Saint-Hilaire 2019-09-26 12:58:35 -07:00
parent 465d5345cb
commit d511e431ea
7 changed files with 53 additions and 3 deletions

View File

@ -263,6 +263,7 @@
<Content Include="public\styles\font-awesome\scss\_screen-reader.scss" />
<Content Include="public\styles\font-awesome\scss\_stacked.scss" />
<Content Include="public\styles\font-awesome\scss\_variables.scss" />
<Content Include="public\styles\messenger.css" />
<Content Include="public\styles\style.css" />
<Content Include="readme.md" />
<Content Include="sample-config.json" />

View File

@ -2847,7 +2847,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
var smesh = command.meshid.split('/');
if ((smesh.length != 3) || (smesh[0] != 'mesh') || (smesh[1] != domain.id)) { err = 'Invalid group id'; }
var serverName = parent.getWebServerName(domain);
if (parent.args.lanonly == true) { err = 'Server has not fixed IP or DNS name.'; }
// Handle any errors
if (err != null) {
@ -2865,6 +2864,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
var xdomain = (domain.dns == null) ? domain.id : '';
if (xdomain != '') xdomain += "/";
var url = "http" + (args.notls ? '' : 's') + "://" + serverName + ":" + httpsPort + "/" + xdomain + "agentinvite?c=" + inviteCookie;
if (serverName.split('.') == 1) { url = "/" + xdomain + "agentinvite?c=" + inviteCookie; }
ws.send(JSON.stringify({ action: 'createInviteLink', meshid: command.meshid, url: url, expire: command.expire, cookie: inviteCookie, responseid: command.responseid, tag: command.tag }));
break;

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.4.1-i",
"version": "0.4.1-j",
"keywords": [
"Remote Management",
"Intel AMT",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -104,6 +104,21 @@
background-color: orange;
}
.icon12 {
background: url(../images/messenger32.png) -352px 0px;
background-color: gray;
}
.icon13 {
background: url(../images/messenger32.png) -384px 0px;
background-color: gray;
}
.icon14 {
background: url(../images/messenger32.png) -416px 0px;
background-color: gray;
}
.fileicon {
background: url(../images/messenger32.png) -96px 0px;
height: 32px;

File diff suppressed because one or more lines are too long

View File

@ -12,6 +12,7 @@
</head>
<body style="font-family:Arial,Helvetica,sans-serif">
<div id="xtop" style="position:absolute;left:0;right:0;top:0;height:38px;background-color:#036;color:#c8c8c8;box-shadow:3px 3px 10px gray">
<div id="notifyButton" class="icon13 topButton" style="margin-right:4px" title="Enable browser notification" onclick="enableNotificationsButtonClick()"></div>
<div id="fileButton" class="icon4 topButton" title="Share a file" style="display:none" onclick="fileButtonClick()"></div>
<div id="camButton" class="icon2 topButton" title="Activate camera & microphone" style="display:none" onclick="camButtonClick()"></div>
<div id="micButton" class="icon6 topButton" title="Activate microphone" style="display:none" onclick="micButtonClick()"></div>
@ -52,6 +53,7 @@
var remoteStream = null;
var multiWebRtc = true; // if set to true, multiple WebRTC sessions will be setup. If false, everything uses one session.
var userMediaSupport = 0;
var notification = null;
getUserMediaSupport(function (x) { userMediaSupport = x; })
var webrtcconfiguration = "{{{webrtconfig}}}";
if (webrtcconfiguration == '') { webrtcconfiguration = null; } else { try { webrtcconfiguration = JSON.parse(decodeURIComponent(webrtcconfiguration)); } catch (ex) { console.log('Invalid WebRTC config: \"' + webrtcconfiguration + '\".'); webrtcconfiguration = null; } }
@ -65,13 +67,23 @@
// Set the title
if (args.title) { QH('xtitle', ' - ' + args.title); document.title = document.title + ' - ' + args.title; }
// Setup web notifications
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
// Listen to drag & drop events
document.addEventListener('dragover', haltEvent, false);
document.addEventListener('dragleave', haltEvent, false);
document.addEventListener('drop', fileDrop, false);
document.onclick = function (e) {
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (notification != null) { notification.close(); notification = null; }
}
// Trap document key up events
document.onkeyup = function ondockeypress(e) {
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (notification != null) { notification.close(); notification = null; }
if (state == 2) {
if ((e.keyCode == 8) && (userInputFocus == 0)) {
// Backspace
@ -84,6 +96,8 @@
// Trap document key presses
document.onkeypress = function ondockeypress(e) {
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (notification != null) { notification.close(); notification = null; }
if (state == 2) {
if (e.keyCode == 13) {
// Return
@ -148,10 +162,23 @@
function displayRemote(msg) {
QA('xmsg', '<div style="clear:both"><div class="remoteBubble">' + msg + '</div><div></div></div>');
Q('xmsg').scrollTop = Q('xmsg').scrollHeight;
// If web notifications are granted, use it.
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
if (Notification && (Notification.permission == "granted")) {
if (notification != null) { notification.close(); notification = null; }
if (args.title) {
notification = new Notification("MeshMessenger - " + args.title, { body: msg });
} else {
notification = new Notification("MeshMessenger", { body: msg });
}
}
}
// Display and send a message from the local user
function xsend(event) {
if (notification != null) { notification.close(); notification = null; }
if (Notification) { QV('notifyButton', Notification.permission != 'granted'); }
var outtext = Q('xouttext').value;
if (outtext.length > 0) {
Q('xouttext').value = '';
@ -486,6 +513,12 @@
send({ action: 'fileUploadAck', id: msg.id });
}
// Toggle notification
function enableNotificationsButtonClick() {
if (Notification) { Notification.requestPermission().then(function (permission) { QV('notifyButton', permission != "granted"); }); }
return false;
}
// Camera button
function camButtonClick() {
if (localStream == null) { startLocalStream({ video: true, audio: true }); }
@ -603,6 +636,7 @@
if (webchannel != null) { try { webchannel.close(); } catch (e) { } webchannel = null; }
if (socket != null) { try { socket.close(); } catch (e) { } socket = null; }
}
</script>
</body>
</html>