Support Topics Documentation Slack YouTube Blog

Realtime Leaderboard

Morning Backendless.

I don’t have a problem or a bug :slight_smile: but just wanted to be pushed in the right directon.

We use backendless 5.0 in our app. Currently the scores in the app are saved to a scores table in backendless. If those scores in the table change we would like them to change on a user facing web leaderboard too. It looks like the realtime database would be ideal. We started using node.js and websockets a while back and never finished it, but it looks like using backendless realtime would kind of do away with using this anyway and be a simpler approach as you have already done a lot of the heavy lifting?

Any suggestions to what kind of approach you might use for this project if we were to go for a backendless solution. Basically anytime a score changes for a user or a new score is created in the iOS or Android app we want to show this on a simple web based leaderboard.

Any pointers gratefully received.

Mike

Hi @mike-turner

If in terms of your leaderboard table max score can be either CREATED or UPDATED - then you should use both create and update listeners. Basically there are 2types of listeners: conditional and unconditional. Unconditional subscribes to ALL create and update events in a certain table while conditional ones are triggered only when specified condition is met. F.e.:

EventHandler<Map> orderEventHandler = Backendless.Data.of( "LeaderBoard" ).rt();

orderEventHandler.addCreateListener( "maxScore > 1000", new AsyncCallback<Map>()
{
//your handleResponse and handleFault blocks
}

In this case listener will be triggered only in case if maxScore of created object is higher than 1000.
Same for update listener.
In order to keep leaderboard “fresh” - retrieve objects from leaderboard table with DESC sorting by maxScore column. Any update or create event will trigger a listener. Whether the object is created/updated from iOS SDK, Android, REST or even Data console. Nothing special or extra should be done, listeners are just interceptors.

More about listeners, listeners triggering etc you can read in docs:
JS (for web) - https://backendless.com/docs/js/rt_handlers_and_events.html
Android (just in case) - https://backendless.com/docs/android/rt_handlers_and_events.html
iOS (just in case) - https://backendless.com/docs/ios/rt_handlers_and_events.html

THESE articles also might be helpful, on of them even has leaderboard example :wink: :


Regards,
Anton

Awesome, thanks Anton for that information. I will read through all the links, but seems perfect.

I think I just need to find some sort of javascript table library which will look pretty and backendless can do the work!

Super! If you face any difficulties while working on realtime DB - do not hesitate to ask :wink:

Thanks, any suggestions on any javascript/web libraries for tables to base leaderboard table itself on. Was thinking of datatables.net but wondered if you guys had any recommendations? A whole library might be overkill.

Hi Mike

It depends on JS framework you use in your app. The plugin you provided is a jQuery plugin, so if you build your app based on plain JS/HTML using jQuery you can try this one. But if you use React or Angular, I assume, you can take a look at React/Angular Table components.

Backendless provides you a data storing, and a way how to display and manage it you have to choose based on your project architecture.

Regards, Vlad

Thanks Vladimir. Starting with a complete blank canvas for the web leaderboard… Thanks I was just fishing for some personal recommendations in case you had come across something perfect as there are quite a few different options for me to look at otherwise, but this is probably on the edge of the backendless forum brief!!