0

What I want to do is, when something new comes into the database, it gets the latest value entered and plays a specific song depending on what it says.

For example, on my computer, I run this website. Say somebody else around the world picked up their phone and clicked to play a song, that song would automatically play on all devices running the page. When somebody chooses a new song, the song should change.

I have made several tries at this, mainly trying to use setInterval in JavaScript however it just updates and updates all the time as you would expect.

I guess what I really am looking for is a way to track when the database has been updated, any solutions or code examples I can use?

1
  • Keep track of which user's you've "notified" so you don't "notify" them multiple times of the same thing. Commented Mar 28, 2017 at 16:25

1 Answer 1

2

If I understand you right, you can use push notifications. https://firebase.google.com/docs/notifications/

Here's a tutorial how to set up a js client https://firebase.google.com/docs/cloud-messaging/js/client

In this case you won't have to do unnecessary requests to the server to fetch updated. Just send a push notification to the client and do necessary actions on the client side.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.