You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I came across a bug where if you broadcast an event to a room, it times out unless you explicitly set a timeout variable.
To Reproduce
Please fill the following code example:
Socket.IO server version: ^4.0.0
Server
import{createServer}from"node:http";import{readFile}from"node:fs/promises";import{Server}from"socket.io";constport=process.env.PORT||3000;consthttpServer=createServer(async(req,res)=>{if(req.url!=="/"){res.writeHead(404);res.end("Not found");return;}// reload the file every timeconstcontent=awaitreadFile("index.html");res.writeHead(200,{"Content-Type": "text/html","Content-Length": Buffer.byteLength(content),});res.end(content);});constio=newServer(httpServer,{});constroomCode="Test room code"io.on("connection",(socket)=>{console.log(`connect ${socket.id}`);socket.on("joinRoom",async(username,ack)=>{console.log(`${username} joining`);socket.join(roomCode);// This doesn't workconstresponse=awaitsocket.to(roomCode).emitWithAck("userJoined",username);// This does// const response = await socket.to(roomCode).timeout(5000).emitWithAck("userJoined", username);ack(response);})});httpServer.listen(port,()=>{console.log(`server listening at http://localhost:${port}`);});
Socket.IO client version: ^4.0.0
Client
import{io}from"socket.io-client";constport=process.env.PORT||3000;constsocket=io(`http://localhost:${port}`);constsocket2=io(`http://localhost:${port}`);socket.on("userJoined",(username,ack)=>{ack("username1")})constresponse1=awaitsocket.emitWithAck("joinRoom","username1");console.log(`Response 1 is ${response1}`);constresponse2=awaitsocket2.emitWithAck("joinRoom","username2")console.log(`Response 2 is ${response2}`);
Expected behavior
It should work with or without the explicit timeout set.
Platform:
OS: Ubuntu 22.04.5 LTS
The text was updated successfully, but these errors were encountered:
In addition, can I get some clarification whether a emitWithAck chained to a to(room) is supported. Officially, it seems not to be per this, but I've seen multiple places where people are using it, such as here, or even in the code(if I'm reading it correctly). Am I misunderstanding the documentation, or are the documents outdated?
Oops, I've updated the documentation, because acknowledgements are now supported when broadcasting (since [email protected], released in 2022). Good catch!
Describe the bug
I came across a bug where if you broadcast an event to a room, it times out unless you explicitly set a timeout variable.
To Reproduce
Please fill the following code example:
Socket.IO server version:
^4.0.0
Server
Socket.IO client version:
^4.0.0
Client
Expected behavior
It should work with or without the explicit timeout set.
Platform:
The text was updated successfully, but these errors were encountered: