0

actually I'm working on reactJs project with laravel on backend I want to play sound whenever I recieve notification I tried but I didn't get a solution. this is my code :

  useEffect(() => {
    let statusInterval = setInterval(() => {
    getData();

  }, 10000)
  return () => {
    clearInterval(statusInterval);
  }
  }, [])

  async function getData() {
    let result = await fetch(`${API_ENDPOINT}/api/listComplain`);
    result = await result.json();
    setData(result)
  }

I want also to know if there's another way better that setInterval to get data Thanks in advance for your help.

syrine
  • 1
  • 1
  • https://stackoverflow.com/questions/18826147/javascript-audio-play-on-click Repurpose the code here to fire whenever your notification event fires? – Lucretius Jun 22 '22 at 18:10
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 22 '22 at 19:29

1 Answers1

0

Classic would have been to use web sockets for this instant notification notices to clients. But this requires some setup and knowledge. Actually I wrote a service that you can POST to it and it will send data (like a string) to the clients, which is what you need. https://rejax.io .

IT goldman
  • 14,885
  • 2
  • 14
  • 28