Skip to content

fetchSockets() always returns RemoteSocket[] #4595

@nathan6am

Description

@nathan6am

Describe the bug
I am trying to retrieve a socket instance by its id, however, using the io.fetchSockets() method always returns a RemoteSocket[], so methods like socket.timeout can't be used from the resulting instance. According to the docs fetchSockets should return Socket[] | 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

//Returns a Promise<RemoteSocket | undefined>
const socketInstanceById = async (socketId: string) => {
    const sockets = await io.in(socketId).fetchSockets(); 
    for (const socket of sockets) {
      if (socket.id === socketId) return socket;
    }
 }

Reducing the example to

const sockets = await io.fetchSockets()
//Type of `sockets` is RemoteSocket[]

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions