API Docs for:
Show:

astproxy Class

Module: astproxy

Asterisk proxy with standard interface to use.

Methods

accept

() private

Sets the component's visitors.

addAstListeners

()

Add asterisk event listeners.

amiSocketClose

(
  • had_error
)
private

Handler for the ami_socket_close event emitted once the socket is fully closed. The argument had_error is a boolean which says if the socket was closed due to a transmission error

Parameters:

  • had_error Boolean

    It says if the socket was closed due to a transmission error

amiSocketConnected

() private

Handler for the ami_socket_connect event emitted once the socket is connected.

amiSocketEnd

() private

Handler for the ami_socket_end event emitted when the other end of the socket sends a FIN packet.

amiSocketError

(
  • err
)
private

Handler for the ami_socket_error event emitted when an error occurs, e.g. when lost the connection. The 'close' event will be calledd directly following this event.

Parameters:

  • err Object

    The error object

amiSocketTimeout

() private

Handler for the ami_socket_timeout event emitted when the socket times out from inactivity. This is only to notify that the socket has been idle. The user must manually close the connection.

amiSocketUnwritable

() private

Handler for the ami_socket_unwritable event emitted when the socket isn't writable.

config

(
  • path
)

Set the configuration to be use to establish the telnet asterisk connection. It also reads the queues and trunks list.

Parameters:

  • path String

    The file path of the asterisk JSON configuration file

configAstObjects

(
  • path
)

Reads the asterisk objects.

Parameters:

  • path String

    The file path of the asterisk JSON file

configExtenNames

(
  • path
)

Reads the extension names.

Parameters:

  • path String

    The file path of the users JSON file

configRemoteSitePrefixes

(
  • path
)

Sets the remote sites to have remote sites prefixes.

Parameters:

  • path String

    The file path of the JSON configuration file that contains the remote sites

configSipWebrtc

(
  • path
)

Sets the configuration to be used by sip WebRTC.

Parameters:

  • path String

    The file path of the JSON configuration file

doCmd

(
  • obj
  • cb
)

Executes specified command and return result in the callback. It calls the execute method of the command plugin that has the same name of the specified command. The plugin is contained into the file that resides in the appropriate directory and must have a file name equal to specified command parameter.

e.g. If the command name is astVersion, the astVersion.js plugin must be present.

Parameters:

  • obj Object

    The object with the command name to be executed and the optional parameters

    • command String

      The command name to be executed

    • [parameters] optional

      0..n The parameters that can be used into the command plugin

  • cb Function

    The callback

Example:

doCmd({ command: 'astVersion' }, function (res) {
    console.log(res);
});

doCmd({ command: 'dndGet', exten: '214' }, function (res) {
    console.log(res);
});

emit

(
  • ev
  • data
)

Emit an event. It's the same of nodejs events.EventEmitter.emit method.

Parameters:

  • ev String

    The name of the event

  • data Object

    The object to be emitted

getSipWebrtcConf

() Object

Returns the sip WebRTC configuration.

Returns:

Object:

The sip WebRTC configuration.

on

(
  • type
  • cb
)
Object

Subscribe a callback function to a custom event fired by this object. It's the same of nodejs events.EventEmitter.on method.

Parameters:

  • type String

    The name of the event

  • cb Function

    The callback to execute in response to the event

Returns:

Object:

A subscription handle capable of detaching that subscription.

onData

(
  • data
)
private

Handler for the received data from asterisk. It calls the execute method of the command plugin with the name that corresponds to the ActionID value contained in the data object. Plugins must reside in the appropriate directory.

e.g. If data contains astVersion_12345 ActionID key, the astVersion.js plugin must be present.

Parameters:

  • data Object

    The data received from asterisk

onLogin

(
  • err
  • resp
)
private

Handler for the received logged in event from asterisk.

Parameters:

  • err Object

    The error object

  • resp Object

    The event response data

reload

()

Reload the component.

reset

()

Reset the component.

setAllPluginsCmdLogger

(
  • log
)
private

Call setLogger function for all command plugins.

Parameters:

  • log Object

    The logger object.

setAllPluginsEventLogger

(
  • log
)
private

Call setLogger function for all event plugins.

Parameters:

  • log Object

    The logger object.

setLogger

(
  • log
)
static

Sets the logger to be used.

Parameters:

  • log Object

    The logger object. It must have at least three methods: info, warn and error as console object.

start

()

Start the telnet connection with the asterisk server and listen to any events.

Properties

am

Object private

The asterisk manager.

AST_CONF_FILEPATH

String private

The asterisk configuration file path.

AST_OBJECTS_FILEPATH

String private

The configuration file path of the asterisk objects.

astConf

Object private

The asterisk connection parameters.

emitter

Object private

The event emitter.

IDLOG

String private final

The module identifier used by the logger.

Default: [astproxy]

logger

Object private

The logger. It must have at least three methods: info, warn and error.

Default: console

self

Object private

It's this module.

sipWebrtcConf

Object private

The sip WebRCT configuration.

USERS_CONF_FILEPATH

String private

The configuration file path of the users.