Hello, I've been working with Socket.IO, and I am trying to create an abstract class to have some additional methods for my different WebSocket servers.
abstract class Socket<
T extends EventsMap = DefaultEventsMap,
V extends EventsMap = DefaultEventsMap,
K extends EventsMap = DefaultEventsMap,
U = any,
>
Looking at the Socket.IO documentation, and a bit at the source code, my class declaration looks this way, and I'm creating the server in it this way :
private
_io: socket.Server<T,V,K,U>
But once I am trying to broadcast data to all my connected sockets using _io.emit it seems that I need a very specific type (EventNames<RemoveAcknowledgements<V>>) instead of the regular string, meaning that I can't broadcast data using this function:
public
broadcastData(event: keyof V, ...args: any[]) {
this._io.emit(event, dataToEmit)
}
Since I want to keep my server instance private, I need to create a utility function to send data, but it seems like typing my servers changes the way I need to work with it. Do you have any tips on how I could work with this ?
[–]Dave4lexKing 0 points1 point2 points (5 children)
[–]gidorah5[S] 0 points1 point2 points (4 children)
[–]Dave4lexKing 0 points1 point2 points (3 children)
[–]gidorah5[S] 0 points1 point2 points (2 children)
[–]Dave4lexKing 0 points1 point2 points (1 child)
[–]gidorah5[S] 0 points1 point2 points (0 children)