API Docs for: 2.6
Show:

com_nethcti_remotes Class

Core module that communicates with remote sites using websocket.

Item Index

Methods

addWebsocketId

(
  • user
  • token
  • socketId
  • siteName
  • socket
)

Adds the client websocket identifier into the private object wsid. If it already exists it will be overwritten.

Parameters:

  • user String

    The user used as key

  • token String

    The access token

  • socketId String

    The client websocket identifier to store in the memory

  • siteName String

    The remote site name

  • socket Object

    The connected socket private

badRequest

(
  • socket
)

Send response to the client for bad request received.

Parameters:

  • socket Object

    The client websocket.

clientRestApiLogin

(
  • clientWss
  • site
)
private

Does the login through the rest api to obtain a nonce to construct the authentication token.

Parameters:

  • clientWss Object

    The client websocket socket secure connected to remote site

  • site String

    The remote site name

clientWss401Hdlr

(
  • data
  • site
  • address
  • clientWss
)
private

Handler for a failed login operation through client websocket.

Parameters:

  • data Object

    The data received from the event

  • site String

    The site name

  • address String

    The remote site address

  • clientWss Object

    The client websocket secure

clientWssConnecting

(
  • site
  • address
)
private

Handler for a client websocket connecting.

Parameters:

  • site String

    The remote site name

  • address String

    The remote site address

clientWssConnHdlr

(
  • clientWss
  • site
  • address
)
private

Handler for a client websocket connection.

Parameters:

  • clientWss Object

    The secure client websocket

  • site Site

    The remote site name

  • address String

    The url rest api

clientWssDisconnectHdlr

(
  • site
  • address
  • clientWss
)
private

Handler for a client websocket disconnection.

Parameters:

  • site String

    The site name

  • address String

    The remote site address

  • clientWss Object

    The client websocket secure

clientWssError

(
  • err
  • site
  • address
  • clientWss
)
private

Handler for a client websocket error.

Parameters:

  • err Object

    The error object

  • site String

    The remote site name

  • address String

    The remote site address

  • clientWss Object

    The client websocket secure

clientWssLoggedInHdlr

(
  • data
  • clSocket
  • site
  • address
)
private

Handler for a successful logged in through a client websocket.

Parameters:

  • data Object

    The data received from the event

  • clSocket Object

    The client socket connected to remote site

    • ctiTokenAuthe String

      The authentication token

  • site String

    The site name

  • address String

    The remote site address

clientWssReconnect

(
  • site
  • address
  • clientWss
)
private

Handler for a client websocket reconnection.

Parameters:

  • site String

    The remote site name

  • address String

    The remote site address

  • clientWss Object

    The client websocket secure

clientWssReconnecting

(
  • site
  • address
  • clientWss
)
private

Handler for a client websocket reconnection

Parameters:

  • site String

    The remote site name

  • address String

    The remote site address

  • clientWss Object

    The client websocket secure

clientWssRemoteEndpointPresenceUpdateHdlr

(
  • data
  • site
)
private

Handler of a remote endpoint presence update received from a remote site.

Parameters:

  • data Object

    The data received from the event

  • site String

    The site name

clientWssRemoteExtenUpdateHdlr

(
  • data
  • site
)
private

Handler of a remote extension update received from a remote site.

Parameters:

  • data Object

    The data received from the event

  • site String

    The site name

config

(
  • path
)

Configures the properties used by the component by a configuration file. The file must use the JSON syntax.

Parameters:

  • path String

    The path of the configuration file

connectAllRemoteSites

() private

Connects to all remote sites configured.

connectRemoteSite

(
  • site
  • opts
)
private

Connects to a remote sites configured.

Parameters:

  • site String

    The remote site name

  • opts Object

    The options used by websocket connection

disconnHdlr

(
  • socket
)
private

Websocket disconnection handler.

Parameters:

  • socket Object

    The client websocket

endpointPresenceChangedListener

(
  • username
  • endpointType
  • endpoint
)
private

Handler for the endpointPresenceChanged event emitted by user component. The endpoint presence has changed, so notifies all remote sites.

Parameters:

  • username String

    The username of the endpoint owner

  • endpointType String

    The type of the updated endpoint

  • endpoint Object

    The updated endpoint of the user

extenChanged

(
  • exten
)
private

Handler for the extenChanged event emitted by ast_proxy component. Something has changed in the extension, so notifies all remote sites.

Parameters:

  • exten Object

    The extension object

getAllRemoteSites

() Object

Returns the list of all remote sites status data.

Returns:

Object:

The list of all remote sites status data

getAllRemoteSitesOperatorExtensions

() Object

Returns the perator panel extensions of all remote sites.

Returns:

Object:

Operator panel extensions of all remote sites.

getAllRemoteSitesOperatorGroups

() Object

Returns the operator panel groups of all remote sites.

Returns:

Object:

Operator panel groups of all remote sites.

getAllRemoteSitesUserEndpoints

() Object

