API Docs for:
Show:

com_nethcti_tcp Class

Module: com_nethcti_tcp

Core module that communicates with clients using a TCP connection.

Methods

addSocket

(
  • socket
)

Adds the client socket into the private object sockets. If it already exists it will be overwritten.

Parameters:

  • socket String

    The client socket private

config

(
  • path
)

Configurates the TCP server properties by a configuration file. The file must use the JSON syntax.

Parameters:

  • path String

    The path of the configuration file

configWinPopup

(
  • path
)

Configurates the settings to be used for Windows popup notifications of incoming calls by a configuration file. The file must use the JSON syntax.

Parameters:

  • path String

    The path of the configuration file

connHdlr

(
  • socket
)
private

TCP server connection handler. A new client connection has been made.

Parameters:

  • socket Object

    The client socket

disconnHdlr

(
  • socket
)
private

Client socket disconnection handler.

Parameters:

  • socket Object

    The client socket

evtUserPresenceChanged

(
  • data
)
private

Handler for the evtUserPresenceChanged event emitted by user component. The user has changed the presence, so notify all users associated with it, with the presence data of the user.

Parameters:

  • data Object
    • presence Object

      The presence data

extenConnected

(
  • data
)
private

Handler for the extenConnected event emitted by astproxy component. The event indicates two extensions, but it emits the event for only data.num1, because another event extenConnected will signal the same for other extension.

Parameters:

  • data Object
    • num1 String

      The identy of a part of the conversation

    • num2 Object

      The identy of other part of the conversation

extenDialing

(
  • data
)
private

Handler for the extenDialing event emitted by astproxy component. The extension ringing, so notify all users associated with it, with the identity data of the caller.

Parameters:

  • data Object
    • dialingExten String

      The identifier of the ringing extension

    • callerIdentity String

      The identity data of the caller

extenHangup

(
  • data
)
private

Handler for the extenHangup event emitted by astproxy component. The extension hangup, so notify all users associated with it, with the identity data of the extension.

Parameters:

  • data Object
    • callerNum String

      The identifier of the hangup extension

    • [cause] String optional

      The cause of hangup

    • channelExten String

      The extension of the channel

getFilteredStreamData

(
  • username
  • callerNum
)
Object private

Returns data about the streaming source filtered by user authorizations. If the user doesn't have the authorization, an empty object is returned.

Parameters:

  • username String

    The username

  • callerNum String

    The number of the caller

Returns:

Object:

The filtered streaming data

getNumConnectedClients

() Object private

Returns the number of connected clients.

Returns:

Object:

The number of connected clients grouped by version and the total

getSocketEndpoint

(
  • socket
)
String private

Returns the endpoint of the client socket. The endpoint is constructed by ip_address:port.

Parameters:

  • socket Object

    The TCP client socket

Returns:

String:

The socket endpoint as ip_address:port.

loginHdlr

(
  • socket
  • obj
)
private

TCP socket login handler.

Parameters:

  • socket Object

    The client socket

  • obj Object
    • username String

      The username of the account

    • token String

      The token constructed with the authentication REST request

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.

pingHdlr

(
  • socket
)
private

TCP socket ping handler. It responds with an "active" message.

Parameters:

  • socket Object

    The client socket

reload

() private

Reload the component.

removeClientSocket

(
  • socketId
)

Removes the client socket from the private object sockets.

Parameters:

  • socketId String

    The client socket identifier private

reset

() private

Reload the component.

resetCommandsHdlr

(
  • socket
  • obj
)
private

The handler to reset the commands of a nethifier client.

Parameters:

  • socket Object

    The client socket

  • obj Object
    • username String

      The username of the account

    • token String

      The token constructed with the authentication REST request

send401

(
  • socket
)
private

Send 401 unauthorization response through the client socket.

Parameters:

  • socket Object

    The client socket

sendAutheSuccess

(
  • socket
)
private

Send authorized successfully response to the client by socket.

Parameters:

  • socket Object

    The client socket

sendCallConnectedNotificationEvent

(
  • username
  • data
  • socket
)
private

Send the event to close a desktop notification popup about a connected call.

Parameters:

  • username String

    The username of the client

  • data Object

    The data about the parts of the conversation

  • socket Object

    The TCP socket client

sendCallNotificationEvent

(
  • username
  • data
  • socket
)
private

Send the event to open a desktop notification popup about an incoming call.

Parameters:

  • username String

    The username of the client

  • data Object

    The data about the caller

  • socket Object

    The TCP socket client

sendColorLed

(
  • username
  • color
  • socket
)
private

Send the color to be set in nethifier led.

Parameters:

  • username String

    The username of the client

  • color Object

    The color to be set

  • socket Object

    The TCP socket client

sendHangupNotificationEvent

(
  • username
  • data
  • socket
)
private

Send the hangup event to close a desktop notification popup about an incoming call.

Parameters:

  • username String

    The username of the extension

  • data Object

    The data about the extension

  • socket Object

    The TCP socket client

sendNotificationSupportedCommands

(
  • socket
)
private

Send supported commands by the windows notifications of incoming calls.

Parameters:

  • socket Object

    The client socket

sendResetNotificationSupportedCommands

(
  • socket
)
private

Sends the message to reset the supported commands by the windows notifications client.

Parameters:

  • socket Object

    The client socket

sendStreamingNotificationEvent

(
  • username
  • data
  • socket
)
private

Sends the event to open a desktop notification popup about a streaming source.

Parameters:

  • username String

    The username of the client

  • data Object

    The data about the caller

  • socket Object

    The TCP socket client

setAstProxy

(
  • ap
)

Set the asterisk proxy to be used by the module.

Parameters:

  • ap Object

setAstProxyListeners

() private

Sets the event listeners for the asterisk proxy component.

setCompAuthe

