\ No newline at end of file
diff --git a/views/messenger.handlebars b/views/messenger.handlebars
index 0ea4f482..5ee4aac5 100644
--- a/views/messenger.handlebars
+++ b/views/messenger.handlebars
@@ -12,6 +12,7 @@
+
@@ -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', '
' + msg + '
');
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; }
}
+