diff --git a/src/index.ts b/src/index.ts index 585e433..af4fab9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -134,10 +134,25 @@ export default class Sarus { * * connect(), disconnect() are generally called by the user * - * this.reconnect() is called internally when automatic reconnection is - * enabled, but can also be called by the user + * When disconnected by the WebSocket itself (i.e., this.ws.onclose), + * this.reconnect() is called automatically if reconnection is enabled. + * this.reconnect() can also be called by the user, for example if + * this.disconnect() was purposefully called and reconnection is desired. + * + * The current state is specified by the 'kind' property of state + * Each state can have additional data contained in properties other than + * 'kind'. Those properties might be unique to one state, or contained in + * several states. To access a property, it might be necessary to narrow down + * the 'kind' of state. + * + * The initial state is connecting, as a Sarus client tries to connect right + * after the constructor wraps up. */ - state: "connecting" | "connected" | "disconnected" | "closed" = "connecting"; + state: + | { kind: "connecting" } + | { kind: "connected" } + | { kind: "disconnected" } + | { kind: "closed" } = { kind: "connecting" }; constructor(props: SarusClassParams) { // Extract the properties that are passed to the class