Realtime Events
Realtime events in web is a way to get realtime updates on different entities of the social SDK. This means that whenever a user updates a community, adds/edits a new post within that community feed or adds/edits a comment within that post, the changes will be reflected immediately to all the users that choose to subscribe to the said community, post or comment.
The changes will be reflected through the same liveObject/liveCollection and its dataUpdated
event. The SDK currently supports realtime events subscription to the following models:
Community
Post
Comment
User
Follow/Unfollow
Topics
A topic is just a unique path<string> which has to be constructed for each model that we want to subscribe to in realtime. For each model type, SDK has helper methods to create these topics.
The five helper methods we have right now for the five different model types that support realtime events are:
getCommunityTopic
getPostTopic
getCommentTopic
getUserTopic
getUserFollowTopic
These methods, except for getUserFollowTopic
, have two parameters :
Data model (required) This is the model that we want to subscribe to and it can be the model of any liveObject that we want to subscribe to.
Subscription level (optional) This is a way to determine the level of events within that model that we want to get realtime updates. The SDK has a
SubscriptionLevels
enum which can be used. If not provided, the default subscription level will be the model type that is passed.
Community Topic
Community model supports the following subscription levels:
COMMUNITY
POST
COMMENT
POST_AND_COMMENT
The default value is COMMUNITY
.
Post Topic
Post model supports the following subscription levels:
POST
COMMENT
The default is POST
.
Comment Topic
Comment model supports only COMMENT
subscription level as there are no lower level models.
User Topic
User model is similar to the community model in terms of topic creation. User model supports the following subscription levels
USER
POST
COMMENT
POST_AND_COMMENT
The default value is USER
.
Follow Topic
Refer to Getting Realtime Updates to implement realtime events for follow and unfollow.
Subscribe and Unsubscribe
After creating a topic, you can subscribe and unsubscribe to the topic using EventSubscriberRepository
class.
Subscription Topics limit
The maximum limit for the number of topics that can be subscribed to is 20. Developers should maintain the list of subscriptions themselves and unsubscribe when it's not needed.
There are a few ways we can manage the subscription limit:
We advise the developers to use higher level of topics. For example, instead of creating a topic for each post within a community and for each comment within the posts, it's better to create a single community topic for all the posts and comments within that community by using the
getCommunity
topic method with SubscriptionLevel ofPOST_AND_COMMENT
.We advise the developers to subscribe to a topic when a liveObject is rendered and unsubscribe when not. For example, if you have a list of communities rendered on a page, and you click on one and move to a page that shows the details of that community, you might want to subscribe when user is only viewing community details in details page and unsubscribe when user moves back to community list page.
Observing Realtime events
After subscribing to data models from liveObjects, the changes from the realtime event will also be reflected on the dataUpdated
event of the same liveObject.
Example usage for subscribing and observing realtime events for a community:
If the session is logged out, all the existing subscriptions will be removed.
Last updated