-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fetchSockets()
always returns RemoteSocket[]
#4595
Comments
fetchSockets()
always returns RemoteSocket[]
Getting a Regarding the |
Why would I get a socket.io/lib/broadcast-operator.ts Lines 318 to 338 in 54d5ee0
|
The type of the socket.io/lib/broadcast-operator.ts Lines 327 to 329 in 54d5ee0
Is there anything that should be exposed by the |
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: #4595
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: socketio#4595
The RemoteSocket interface, which is returned when the client is connected on another Socket.IO server of the cluster, was lacking the `timeout()` method. Syntax: ```js const sockets = await io.fetchSockets(); for (const socket of sockets) { if (someCondition) { socket.timeout(1000).emit("some-event", (err) => { if (err) { // the client did not acknowledge the event in the given delay } }); } } ``` Related: socketio#4595
Is there a way to get complete Socket client instance instead of RemoteSocket when using fetchSockets() in clusterized app? I would like to access socket.request.user property (user prop is provided by my express-session/passportjs middlewares) juste as i was able to access when my app was not clusterized: const activeParticipants: Array<Participant> = (
await browserSocket.adapter.fetchSockets({
rooms: new Set([code]),
})
)
.map(
(socket) =>
(socket as unknown as BrowserSocket).request.user
)
.filter((user) => !isUserAdmin(user)); RemoteClient actually not includes socket.request 😭 |
Hi! The You can include the user's id in the io.on("connection", (socket) => {
socket.data.userId = socket.request.user.id;
}); And then use it with const sockets = await io.fetchSockets();
for (const socket of sockets) {
console.log(socket.data.userId);
} |
Describe the bug
I am trying to retrieve a socket instance by its id, however, using the
io.fetchSockets()
method always returns aRemoteSocket[]
, so methods likesocket.timeout
can't be used from the resulting instance. According to the docsfetchSockets
should returnSocket[] | RemoteSocket[]
. I am not using an adapter and the behavior is the same in main namespace.To Reproduce
Please fill the following code example:
Socket.IO server version:
4.5.4
Server
Reducing the example to
Is
fetchSockets
the only way to retrieve a socket instance by its id? If so is there a way to get a Socket instance and not a RemoteSocket?Expected behavior
fetchSockets
should return normal socket instances when called on the same server.The text was updated successfully, but these errors were encountered: