shimaore/esl

unable to add logger option in v11 with typescript

ryanleung96 opened this issue · 5 comments

I'm unable to add the logger option to FreeSwitchClient in v11 with typescript. Any example code to use?

Hi @ryanleung96
Are you getting a TypeScript error, or is this happening at runtime?

The logger should be an object { debug, info, error }, each being a function (a ResponseLogger):

  type ResponseLogger = (msg: string, data: { ref: string, [key:string]: unknown }) => void;

Something along the lines of

logger: {
  debug: (msg,data) => {},
  info: (msg,data) => {},
  error: (msg,data) => {},
}

FWIW I am working on a full rewrite of the module in TypeScript to avoid any discrepancies — although the current type definitions worked well for the applications I wrote with them.

@shimaore

Not in runtime, but in writing my code. Current .d.ts does not support the logger option in FreeSwitchClient.

type ResponseLogger = (msg: string, data: { ref: string, [key:string]: unknown }) => void;
...

class FreeSwitchResponse {
    // constructor(socket: Socket, logger: { debug: ResponseLogger, info: ResponseLogger, error: ResponseLogger });
    stats: {
...

class FreeSwitchClient {
    constructor(options?: {
      host?: string, port: number, password?: string
    });
    connect(): void;
    end(): Promise<void>;
    on(event:'reconnecting', cb:(retry:number) => void) : void;
    on(event:'error', cb:(exception:Error) => void) : void;
    on(event:'connect', cb:(call:FreeSwitchResponse) => void) : void;
    on(event:'warning', cb:(data:unknown) => void) : void;
    on(event:'end', cb:() => void) : void;
}

There's no way I can inject the logger settings to the client

@ryanleung96 sorry about that

Feel free to submit a PR for the d.ts, otherwise I'll take care of it later this week.

@shimaore PR submitted. I added the logger option to FreeSwitchClient constructor and nothing more.

This kind of discrepancy should no longer be present with the rewrite of the module in typescript (v11.1.0).