guid
June 27, 2022, 3:47pm
1
Hi,
After subscribing with
liveCollection.on(‘dataUpdated’, data => {messages = data;});
like in the doc exemple,
It begins with 5 dataUpdated notification for the first message then
I’m receiving up to 300 socket notifications for one single message received, the amount of notification grows indefinitly for only 2 users in the channel
Regards,
Hi @guid could you please share your code snippet when using this function?
guid
June 28, 2022, 6:09am
3
Hi,
Here is the sample:
setup(){
if (!this.client) {
this.client = new AmityClient({ apiKey, apiRegion: ApiRegion.EU });
}
this.client.registerSession({ userId: this.currentUser.id, displayName: `${this.currentUser.firstName} ${this.currentUser.lastName}` });
this.getChatUser();
this.listChannels();
}
private getChatUser() {
try {
this.liveUser = UserRepository.getUser(this.currentUser.id);
this.liveUser.once('dataUpdated', model => { this.onUserUpdated(model); });
this.liveUser.once('dataError', error => { this.onUserError(error); });
} catch (error) {
console.error(error);
}
}
private listChannels() {
for (let channelConfig of this.channelConfigList) {
let channelId = channelConfig.getChannelId();
let channel = ChannelRepository.getChannel(channelId);
if (channel && channel.dataStatus !== CHAT_CHANNEL_NOT_EXISTS) {
this.addChannel(channel.model, channelConfig);
channel.on('dataUpdated', channelUpdated => { this.onChannelUpdated(channelConfig, channelUpdated) });
channel.once('dataError', error => { this.onChannelError(channelId, error) });
} else {
this.addChannel(null, channelConfig);
}
}
}
private onChannelUpdated(channelConfig: ChatChannelConfig, _channel: any) {
// console.log(`[AmityService.onChannelUpdated]`, channelConfig.getChannelId());
let chatChannel = this.addChannel(_channel, channelConfig);
if (!chatChannel.messageLoaded) {
// Lister les messages du channel
this.listChannelMessage(channelConfig.getChannelId());
this.listChannelMembers(channelConfig, _channel);
}
this.sortChatChannelsByLastActivity();
// this.chatChannelList$.next(this.chatChannelList);
this.propagateChatChannelList();
}
private listChannelMessage(channelId) {
let messageList = MessageRepository.queryMessages({ channelId });
messageList.on('dataUpdated', messageList => this.onChannelMessageListUpdated(channelId, messageList));
messageList.on('dataError', messageList => this.onChannelMessageListError(channelId, messageList));
}
private onChannelMessageListUpdated(channelId: string, messageList) {
console.log(`[AmityService.onChannelMessageListUpdated]`, channelId);
const channel = this.getChatChannelById(channelId);
if ((channel.messageList || []).length != messageList.length) {
channel.setMessageList(messageList);
}
}
Once receiving a message, handler onChannelMessageListUpdated is called 5 times for the first message, on the second, i’m getting around 9 call of this handler et it keeps growing.
Thanks for your help.
Regards
guid
June 28, 2022, 6:13am
4
Hi,
My answer has been hidden by Akismeet.
Hope you can see it.
@guid Yes, I can see your post.
Thank you.
guid
June 28, 2022, 8:02am
6
If you need the entire js files, I can send them by mail if you want.
Guillaume
@guid Can you sand email us at support.asc@amity.co ?
Thank you .
guid
June 28, 2022, 8:38am
8
files sent with explanations.
Regards
1 Like
@guid I have received the files and I will pass this to the team for further investigation.
@guid Can you try to change from channel.on(‘dataUpdated’, …
to channel.once(‘dataUpdated’,… ?
guid
June 28, 2022, 12:08pm
11
Hi,
We use to have channel.once(‘dataUpdated’,… until yesterday.
the problem of receiving multiple call on messageList.on(‘dataUpdated’,…) Handler was already present.
guid
June 28, 2022, 12:48pm
12
Do you have the same issue ?
Hi, @guid Can I have more information?
How many channels does the user join?
The object that your receive is it all the same?
guid
June 29, 2022, 8:22am
14
Here is a video to see what’s happening in details
guid
June 29, 2022, 9:35am
15
Hi
I started from scratch a new implementation to ensure i add not mistakes
the code is directly on the web page.
Video of the result: Loom | Free Screen & Video Recording Software
Code ( use of liveChannel.once instead of .on ):
apiKey = environment.AmityApiKey;
client;
channelId = 'lpmember<11180>_orga<2>';
singleChannel;
messageList;
messageListLoaded = false;
loadSampleAmity() {
this.client = new AmityClient({ apiKey: this.apiKey, apiRegion: ApiRegion.EU });
this.client.userId = this.currentUser.id;
let sessionData = {
userId: this.currentUser.id,
displayName: `${this.currentUser.fullIdentity.firstName} ${this.currentUser.fullIdentity.lastName}`
};
this.client.registerSession(sessionData);
// Get User Data
const liveUser = UserRepository.getUser(this.currentUser.id);
liveUser.once('dataUpdated', model => {
console.log(`[getUser.dataUpdated]`, model);
// const channelId = 'lpmember<11180>_orga<2>';
let liveChannel = ChannelRepository.getChannel(this.channelId);
if (liveChannel.dataStatus == 'not-exist') {
console.error(`channel ${this.channelId} does not exists -> exit`);
return;
}
liveChannel.once('dataError', error => { console.error(`[getChannel.dataError]`, error) });
liveChannel.once('dataUpdated', channelUpdated => {
this.singleChannel = channelUpdated;
console.log(`channel ${this.channelId} updated`);
if (this.messageListLoaded)
return; // Exit if already loaded
console.log(`Load messages for channel ${this.channelId}`);
this.messageListLoaded = true;
let queryMessagesData = { channelId: this.channelId };
let messageList = MessageRepository.queryMessages(queryMessagesData);
messageList.on('dataError', error => {
console.error(`[queryMessages.dataError]`, error)
});
messageList.on('dataUpdated', messageList => {
console.log(`[queryMessages.dataUpdated( messageList.length = ${messageList.length})]`);
});
});
});
liveUser.once('dataError', error => {
console.error(`[getUser.dataError]`, error);
});
}
postMessage() {
let data = {
channelId: this.channelId,
text: new Date().getTime().toString()
}
MessageRepository.createTextMessage(data);
}
Hi @guid our team is investigating this issue, I will keep you posted on the progress, thank you
Hi @guid is this issue still persisting? Our team has checked and seems that it’s solved Please let us know if it’s still happening.