Returns the user endpoints of all remote sites.

Returns:

Object:

User endpoints of all remote sites.

getAllRemoteSitesUsernames

() Object

Returns the usernames of all remote sites.

Returns:

Object:

Usernames of all remote sites.

getAllSitesPrefixCall

() Object

Returns the prefix of all remote sites.

Returns:

Object:

The keys are the remote site names and the values the corresponding prefixes.

getNumConnectedClients

(
  • The
)
private

Returns the number of connected clients.

Parameters:

  • The Number

    number of connected clients.

getRandomIntInclusive

(
  • min
  • max
)
Number private

Returns a random integer between min (included) and max (included) using Math.round() will give you a non-uniform distribution!

Parameters:

  • min Number

    Start interval number

  • max Number

    End interval number

Returns:

Number:

A random integer number between min (included) and max (included)

getRemoteSiteStatus

(
  • site
)
Object private

Returns the status data about the remote site.

Parameters:

  • site String

    The remote site name

Returns:

Object:

The status data about the remote site.

getSiteName

(
  • username
  • token
)
String

Check if the user is an authenticated remote site that has already logged in.

Parameters:

  • username String

    The username of the remote site

  • token String

    The authentication token used by remote site

Returns:

String:

The name of the remote site.

getSitePrefixCall

(
  • site
)
String

Returns the prefix used to call the extensions of the remote site.

Parameters:

  • site String

    The name of the remote site

Returns:

String:

The prefix used to call the remote site.

getWebsocketEndpoint

(
  • socket
)
String private

Return the endpoint of the websocket. The endpoint is constructed by ip_address:port.

Parameters:

  • socket Object

    The websocket

Returns:

String:

The websocket endpoint as ip_address:port.

isClientRemote

(
  • username
  • token
)
Boolean

Check if the user is an authenticated remote site that has already logged in.

Parameters:

  • username String

    The username of the remote site

  • token String

    The authentication token used by remote site

Returns:

Boolean:

True if the remote site username has already logged in.

loginHdlr

(
  • socket
  • data
)
private

Websocket login handler.

Parameters:

  • socket Object

    The client websocket

  • data Object

    The data passed by the client

    • accessKeyId String

      The username of the account

    • token String

      The token received by the authentication REST request

newRemotePostit

(
  • data
  • cb
)

Creates a new post-it for a remote user of a remote site.

Parameters:

  • data Object

    The object with parameters

    • creator String

      The username of the creator

    • site String

      The remote site name

    • recipient String

      The recipient username

    • text String

      The text of the message

  • cb String

    The callback function

remoteSiteExists

() Boolean

Checks if a remote site exists.

Returns:

Boolean:

True if the remote site exists

removeWebsocketId

(
  • socketId
)

Removes the client websocket identifier from the private object wsid.

Parameters:

  • socketId String

    The client websocket identifier private

restApi

(
  • site
  • url
  • method
  • headers
  • data
  • cb
)
private

Does a generic rest api call.

Parameters:

  • site String

    The remote site name

  • url String

    The url to be called

  • method String

    The request method (GET or POST)

  • headers Object

    The headers to be added to the request

  • data Object

    The data to be passed

  • cb Function

    The callback function

restApiSiteOpExtensions

(
  • site
  • cb
)
private

Gets all the extensions from the specified remote site.

Parameters:

  • site String

    The remote site name

  • cb Function

    The callback function

restApiSiteOpGroups

(
  • site
  • cb
)
private

Gets all the operator group panels from the specified remote site.

Parameters:

  • site String

    The remote site name

  • cb Function

    The callback function

restApiSiteUserEndpoint

(
  • site
  • cb
)
private

Gets all the user endpoints from the specified remote site.

Parameters:

  • site String

    The remote site name

  • cb Function

    The callback function

restApiSiteUsernames

(
  • site
  • cb
)
private

Gets all the usernames from the specified remote site.

Parameters:

  • site String

    The remote site name

  • cb Function

    The callback function

send401

(
  • socket
)
private

Send 401 unauthorization response through websocket.

Parameters:

  • socket Object

    The client websocket

sendAutheSuccess

(
  • socket
)
private

Send authorized successfully response through websocket.

Parameters:

  • socket Object

    The client websocket

sendClientWssRemoteSiteUpdateStatus

(
  • site
)
private

Updates all local clients about the status data of the remote site.

Parameters:

  • site String

    The remote site name

sendError

(
  • socket
  • [obj]
)

Send the error result to the client.

It can throw an Exception.

Parameters:

  • socket Object

    The client websocket

  • [obj] String optional

    The object to send

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.

setAuthe

(
  • autheMod
)

Set the authentication module to be used.

Parameters:

  • autheMod Object

    The authentication module.

setComNethctiWsListeners

() private

Sets the event listeners for the websocket communication component.

setCompAuthorization

(
  • comp
)

Sets the authorization module to be used.

Parameters:

  • comp Object

    The authorization module.

