API Docs for: 2.6
Show:

com_nethcti_ws Class

Module: com_nethcti_ws

Core module that communicates with the clients using websocket.

Methods

addWebsocketId

(
  • user
  • token
  • socketId
)

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 private

badRequest

(
  • socket
)

Send response to the client for bad request received.

Parameters:

  • socket Object

    The client websocket.

config

(
  • path
)

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

Parameters:

  • path String

    The path of the configuration file

configPrivacy

(
  • path
)

Customize the privacy used to hide phone numbers by a configuration file. The file must use the JSON syntax.

Parameters:

  • path String

    The path of the configuration file

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

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 interested clients.

Parameters:

  • exten Object

    The extension object

extenDialing

(
  • data
)
private

Handler for the extenDialing event emitted by ast_proxy 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 Object

      The identity data of the caller

getFilteredCallerIndentity

(
  • username
  • callerIdentity
)
Object private

Returns identity data of the caller filtered by user authorizations. Returned caller notes are those all of the user and the publics of the others if he has only the "postit" authorization and all the caller notes if he has the "admin postit" authorization. Phonebook contacts returned is the one created by the user in the cti phonebook, or one from the centralized phonebook or a public contact created by other users in the cti address book.

Parameters:

  • username String

    The username

  • callerIdentity Object

    The identity of the caller to be filtered

Returns:

Object:

The filtered caller identity.

getNumConnectedClients

(
  • The
)
private

Returns the number of connected clients.

Parameters:

  • The Number

    number of connected clients.

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.

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

meetmeConfChanged

(
  • conf
)
private

Handler for the astProxy.EVT_MEETME_CONF_CHANGED event emitted by ast_proxy component. Something has changed in the meetme conference, so notifies all clients associated with the conference extension.

Parameters:

  • conf Object

    The conference object

meetmeConfEnd

(
  • confId
)
private

Handler for the astProxy.EVT_MEETME_CONF_END event emitted by ast_proxy component. A meetme conference has been ended, so notifies all clients associated with the conference extension.

Parameters:

  • confId String

    The conference identifier

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.

parkingChanged

(
  • parking
)
private

Handler for the parkingChanged event emitted by ast_proxy component. Something has changed in the parking, so notifies all interested clients.

Parameters:

  • parking Object

    The parking object

queueChanged

(
  • queue
)
private

Handler for the queueChanged event emitted by ast_proxy component. Something has changed in the queue, so notifies all interested clients.

Parameters:

  • queue Object

    The queue object

queueMemberChanged

(
  • member
)
private

Handler for the queueMemberChanged event emitted by ast_proxy component. Something has changed in the queue member, so notifies all interested clients.

Parameters:

  • member Object

    The queue member object

removeWebsocketId

(
  • socketId
)

Removes the client websocket identifier from the private object wsid.

Parameters:

  • socketId String

    The client websocket identifier private

send401

(
  • socket
)
private

Send 401 unauthorization response through websocket.

Parameters:

  • socket Object

    The client websocket

sendAnswerWebrtcToClient

(
  • username
  • extenId
)

Sends an event to the client to answer the incoming call of webrtc extension.

Parameters:

  • username String

    The name of the client user

  • extenId String

    The extension identifier

sendAutheSuccess

(
  • socket
)
private

Send authorized successfully response through websocket.

Parameters:

  • socket Object

    The client websocket

sendCallWebrtcToClient

(
  • username
  • to
)

Sends an event to the client to call the number using webrtc extension.

Parameters:

  • username String

    The name of the client user

  • to String

    The destination number to be called using client webrtc phone

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

sendEventToAllClients

(
  • evname
  • data
  • fn
)

It send an event to all the local websocket clients. It accepts also an optional function to be verified before perform the sending.

Parameters:

  • evname String

    The event name

  • data Object

    The event data object

  • fn Function

    The function to be passed to perform the sending. It will be called passing the "username" associated with websocket

sendEvtToUserWithExtenId

(
  • evtName
  • evtObj
  • extenId
)
private

Sends the event only to users with associated extension.

Parameters:

  • evtName String

    The name of the event

  • evtObj Object

    The event data object

  • extenId String

    The extension identifier

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.

setCompAuthorization

(
  • comp
)

Sets the authorization module to be used.

Parameters:

  • comp Object

    The authorization 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

