0

I've got the following piece of code (a basic notification that is pushed if the user permits such). My final goal is to have such a notification appear everytime a certain parameter's value reaches a threshold in my project. Let's say I have a live tracker of how many people are in a certain place. If that value passes 50, push a notification. I have not found anything similar and I am unsure where to start from with this.

<script>
        function showNotification() {
          const notification = new Notification("New message form Scenwise", {
            body: "just testing if this notification works"
          })
        }

        if (Notification.permission === "granted") {
          showNotification();
        } 
        else if (Notification.permission !== "denied") {
          Notification.requestPermission().then(permission => {
            if (permission === "granted") {
              showNotification();
            }
          })
        }
</script>
 

Denxah129
  • 23
  • 6

1 Answers1

0

Assuming this parameter is a variable you're maintaining in your javascript and only your code is updating the value of this variable, you should be able implement logic every time you update its value to check if it meets your threshold, and push a notification if necessary.

If you need a more automated solution, this might be helpful to you: Listening for variable changes in JavaScript

Based1776
  • 79
  • 4