SocketCluster / socketcluster

Highly scalable realtime pub/sub and RPC framework
https://socketcluster.io
MIT License
6.15k stars 314 forks source link

"Ready" Event Listener not defined in socketcluster-server type definitions #555

Open unicornlab-brylleg opened 2 years ago

unicornlab-brylleg commented 2 years ago

It seems that the listener for the "ready" event of the AGServer type does not exist in the type definitions within \node_modules\@types\socketcluster-server\server.d.ts. Please see the below code snippet of this file:

listener(eventName: 'error'): ConsumableStream<{ error: Error }>;
listener(eventName: 'warning'): ConsumableStream<{ warning: Error }>;
listener(eventName: 'handshake'): ConsumableStream<{ socket: AGServerSocket }>;
listener(eventName: 'authenticationStateChange'): ConsumableStream<AGServer.AuthStateChangeData>;
listener(eventName: 'authentication'): ConsumableStream<AGServer.AuthenticationData>;
listener(eventName: 'deauthentication'): ConsumableStream<AGServer.DeauthenticationData>;
listener(eventName: 'badSocketAuthToken'): ConsumableStream<AGServer.BadSocketAuthTokenData>;
listener(eventName: 'connection'): ConsumableStream<AGServer.ConnectionData>;
listener(eventName: 'subscription'): ConsumableStream<AGServer.SubscriptionData>;
listener(eventName: 'unsubscription'): ConsumableStream<AGServer.UnsubscriptionData>;
listener(eventName: 'connectionAbort'): ConsumableStream<AGServer.ConnectionAbortData>;
listener(eventName: 'disconnection'): ConsumableStream<AGServer.DisconnectionData>;
listener(eventName: 'closure'): ConsumableStream<AGServer.ClosureData>;

However, according to the documentation of AGServer, there is a "ready" event defined: 'ready' | Emitted when the server is ready to accept connections.

I have checked the source code in \node_modules\socketcluster-server\server.js and it does indeed emit the "ready" event as per the below snippet:

if (this.brokerEngine.isReady) {
    this.isReady = true;
    this.emit('ready', {});
  } else {
    this.isReady = false;
    (async () => {
      await this.brokerEngine.listener('ready').once();
      this.isReady = true;
      this.emit('ready', {});
    })();
  }

Is it just me or is the type definitions file incomplete in this regard?

Package Versions: "socketcluster-server": "^16.1.0" "@types/socketcluster-server": "^15.0.4" "socketcluster": "^16.0.2"

jondubois commented 2 years ago

It's possible. You can make a pull request on the DefinitelyTyped repo on GitHub: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/socketcluster-server