I developed javascript chat (php on the backend) using:
1) long-polling to get new messages for the receiver
2) sessionStorage to store the counter of messages
3) setInterval to read new messages and if sessionStorageCounter < setIntervalCounter then the last message is shown to receiver.
4) javascript to create,update and write the chat dialogues
The module works fine, but when users have a quick chat, the front part of the recipient receives two or three identical messages (neither the counter works, nor the request provides double inserts).
The code seems to be correct (why I don’t provide the code), so the delay may be caused by a time delay (nothing changes when reducing the interval delay).
Do you think that the above scheme is bad practice and which scheme do you think will fix the errors?
source
share