I have created one messanger component in Lightning web component where i am saving and getting the messages from Object. I want that once i saved the message it should reflect on every users instance whenever i save.currently the message is showing on other user instances when i reload the page.I dont know how to achieve this in Lightning Web Components .
Please help me to find the solution.
Thanks in advance.
Best Answer
One option is to create a Push Topic or Platform event that fires whenever a new record is created in your object, and then use lightning-emp-api to listen to those changes in LWC. However,
lightning-emp-api
is not supported in communities, or off-platform, and there are limits associated with PushTopics/Platform Events.The other option (which is my recommendation) is to use WebSockets. For a chat use case, using WebSockets is more appropriate, and your component would work on Communities and Off-Platform. Here is an excellent blog post that explains it in detail.