Live objects between different devices

Hello amity !
steps
1- open two tabs on browser
2- add new post inside the first tab
3- subscribe to live object like this this.liveFeed.on(‘dataUpdated’)

problem

  • the new post added successfully to the tab that i add the post from
    and the live event work with this tab but the other tab not updated the new post that is created with the other tab

expected
need to make live object that detect any change with any other device to make post real time updated

please help me to solve these issue
i use == ionic vue js
and version == “@amityco/js-sdk”: “^5.6.0”

thanks

@amitysupport Hello can you please help me

Hi @mohamedismael , our team is already working on this & will get back to you as soon as possible. Thank you

So its not implemented yet in sdk right ??

@amitysupport
its not implemented or you will get back to me ?

Our team is checking on this behaviour, and will get back to you once we have the update.

Hello @mohamedismael after the investigation, it appears that in some features you are required to subscribe to the real-time event, please see the sample steps below:

  1. You need to get a topic of real-time event from this example
    ASC Sample Code

  2. Add the topic from #1 to EventSubscriberReposity same as the example
    ASC Sample Code

  3. After #1 and #2 real-time event service will send an event to the client automatically (*.on('dataUpdated') will work as expected, please see sample code here ASC Sample Code )

Note: Please don’t forget to do unsubscribe when user proceed to change the page or when real-time events are not required

thank you for your response it works for me
but need one thing

how to subscribe to all posts include timeline and community posts
i call PostRepository.queryAllPosts()
that retrieve all timeline posts includes posts inside community
how to subscribe to this ?

@amitysupport Hello can you please help me to solve this

Hey @mohamedismael

You would need to individually subscribe to the posts returned in the response for queryPosts.

Also, you would need to subscribe to the appropriate topic based on targetType.

@amitysupport
i know what you mean but i don`t know what is the appropriate topic need to use
i test all but get error
can you please send me am example to subscribe on PostRepository.queryAllPosts()
that i need it to get All posts includes timeline , community and user follow posts
thank you

There are 2 types of posts: user posts and community posts. If user posts a post in the community it’s a community posts, other way it is user post. Community posts appear in community feeds, user posts in user feeds.

To receive post updates for the user you should do:

import { 
  UserRepository, 
  getUserTopic, 
  SubscriptionLevels, 
  EventSubscriberRepository,
} from '@amityco/js-sdk';

let user;
const liveUser = UserRepository.userForId('abc');

liveUser.on('dataUpdated', model => {
  user = model;
});

// once you have user model you can subscribe to the topic to receive updates for all posts appeared in the user feed 

const topic = getUserTopic(user, SubscriptionLevels.POST);
EventSubscriberRepository.subscribe(topic);

Community:

let community;
const liveCommunity = CommunityRepository.communityForId('abc');

liveCommunity .on('dataUpdated', model => {
  community= model;
});
...
const topic = getCommunityTopic(community, SubscriptionLevels.POST);
EventSubscriberRepository.subscribe(topic);

The queryAllPosts gives you back a mix of posts from different user feed and community feeds. To be notified that some post is created in general you should subscribe by hand for every user and community you want receive updates from.

For you case, I suppose it’s enough to subscribe to

const topic = getUserTopic(user, SubscriptionLevels.POST);

Where user is your user.

There is no unique topic for queryAllPosts which gives update for everything.

2 Likes