(
  • autheMod
)

Set the authentication module to be used.

Parameters:

  • autheMod Object

    The authentication module.

setCompAuthorization

(
  • comp
)

Sets the authorization module to be used.

Parameters:

  • comp Object

    The authorization module.

setCompConfigManager

(
  • comp
)

Sets the config manager module to be used.

Parameters:

  • comp Object

    The config manager module.

setCompStreaming

(
  • comp
)

Set the streaming module to be used.

Parameters:

  • comp Object

    The streaming module.

setCompUser

(
  • comp
)

Sets the user module to be used.

Parameters:

  • comp Object

    The user module.

setLogger

(
  • log
)
static

Set 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.

socketSend

(
  • socket
  • msg
  • cb
)
private

Send a message.

Parameters:

  • socket Object

    The socket

  • msg Object

    The message

  • cb Function

    The callback function

start

()

Creates the TCP server and adds the listeners for other components.

unauthorized

(
  • socket
)
private

Manage unauthorized access. It send 401 unauthorized response to the client and disconnect the socket.

Parameters:

  • socket Object

    The client socket

updateTokenExpirationOfAllTcpUsers

() private

Update the token expiration of all users that are connected by TCP.

Properties

CALL_NOTIF_TEMPLATE_NAME

String private final

The name of the template file for a call notification popup.

Default: "call.html"

callNotifSize

Object private

The size of the call notification popup. It is customized by the configWinPopup method.

Default: { width: 400, heigth: 96 }

callNotifTemplatePath

String private

The path of the template file for a call notification popup. It is constructed by the config method.

compAstProxy

Object private

The asterisk proxy component.

compAuthe

Object private

The authentication module.

compAuthorization

Object private

The authorization module.

compConfigManager

Object private

The config manager module.

compStreaming

Object private

The streaming component.

compUser

Object private

The user component.

CONFIG_WINPOPUP_FILEPATH

String private

The configuration file path of the windows popup.

ctiProto

String private

The protocol used by the cti server. It is used by the windows popup notification to open the NethCTI application using the configured protocol. It is customized by the configuration file.

Default: "https"

emitter

Object private

The event emitter.

ENCODING

String private final

The enconding used to write the TCP client sockets.

Default: "utf8"

EVT_COLOR_LED

String

The name of the set led color event.

Example:

"setColorLed"

Default: "setColorLed"

EVT_COMMANDS

String

The name of the suported commands event.

Example:

{
   "commands": {
     "url": {
       "command": "url",
       "runwith": ""
     }
   }
}

Default: "commands"

EVT_EXTEN_CONNECTED

String

The name of the extension connected event.

Default: "extenConnected"

EVT_EXTEN_HANGUP

String

The name of the extension hangup event.

Default: "extenHangup"

EVT_NOTIFICATION

String

The name of the extension ringing event.

Example:

{
   "notification": {
     "id": "91200<-202",
     "url": "https://<server>/webrest/...",
     "width": "480",
     "height": "280",
     "action": 'open',
     "closetimeout": "10"
   }
}

Default: "notification"

EVT_PING

String

The name of the ping event.

Example:

{
   "ping": "active"
}

Default: "ping"

EVT_RELOADED

String

The name of the reloaded event.

Example:

"reloaded"

Default: "reloaded"

EVT_USER_PRESENCE_CHANGED

String

The name of the extension presence changed event.

Default: "userPresenceChanged"

IDLOG

String private final

The module identifier used by the logger.

Default: [com_nethcti_tcp]

LED_COLOR_MAPPING

Object private final

The color mapping for nethifier led. The colors are in RGB format and if you want to bliking it append "|blink" at the end.

Default: { ringing: '255:0:0|blink', dnd: '255:0:0', busy: '255:0:0', online: '0:255:0', callForward: '0:0:255', voicemail: '0:0:255', cellphone: '0:0:255' }

logger

Object private

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

Default: console

notifCloseTimeout

String private

The timeout to automatic close notification popup.

Default: 10

notifSupportedCommands

Object private

The supported commands for windows popup notifications. It is initialized by the configWinPopup method.

Default: {}

port

String private

The TCP server port. It is customized by the configuration file.

server

Object private

The TCP server.

sockets

Object private

Contains all client socket of authenticated clients. The key is the client socket identifier and the value is an object containing the socket object and the token of the user.

STREAMING_NOTIF_TEMPLATE_NAME

String private final

The name of the template file for a streaming notification popup.

Default: "streaming.html"

streamingNotifTemplatePath

String private

The path of the template file for a streaming notification popup. It is constructed by the config method.

streamNotifSize

Object private

The size of the streaming notification popup. It is customized by the configWinPopup method.

Default: { width: 400, heigth: 400 }

updateTokenExpirationInterval

Number private

Interval time to automatic update token expiration of all users that are connected by socket.

Events

commands

Emitted to a tcp client with supported commands on login action received.

Event Payload:

  • data Object

    The data about the event

extenConnected

Emitted to a tcp client connection on extension connected on a conversation.

Event Payload:

  • data Object

    The data about the event

    Example:

    { "extenConnected": "223" }

extenHangup

Emitted to a tcp client connection on extension hangup.

Event Payload:

  • data Object

    The data about the event

    Example:

    { "extenHangup": "223" }

notification

Emitted to a tcp client connection on extension ringing.

Event Payload:

  • data Object

    The data about the event

ping

Emitted to a tcp client connection on action ping received.

Event Payload:

  • data Object

    The data about the event

reloaded

Fired when the componente has been reloaded.

setColorLed

Fired when the nethifier led has to be set.

userPresenceChanged

Emitted to a tcp client connection on extension presence changed.

Event Payload:

  • data Object

    The data about the event

    Example:

    { presence: { username: 'andrea', status: 'dnd' } }