Node.js, socket.io - io.emit doesn't work for a few seconds
up vote
0
down vote
favorite
I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb
is emitted from the client like so: socket.emit('passBomb');
This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:
socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});
If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.
How could I go about fixing this?
javascript node.js socket.io
add a comment |
up vote
0
down vote
favorite
I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb
is emitted from the client like so: socket.emit('passBomb');
This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:
socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});
If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.
How could I go about fixing this?
javascript node.js socket.io
Have you tried adding someconsole.log()
's to see if the logs as instant or taking a few seconds?
– NewToJS
3 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb
is emitted from the client like so: socket.emit('passBomb');
This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:
socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});
If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.
How could I go about fixing this?
javascript node.js socket.io
I have a Node.js app with socket.io. When the user clicks a button, an event called passBomb
is emitted from the client like so: socket.emit('passBomb');
This works fine, and when outputting from the server side, the message is recieved. I have it then emit from the function on the server side like so:
socket.on('passBomb', function(){
//OTHER CODE IS HERE, WORKS FINE, "game" is also defined here
io.to(game.pin).emit('bombPassed', game.gameData.bombHolder);
});
If I click the button within a few seconds of the button appearing due to setting display to "" or "block" in the javascript, the message is not received, and possibly not even sent. But if I click it again after a few seconds, the message is received by the client.
How could I go about fixing this?
javascript node.js socket.io
javascript node.js socket.io
asked 3 hours ago
TheProgrammedDev
13
13
Have you tried adding someconsole.log()
's to see if the logs as instant or taking a few seconds?
– NewToJS
3 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago
add a comment |
Have you tried adding someconsole.log()
's to see if the logs as instant or taking a few seconds?
– NewToJS
3 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago
Have you tried adding some
console.log()
's to see if the logs as instant or taking a few seconds?– NewToJS
3 hours ago
Have you tried adding some
console.log()
's to see if the logs as instant or taking a few seconds?– NewToJS
3 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53349378%2fnode-js-socket-io-io-emit-doesnt-work-for-a-few-seconds%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried adding some
console.log()
's to see if the logs as instant or taking a few seconds?– NewToJS
3 hours ago
At which point does your button appear again? what triggers it? please post that code?
– Sparlarva
2 hours ago
I have tried adding console.logs and they are instant, before and after the io.to(), under all circumstances
– TheProgrammedDev
1 hour ago
And the button appears due to a function using document.getElementById(“passButton”).style.display = “block” (on mobile, cannot do code blocks)
– TheProgrammedDev
1 hour ago
It’s a strange problem, has never happened before, and there is no apparent reason why this occurs.
– TheProgrammedDev
1 hour ago