I would like to know how to wait on an socket.on call. I know that one could use the callbacks as described here, but this is not applicable in my case (at least I think it is not). The following is what I have:
index.html
...
socket.on('update_img', function(data) {
// Do something
});
scanner.addListener('scan', function(content) {
socket.emit('answer', content);
});
and then on the server:
...
client.emit('update_img', some_data);
...
client.on('answer', function(data) {
// do something with the answer
});
what basically happens, I send something to the frontend which then generates an image. At the same time, the library in the browser (instascan
, thus scanner.addListener) waits for reading a QR-code and sends its content back to the server. So what I now need is that client.on('answer', ...);
waits for this answer.
Is there any way to achieve this?