()

Creates the websocket servers (http and https) and adds the listeners for other components.

startWsServer

() private

Creates the websocket server (http) and adds the listeners for other components.

startWssServer

() private

Creates the websocket server secure (https) and adds the listeners for other components.

trunkChanged

(
  • trunk
)
private

Handler for the trunkChanged event emitted by ast_proxy component. Something has changed in the trunk, so notifies all interested clients.

Parameters:

  • trunk Object

    The trunk object

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 all users that are connected by websocket (http and https).

wsConnHdlr

(
  • socket
)
private

Websocket (http) connection handler.

Parameters:

  • socket Object

    The client websocket.

wssConnHdlr

(
  • socket
)
private

Websocket secure (https) connection handler.

Parameters:

  • socket Object

    The client websocket.

Properties

astProxy

Object private

The asterisk proxy.

compAuthe

Object private

The authentication module.

compAuthorization

Object private

The authorization 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.

emitter

Object private

The event emitter.

EVT_ALL_WS_CLIENT_DISCONNECTION

String

The name of the client websocket disconnection event.

Default: "allWsClientDisonnection"

EVT_ANSWER_WEBRTC

String

The name of the event for answer webrtc extension

Default: "answerWebrtc"

EVT_CALL_WEBRTC

String

The name of the event to call number using WebRTC extension

Default: "callWebrtc"

EVT_ENDPOINT_PRESENCE_UPDATE

String

The name of the endpoint presence update event.

Default: "endpointPresenceUpdate"

EVT_EXTEN_UPDATE

String

The name of the extension update event.

Default: "extenUpdate"

EVT_WS_CLIENT_LOGGEDIN

String

The name of the client logged in event.

Default: "wsClientLoggedIn"

EVT_WSS_CLIENT_CONNECTED

String

The name of the event emitted when a client websocket has been connected.

Default: "wssClientConnected"

HTTPS_CERT

String private

The path of the certificate to be used by HTTPS server. It can be customized in the configuration file.

Default: "/etc/pki/tls/certs/localhost.crt"

HTTPS_KEY

String private

The path of key to be used by HTTPS server. It can be customized in the configuration file.

Default: "/etc/pki/tls/private/localhost.key"

IDLOG

String private final

The module identifier used by the logger.

Default: [com_nethcti_ws]

logger

Object private

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

Default: console

privacyStrReplace

String private final

The string used to hide phone numbers in privacy mode.

Default: "xxx"

updateTokenExpirationInterval

Number private

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

USER_AGENT

String private final

The user agent used to recognize cti client application. The user agent is set to the socket properties when client login (loginHdlr) and checked when disconnect (disconnHdlr) to set the offline presence of the client user.

Default: "nethcti"

WS_LOG_LEVEL

Number private final

The log level of the websocket library. Log only the errors by default.

Default: 0

WS_ROOM

Object private final

The websocket rooms used to update clients with asterisk events.

Default: { AST_EVT_CLEAR: "ast_evt_clear", AST_EVT_PRIVACY: "ast_evt_privacy" }

wsid

Object private

Contains all websocket identifiers of authenticated clients (http and https). The key is the websocket identifier and the value is an object containing the username and the token of the user. It's used for fast authentication for each request.

wsPort

String private

The websocket server port.

wsServer

Object private

The websocket server (http).

wssPort

String private

The websocket secure server port.

wssServer

Object private

The websocket server secure (https).

Events

answerWebrtc

Emitted to a websocket client connection to answer an incoming call to webrtc extension.

Event Payload:

  • exten String

    The WebRTC extension identifier

callWebrtc

Emitted to a websocket client connection to call a number using webrtc extension.

Event Payload:

  • to String

    The destination number to be called using WebRTC extension

endpointPresenceUpdate

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

Event Payload:

  • data Object

    The data about the user endpoint presence

extenUpdate

Emitted to a websocket client connection on extension update.

Event Payload:

  • exten Object

    The data about the extension

wsClientDisonnection

Fired when a websocket client connection has been closed.

Event Payload:

  • username String

    The name of the user that has closed the connection

wsClientLoggedIn

Fired when a client has been logged in by a websocket connection.

Event Payload:

  • username String

    The name of the user that has been logged in.

wssClientConnected

Fired when a client websocket has been connected.