I recently added functionality so my socket.io based chatroom can broadcast file now. Below is how I did it:
var data = e.originalEvent.target.files[0];
var reader = new FileReader();
reader.onload = function(evt){
var file = evt.target.result;
socket.emit('base64 file', file);
};
reader.readAsDataURL(data);
But I notice that when a user is sending a file, he/she can no longer send out any chat message, the chat messages he sent are queued and will emit once the file finish sending. Is there a way to get around this behavior?
Moreover, when a user sends a bigger file that's taking more than 60 seconds, he gets disconnected. I think this is due to the default timeout setting of Socket.io. I guess since user can't send message when sending file, he can't send his heartbeat to the server as well, thus server thinks he's timed out. This seems to be a bug to me.
How do I avoid timeout issue and allow user to chat while sending file? Thx!
Update:
New Socket.io support sending binary data using buffer
, so I tested that too. However, there's still this same problem.