Class FreeSwitchClient

FreeSwitchClient is the class you use to create a new client. It will automatically reconnect.

const client = new FreeSwitchClient({ logger: pino.default() })
const res = await client.bgapi('sofia status', 1000)
console.log('sofia status is', res)

Hierarchy (View Summary)

Constructors

  • Parameters

    • options: { host?: string; logger: Logger; password?: string; port?: number }

    Returns FreeSwitchClient

Properties

custom: FreeSwitchEventEmitter<
    string,
    Record<string, (data: FreeSwitchEventData) => void>,
>

Event emitter for custom events

this.custom.on('conference::maintenance', (data) => {
})
logs: FreeSwitchEventEmitter<
    "log",
    { log: (data: FreeSwitchParserData) => void },
> = ...

EventEmitter for log events You must use client.log() beforehand to specify the log level.

ref: string = ...

Uniquely identify each instance, for tracing purposes.

stats: {
    apiResponses: bigint;
    authRequest: bigint;
    bodyParseErrors: bigint;
    commandReply: bigint;
    disconnect: bigint;
    events: bigint;
    logData: bigint;
    missingContentType: bigint;
    missingEventName: bigint;
    nonEmptyBufferAtEnd: bigint;
    rudeRejections: bigint;
    unflushedWrites: bigint;
    unhandled: bigint;
} = ...

Statistics about this connection

Type declaration

  • apiResponses: bigint

    Number of api responses

  • authRequest: bigint

    Number of authentication requests

  • bodyParseErrors: bigint

    Number of body parse errors

  • commandReply: bigint

    Number of command replies

  • disconnect: bigint

    Number of disconnect event received

  • events: bigint

    Number of FreeSwitch events received

  • logData: bigint

    Number of log data events received

  • missingContentType: bigint

    Number of missing Content-Type headers

  • missingEventName: bigint

    Number of missing Event-Name headers

  • nonEmptyBufferAtEnd: bigint

    Number of unexpected non-empty buffer at end of processing.

  • rudeRejections: bigint

    Number of rude rejections (generally due to ACL access to the Event Socket)

  • unflushedWrites: bigint

    Number of unflushed writes, indicating the network or FreeSwitch are not keeping up with our traffic

  • unhandled: bigint

    Number of unhandled events

Methods

  • End this instance.

    Returns void

  • Execute an application for the given UUID (channel). Does not await the result. event-uuid and event-uuid-name are set as app_uuid and app_uuid_name in the channel, respectively.

    If you would like to await the result, use command_uuid.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • uuid: string
    • appName: string
    • appArg: string
    • headers: {
          "content-type"?: string;
          "event-uuid"?: string;
          "event-uuid-name"?: string;
          "hold-bleg"?: boolean;
          loops?: number;
      }
    • timeout: number

    Returns SendResult

  • Hangup the call referenced by the given UUID with an optional (FreeSwitch) cause code.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • uuid: string
    • hangupCause: string = 'NORMAL_UNSPECIFIED'
    • timeout: number

    Returns SendResult

  • Enable logging on the socket, setting the log level.

    client.log(7)
    client.logs.on('log', (data) => { … })

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • level: number
    • timeout: number

    Returns SendResult

  • Disable logging on the socket.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • timeout: number

    Returns SendResult

  • Send an event into the FreeSwitch event queue with a body.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • eventName: EventName
    • args: ValueMap
    • contentType: string
    • content: Buffer<ArrayBufferLike>
    • timeout: number

    Returns SendResult

  • Send a message to a given UUID (channel).

    This is a low-level operation; in most cases execute_uuid, command_uuid etc will provide a better API.

    This method is not exposed by default; create a subclass of FreeSwitchClient in order to access it.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • uuid: string
    • command: string
    • args: ValueMap
    • body: undefined | Buffer<ArrayBufferLike>
    • timeout: number

    Returns SendResult

  • Forwards the media to and from a given socket.

    This method is not expected to throw / return a rejected Promise.

    Parameters

    • uuid: string
    • args: {
          flags?: "native";
          "local-ip": string;
          "local-port": number;
          "remote-ip": string;
          "remote-port": number;
          transport: "tcp" | "udp";
      }
      • Optionalflags?: "native"

        native means do not transcode to/from L16 audio

        In other words, if the flags is present, audio will be in the native codec. If the flag is absent, audio will be in L16 format.

      • local-ip: string
      • local-port: number
      • remote-ip: string
      • remote-port: number
      • transport: "tcp" | "udp"
    • timeout: number

    Returns SendResult