I have problems when i upload an image to my server, when i do that i want to emit this event to the room "1room"
`io.sockets.in("1room").emit('image_added','OK');`
the problem is, the event doesnt fired on the client, but if i reload the page yes, the event is fired.
HTML
<form ref='uploadForm'
id='uploadForm'
action='http://localhost:3000/upload'
method='post'
encType="multipart/form-data">
<input type="file" name="sampleFile" />
<input type='submit' value='Upload!' />
</form>
SERVER
io.sockets.on('connection', function(socket){
socket.join("1room");
});
app.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
let sampleFile = req.files.sampleFile;
sampleFile.mv('/xampp2/htdocs/pic.jpg', function(err) {
if (err)
return res.status(500).send(err);
if (res.status(200)){
io.on('connection', function(socket){
io.sockets.in("1room").emit('image_added','OK');
});
}
});
});
CLIENT
socket.on('image_added', function(status) {
alert(status);
});