I'm writing a lightning page that allows two players to remotely play chess through the same lightning page. The page uses the aura framework.

For what I've already implemented, the Game__c object has two lookup fields to a user- one for each player- and only lets the correct player move a piece on their turn. Moreover, when the page loads, it loads the correct board position.

However, when a player moves a piece, the board does not update on their opponent's screen- the opponent has to refresh to see the update.

How can I make the board update in as soon as the active player makes their move?

up vote 5 down vote accepted

Very very interesting question.

  1. Using Platform Events and lightning:empAPI : This can be solved by Platform events, whenever a player makes a move, fire a platform event. Also as a listener use lightning:empAPI in both the components.

When 1 player makes a move, the other player's components gets notified and he reacts accordingly by refreshing the view or moving that piece via code.

  1. Using Lightning Data Services: This might be another way to handle this. According to docs/DF18 session, LDS automatically uses streaming API so that all screens have fresh data, not sure how effective it is.
  • 1
    Seems promising, but [in both the components] -- is actually the instance of same component, so an event fired and subscribed sits on the same component, thus it may get complex as which User need to fire vs. which User need to subscribe to the event. – Jayant Das Nov 15 at 22:08
  • Can be bit challenging, but I have built something similar that the event though fires only the people who mentioned in will react to it. – Pranay Jaiswal Nov 15 at 22:21

There is a new feature mentioned at DF 18 called Live Records, that will be part of Lightning Data Service, which I think is based on the new Change Data Capture feature, but I think it is only in Dev Preview right now: https://developer.salesforce.com/blogs/2018/08/what-is-change-data-capture.html

If you look at this DF session, you'll see a demo of it doing pretty much what you are describing - user 1 is viewing a record and it is changed by another user - and the change will be automatically made on user 1's screen without requiring a refresh. So might be worth seeing if you can get access to that since you have a good use case there

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.