Enhance your Meteor web application with desktop notifications that include icons and audio features

I've been attempting to incorporate a basic HTML5 desktop notification into my Meteor Web Application. Below is the code snippet I've tried:

if (!("Notification" in window)) {
        alert("This browser does not support desktop notification");
        }

        // Checking if notification permissions have been granted
       else if (Notification.permission === "granted") {
            var date = new Date();
            var audio = new Audio();
            audio.src = "../../../universal/bells.wav";
            audio.load();
            audio.play();
            var notification = new Notification("Allow Notifications!", {
                              dir: "auto",
                              lang: "hi",
                              tag: "testTag"+date.getTime(),
                              icon: "../../../assets/notification.png",
                              });
          }

        // Asking for permission if not granted or denied
        else if (Notification.permission !== 'denied') {
          Notification.requestPermission(function (permission) {
          if (permission === "granted") {
            var notification = new Notification("Granted Permission for Notifications");
          }
      });
      }

However, both the audio and image are not showing up. Regarding the audio files, I'm receiving this error message:

"Uncaught (in promise) DOMException: Failed to load because no supported source was found."

If I disable the audio section of the code, I encounter an error related to the image icon:

"Refused to load the image '' because it violates the following Content Security Policy directive: "img-src data: 'self' http://.googleapis.com https://.googleapis.com http://.gstatic.com https://.gstatic.com http://.bootstrapcdn.com https://.bootstrapcdn.com"."

Is there an alternative method to implement desktop notifications in a Meteor App? Additionally, can notifications be positioned at the center of the page?

Answer №1

Great news! I figured out the answer to our problem. In meteor, all media files must be located in the public folder in order to be accessed!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process of exporting the app object in Express?

My application object is initialized in the app.js file: var app = express(); var reg = require('./routes/reg'); app.use('/reg',reg); ... ... module.exports = app; In reg.js, I use app.get(): var app = require("../app.js"); ... ... a ...

The functionality to rename a label by clicking on an image button is currently malfunctioning

There seems to be an issue with this code where the label name is not changing as expected when clicking the image button. I have noticed that upon closer inspection, the label does change momentarily but then reverts back to its original value immediatel ...

Preserving state values with the useState hook throughout various function invocations

When I click the button to delete department rows from my table, I am using the "deleteDepartment" function. The issue arises when trying to get the selected row index in the "selectedRows" hook. It seems that the "rowSelection" state keeps accumulating va ...

Guide on sending files through an API request with formData() using Vuejs and Axios

My goal is to utilize an API to upload a file to the server. The documentation on documenter.getpostman outlines how to use the API: --form 'type="1"' \ --form 'user_id="1"' \ --form 'file=@"/C:/U ...

Can you retrieve functional context from a class component in react-native?

In my current react-native project version 0.63.2, I am implementing @react-navigation-5 for navigation. The navigation flow includes transition from the splash screen to the login screen and then to the tab screen all done using context. appContext.js im ...

What causes the disappearance of an entire component's code?

Can someone please explain what just happened here? Is it a problem with VS Code or is it a hardware issue? Sometimes my HDD appears to be undetected (not sure if it's due to malfunction of the HDD or something else). https://i.sstatic.net/BVCNm.png ...

Using Laravel and Inertia App to fetch data from an API endpoint

I am currently using Laravel with InertiaJS and VueJS for my App. Jetstream scaffolding is handling all the authentication tasks within the app. However, I am facing an issue with a few pages that need to access the api.php routes in my project. For examp ...

Tips for declaring a data variable in Vue with the help of APIs

I'm currently working on a project where I am integrating movie data from an API (TMDb) using Vue Routers. I have a component named 'MovieList' where I am fetching data from the API. Below is the data structure: data() { return { mov ...

Is there a way to display a particular HTML document in one frame while currently being in another frame?

I am trying to set up frames within a frameset, with the following structure: <frameset rows="75%,25%"> <frameset cols="20%,80%"> <frame src="TreeGroup.jsp" name="left" id="f1"/> <frame src="DisplayMap.jsp" name= ...

Encountering 404 Errors while Attempting to Reach API Endpoint in an Express.js Application Hosted on cPanel

I have a Node.js application running on cPanel, and I'm facing 404 errors when trying to access an API endpoint within my app. Let me provide you with the setup details: Directory Structure: public_html/ server.mjs index.html node_modules ...

Any suggestions on how to customize the tawk.to positioning within a Next Js script?

I've been attempting to adjust the positioning of the Tawk.to Sticky button on my Next js website using CSS, but it doesn't seem to be working. Below is the script within the Next Js script tag: <Script dangerouslySetInnerHTML={{ __html: ` ...

Why is it necessary to use 'then' on the response JSON when using the Fetch API? It's like trying to decipher the hidden meaning

While delving into the realm of promises, I decided to test it out with a basic GET request on Twitch. Yet, one aspect is still puzzling me - why does json() return a promise? The response already contains the data, so what's the deal with it being wr ...

Tips for adding an array to a formData: incorporating an array with two values along with their corresponding keys

Snippet : const options = new RequestOptions({ headers: headers }); let myArray; myArray = [{ "subfolder_name": subfolder, "file_upload": file }]; let formData: FormData = new FormData(); formData.append("folder_name",folder ); formData.append("counse ...

The object's key values were unexpectedly empty despite containing data

There's an issue with my object - it initially gets key values, but then suddenly loses them all. All the key values become empty and a message appears in the console for the object: "this value was evaluated upon first expanding. it may have ch ...

Error encountered in Storybook: The value is not iterable (property Symbol(Symbol.iterator) cannot be read)

I recently created a React library using and opted for the React + TypeScript + Storybook template. You can find the entire codebase here → https://github.com/deadcoder0904/react-typical I encountered the following error: undefined is not iterable ( ...

What causes my browser fingerprint to consistently remain unchanged?

declare var Fingerprint2: any; @Component({ selector: 'my-app', template: `Hello`, }) export class App { constructor() { new Fingerprint2().get(function(result, components){ console.log(result); // Device fingerprint as a hash va ...

Exploring the wonders of Node.js, Redis, and Express.js while navigating through the enchanting world of Asynchronous

Hello there, I must confess that this is a whole new realm for me... Here is what we've got: app.get('/user/:user_id/followings', function(req, res) { var response = {} , userId = req.params.user_id , ids = req.param(' ...

Having trouble getting the form to submit using AJAX

=====ANOTHER UPDATE==== (if anyone is interested!) The previous solution I shared suddenly stopped working for some reason. I added a beforeSend function to my ajax request and inserted the section of my JavaScript code that validates my form into it. It&a ...

The organization of JavaScript function declarations

Just a quick query as I seem to be encountering some peculiar bugs and can't seem to find any information on this issue. Does the order in which functions are defined within a file make a difference? Take for instance: function c() { d(); //define ...

How to display a conditional component in a single line with Material UI

I'm facing an issue with a component that is being reused multiple times. Here's the current output: |MyComponent1| |MyComponent2| Specifically, my condition is: if (a == 'One' || b == 'Two'){ <MyComponent data={data}/> ...