Search code examples
node.jssocket.io

SocketIO can't send new message until first will be delivered


Situation:
User has sent image, after image, he will send message. While the second user does not receive a picture, the message will not be sended.

How to send messages normally, like in normal chat? I have found, that there are "async" module for node.js, but how to use it with Socket IO?


Solution

  • You could simply pass every messages in a queue. So each messages must wait for the first one to be send before passing to the next.

    Although, here in your case. I don't think waiting for an image to be sent is wise - this will make your chat unresponsive.

    Rather, use simple text image message. Once you receive this, put a placeholder in the chat where you'll load the image when you received it (displaying a loader meanwhile). This will allow you to continue the chat without being blocked by a long IO process to finish.