Skip to content
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

No typescritp support #50

Open
vandelpavel opened this issue Mar 27, 2023 · 0 comments
Open

No typescritp support #50

vandelpavel opened this issue Mar 27, 2023 · 0 comments

Comments

@vandelpavel
Copy link

vandelpavel commented Mar 27, 2023

In order to make guacamole more TS friendly we've created the following declaration file based on how the guacamole-lite app has been built.

// guacamole-lite.d.ts

// See: https://stackoverflow.com/a/49936686/7931540
type DeepPartial<T> = {
  [P in keyof T]?: T[P] extends Array<infer U>
    ? Array<DeepPartial<U>>
    : T[P] extends ReadonlyArray<infer U>
    ? ReadonlyArray<DeepPartial<U>>
    : DeepPartial<T[P]>;
};

declare module "guacamole-lite" {
  // See packages/client/models/guacamole.ts for other guacamole related types which should be served by "guacamole-lite"

  /**
   * This should have next type structure: https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback [1]
   * But guacamole-lite is using a really old version(1.1.2) of ws(now 8.13.0)
   */
  export interface WsServerOptions {
    port?: number;
  }

  /*
   * This configuration object is used inside the guacamole-lite server to establish the connection with the guacd using the following overload of `Net.connect`
   * function connect(port: number, host?: string, connectionListener?: () => void): Socket;
   * See: https://github.com/vadimpronin/guacamole-lite/blob/d2f4ce1ec1847781ca3667066c9e286624d8e432/lib/GuacdClient.js#L23
   */
  export interface GuacdConnectOptions {
    port?: number;
    host?: string;
  }

  enum GuacamoleLogLevel {
    QUIET = 0,
    ERRORS = 10,
    NORMAL = 20,
    VERBOSE = 30,
    DEBUG = 40,
  }

  /**
   * This configuration object comes from this lines of code used inside the Server.js
   * See: https://github.com/vadimpronin/guacamole-lite/blob/d2f4ce1ec1847781ca3667066c9e286624d8e432/lib/Server.js#L34-L107
   */
  interface __GuacamoleClientOptions {
    maxInactivityTime: number;
    log: {
      level: GuacamoleLogLevel;
      stdLog: typeof console.log;
      errorLog: typeof console.error;
    };

    crypt: {
      cypher: string;
    };

    connectionDefaultSettings: {
      rdp: {
        args: string;
        port: string;
        width: number;
        height: number;
        dpi: number;
      };
      vnc: {
        args: string;
        port: string;
        width: number;
        height: number;
        dpi: number;
      };
      ssh: {
        args: string;
        port: number;
        width: number;
        height: number;
        dpi: number;
      };
      telnet: {
        args: string;
        port: number;
        width: number;
        height: number;
        dpi: number;
      };
    };

    allowedUnencryptedConnectionSettings: {
      rdp: string[];
      vnc: string[];
      ssh: string[];
      telnet: string[];
    };
  }

  export type GuacamoleClientOptions = DeepPartial<__GuacamoleClientOptions> & {
    crypt: {
      key: string;
    };
  };

  export default class GuacamoleLite {
    constructor(
      websocketOptions: WsServerOptions,
      guacdOptions: GuacdConnectOptions,
      clientOptions: GuacamoleClientOptions
    );
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant