Browser-Phone icon indicating copy to clipboard operation
Browser-Phone copied to clipboard

remove browser notification when call ended

Open ArminXG opened this issue 2 years ago • 0 comments

If browser notifications are activated/allowes, the notification for an incoming call is shown even after the call ended, was rejected or canceled. The patch below clears the notification in these cases.

Also, when using Chrome the notification box always includes the URL, which is nice but causes problems. If the user clicks on this URL, a new window of the phone is opened and causes the original one to be offline. Any ides how to remove the URL from this notification? And maybe it is possible to have this notification with two buttons: Accept and Reject.

--- phone.js.bak	2023-01-23 15:04:56.022496589 +0100
+++ phone.js	2023-01-23 15:08:05.250246346 +0100
@@ -2403,6 +2403,7 @@
         if (Notification.permission === "granted") {
             var noticeOptions = { body: lang.incoming_call_from +" " + callerID +" <"+ did +">", icon: getPicture(buddyObj.identity) }
             var inComingCallNotification = new Notification(lang.incoming_call, noticeOptions);
+            lineObj.Notification = inComingCallNotification;
             inComingCallNotification.onclick = function (event) {
 
                 var lineNo = lineObj.LineNumber;
@@ -2504,6 +2505,10 @@
     // Update UI
     $("#line-" + lineObj.LineNumber + "-AnswerCall").hide();
 
+    if(lineObj.Notification){
+        lineObj.Notification.close();
+    }
+
     // Start SIP handling
     var supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
     var spdOptions = {
@@ -2587,6 +2592,10 @@
     // Update UI
     $("#line-" + lineObj.LineNumber + "-AnswerCall").hide();
 
+    if(lineObj.Notification){
+        lineObj.Notification.close();
+    }
+
     // Start SIP handling
     var supportedConstraints = navigator.mediaDevices.getSupportedConstraints();
     var spdOptions = {
@@ -2701,6 +2710,10 @@
     }
     $("#line-" + lineObj.LineNumber + "-msg").html(lang.call_rejected);
 
+    if(lineObj.Notification){
+        lineObj.Notification.close();
+    }
+
     session.data.terminateby = "us";
     session.data.reasonCode = 486;
     session.data.reasonText = "Busy Here";
@@ -2740,6 +2753,10 @@
             console.log("Call completed elsewhere before answer");
         }
 
+        if(lineObj.Notification){
+            lineObj.Notification.close();
+        }
+
         lineObj.SipSession.dispose().catch(function(error){
             console.log("Failed to dispose the cancel dialog", error);
         })
@@ -8332,6 +8349,7 @@
     this.SipSession = null;
     this.LocalSoundMeter = null;
     this.RemoteSoundMeter = null;
+    this.Notification = null;
 }
 function ShowDial(){
     CloseUpSettings();

ArminXG avatar Jan 24 '23 14:01 ArminXG