Consider the following scenario...
- Member connects to chat channel
- Member disconnects from chat channel
- Same member tries to reconnect to same chat channel
My problem is the following...Between steps 2 and 3, when the member tries to reconnect to the same channel, I get the error, "Member already exists". In order to solve the problem, I tried the following steps:
2.1 Call channel.leave()
2.2 channel.leave() successfully returns
2.3 Member tries to reconnect to same chat channel
- Member successfully connects to same chat channel
After successfully reconnecting, when the member tries to send a message, it appears twice. Not a working solution. Instead of using channel.leave(), also tried using channel.removeMember(identity) instead. After reconnecting back to the same channel, again, if the member send a message, it appears twice. Time for the final question, how could/should a member connect and disconnect gracefully from a chat channel so it could keep having a conversation just like if that member had never left the channel?
Thanks!
Edit:
Step 1
const token = await axios.post('/twilio/chat',
{ identity: identity , room: channelName },
{ headers: header })
Step 2.
const client = await Chat.Client.create(token);
Step 3.
const channel = await client.getChannelByUniqueName(channelName)
Step 4.
const joinedChannel = await channel.join();
Step 5
const messages = await channel.getMessages()
messages.items.forEach((message) => {
//Consume unread messages...
})
channel.setAllMessagesConsumed()
Step 6. Listen to added messages
channel.on('messageAdded', (message) => {
//When sending a message, this is where I get it duplicated after reconnecting to room
})
const previousChannel = await channel.leave()
Step 7. When leaving channel....
const previousChannel = await channel.leave()
After many trial and errors, I have finally come to the following conclusion. In order to "fix" the problem, I have to refresh the tab, and in order to recreate it, I follow the aforementioned steps without refreshing the tab... Memory leak?
Firefox 65.0.1
Chromium 72.0.3626.53
UPDATE:
Fixed. In step 7, after leaving the room, the client has to be gracefully shutdown...
client.shutdown()
Not a really friendly fix since it is not even documented as a required step for leaving a room. The most probable cause is indeed a memory leak somewhere. Hope this bug can be fixed sometime soon...