setCompComNethctiWs

(
  • comp
)

Sets the websocket communication module to be used.

Parameters:

  • comp Object

    The module.

setCompPostit

(
  • comp
)

Sets post-it architect component.

Parameters:

  • comp Object

    The post-it architect component.

setCompUser

(
  • comp
)

Sets the user module to be used.

Parameters:

  • comp Object

    The user module.

setCompVoicemail

(
  • cv
)

Sets voicemail architect component used by voicemail functions.

Parameters:

  • cv Object

    The voicemail architect component.

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.

setPostitListeners

() private

Sets the event listeners for the post-it component.

setUserListeners

() private

Sets the event listeners for the user component.

setVoicemailListeners

() private

Sets the event listeners for the voicemail component.

start

()

Starts the component connecting to all remote sites configured and adds the listeners for other components.

unauthorized

(
  • socket
)
private

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

Parameters:

  • socket Object

    The client websocket

updateNewPostitListener

(
  • recipient
  • list
)
private

Manages the event emitted by the post-it component to update the new post-it messages. It send all new post-it to the recipient user.

Parameters:

  • recipient String

    The recipient user of the new post-it

  • list Array

    All the new post-it messages of the user

updateNewVoiceMessagesListener

(
  • voicemail
  • list
)
private

Manages the new voicemail event emitted by the voicemail component. It sends all new voice messages of the voicemail to all users who use the voicemail.

Parameters:

  • voicemail String

    The voicemail identifier

  • list Array

    The list of all new voicemail messages

updateTokenExpirationOfAllWebsocketUsers

() private

Update the token expiration of remote sites that are connected by wss.

wssConnHdlr

(
  • socket
)
private

Websocket secure (https) connection handler.

Parameters:

  • socket Object

    The client websocket.

wssLogin

(
  • clientWss
  • user
  • hostname
)
private

Does login operation through websocket to a remote site.

Parameters:

  • clientWss Object

    The client socket connected to remote site

    • ctiTokenAuthe String

      The authentication token

  • user String

    The username

  • hostname String

    The remote hostname

Properties

allSitesOpExtensions

Object private

Contains all operator extensions of all remote sites.

Default: {}

allSitesOpGroups

Object private

Contains all operator panel groups of all remote sites.

Default: {}

allSitesUserEndpoints

Object private

Contains all user endpoints of all remote sites.

Default: {}

allSitesUsernames

Object private

Contains all usernames of all remote sites.

Default: {}

astProxy

Object private

The asterisk proxy.

compAuthe

Object private

The authentication module.

compAuthorization

Object private

The authorization module.

compComNethctiWs

Object private

The websocket communication module.

compPostit

Object private

The post-it architect component.

compUser

Object private

The user component.

compVoicemail

Object private

The voicemail architect component used for voicemail functions.

CONNECTION_TIMEOUT

Number private final

Remote connection timeout.

Default: 10000

EVT_REMOTE_ENDPOINT_PRESENCE_UPDATE

String

The name of the remote endpoint presence update event.

Default: "remoteEndpointPresenceUpdate"

EVT_REMOTE_EXTEN_UPDATE

String

The name of the remote extension update event.

Default: "remoteExtenUpdate"

EVT_REMOTE_SITE_UPDATE

String

The name of the remote site update event.

Default: "remoteSiteUpdate"

IDLOG

String private final

The module identifier used by the logger.

Default: [com_nethcti_remotes]

logger

Object private

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

Default: console

MAX_RANDOM_DELAY

Number private final

Maximum amount of time used to product a random number used for reconnection attempts.

Default: 5000

MAX_RECONNECTION_DELAY

Number private final

Maximum delay waited between two reconnection attempts to a remote site. It is incremented by a random amount of time between 0 and MAX_RANDOM_DELAY.

Default: 60000

remoteSites

Object private

Contains remote sites to be connected. It is populated by JSON configuration file.

REST_PROTO

String private

The protocol to be used for rest api calls.

Default: "https"

updateTokenExpirationInterval

Number private

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

wsid

Object private

Contains all the secure websocket of authenticated remote sites. The keys are the websocket identifiers and the values are objects containing:

  • username
  • token
  • remote site name
  • socket object

It is used for fast authentication for each request.

wssClients

Object private

Contains all client websockets logged into the remote sites. The keys are the remote site names and the values are the respective websocket objects.

Default: {}

Events

remoteEndpointPresenceUpdate

Emitted to all websocket client connection on user endpoint presence update.

Event Payload:

  • data Object

    The data about the user endpoint presence

remoteExtenUpdate

Emitted to all websocket client connection on remote extension update.

Event Payload:

  • obj Object

    The data about the remote extension

    • remoteSite Object

      The remote site name

    • data Object

      The extension data

remoteSiteUpdate

Emitted to a all websocket client connection on remote site update.

Event Payload:

  • obj Object

    The data about the remote site

    • remoteSite Object

      The remote site name

    • data Object

      The remote site data