API Docs for:
Show:

com_nethcti_ws Class

Module: com_nethcti_ws

Core module that communicates with the clients using websocket.

Item Index

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

doLogin

(
  • socket
  • obj
)
private

Does the login.

Parameters:

  • socket Object

    The client websocket

  • obj Object

    The data passed by the client

    • accessKeyId String

      The username of the account

    • token String

      The token received by the authentication REST request

    • [uaType] String optional

      The user agent type ("mobile" | "desktop")

evtStreamingSourceChanged

(
  • evt
)
private

Handler for the evtStreamingSourceChanged event emitted by streaming component. The streaming source image has been changed, so notifies all clients.

Parameters:

  • evt Object
    • source String

      The streaming source

    • image String

      The streaming image in base64 format

evtStreamingSourceSubscribed

(
  • evt
)
private

Handler for the evtStreamingSourceSubscribed event emitted by streaming component. The streaming source has been subscribed, so handle streaming sources rooms.

Parameters:

  • evt Object
    • username String

      The username to subscribe with

    • streamId String

      The streaming source identifier

evtStreamingSourceUnsubscribed

(
  • evt
)
private

Handler for the evtStreamingSourceUnsubscribed event emitted by streaming component. The streaming source has been unsubscribed, so handle streaming sources rooms.

Parameters:

  • evt Object
    • username String

      The username to subscribe with

    • streamId String

      The streaming source identifier

evtUserPresenceChanged

(
  • evt
)
private

Handler for the userPresenceChanged event emitted by user component. The user presence has changed, so notifies all clients.

Parameters:

  • evt Object
    • username String

      The username

    • presence String

      The presence status of the user

evtUserProfileAvatarChanged

(
  • evt
)
private

Handler for the evtUserProfileAvatarChanged event emitted by user component. The user avatar picture has been changed, so notifies all clients.

Parameters:

  • evt Object
    • username String

      The username

    • avatar String

      The avatar picture in base64 format

extenChanged

(
  • exten
)
private

Handler for the extenChanged event emitted by astproxy component. Something has changed in the extension, so notifies all interested clients.

Parameters:

  • exten Object

    The extension object

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 Object

      The identity data of the caller

    • callerHasConf Boolean

      True if the caller has an active conference

extenHangup

(
  • data
)
private

Handler for the extenHangup event emitted by astproxy component.

Parameters:

  • data Object

    The extension hangup data object

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
  • obj
)
private

Websocket login handler.

Parameters:

  • socket Object

    The client websocket

  • obj Object

    The data passed by the client

    • accessKeyId String

      The username of the account

    • token String

      The token received by the authentication REST request

    • [uaType] String optional

      The user agent type ("mobile" | "desktop")

meetmeConfChanged

(
  • conf
)
private

Handler for the astProxy.EVT_MEETME_CONF_CHANGED event emitted by astproxy 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 astproxy 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.

onDestroy

()

Handle the module destroy process.

parkingChanged

(
  • parking
)
private

Handler for the parkingChanged event emitted by astproxy 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 astproxy 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 astproxy component. Something has changed in the queue member, so notifies all interested clients.

Parameters:

  • member Object

    The queue member object

reload

() private

Reload the component.

removeWebsocketId

(
  • socketId
)

Removes the client websocket identifier from the private object wsid.

Parameters:

  • socketId String

    The client websocket identifier private

reset

() private

Reload the component.

send401

(
  • socket
)
private

Send 401 unauthorization response through websocket.

Parameters:

  • socket Object

    The client websocket

sendAllCompReloaded

()

Send an event to all the clients to inform them about all components reloaded.

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
  • [fnData]
)

It sends an event to all the local websocket clients. It accepts also a function to be verified before performing the send and an optional function to manipulate data before 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

  • [fnData] Function optional

    The function to be passed to perform the data manipulation. It will be called passing the "username" associated with websocket and the data event

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

(
  • comp
)

Set the asterisk proxy to be used by the module.

Parameters:

  • comp Object

    The asterisk proxy component

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.

setCompStreaming

(
  • comp
)

Sets the streaming module to be used.

Parameters:

  • comp Object

    The user module.

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.

setStreamingListeners

() private

Sets the event listeners for the streaming 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 server (http) and adds the listeners for other components.

startWsServer

() private

Creates the websocket server unsecure listening on localhost.

trunkChanged

(
  • trunk
)
private

Handler for the trunkChanged event emitted by astproxy 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).

wsConnHdlr

(
  • socket
)
private

Websocket (http) 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.

compStreaming

Object private

The streaming component.

compUser

Object private

The user component.

compVoicemail

Object private

The voicemail architect component used for voicemail functions.

CONFIG_PRIVACY_FILEPATH

String private

The configuration file path of the privacy.

emitter

Object private

The event emitter.

EVT_ALL_WS_CLIENT_DISCONNECTION

String

The name of the client websocket disconnection event.

Default: "allWsClientDisonnection"

EVT_CALL_WEBRTC

String

The name of the event to call number using WebRTC extension

EVT_EXTEN_CONNECTED

String

The name of the extension connected event.

Default: "extenConnected"

EVT_EXTEN_UPDATE

String

The name of the extension update event.

Default: "extenUpdate"

EVT_MEETME_CONF_END

String

The name of the meetme conference end event.

Default: "meetmeConfEnd"

EVT_MEETME_CONF_UPDATE

String

The name of the meetme conference update event.

Default: "meetmeConfUpdate"

EVT_PARKING_UPDATE

String

The name of the parking update event.

Default: "parkingUpdate"

EVT_QUEUE_MEMBER_UPDATE

String

The name of the queue member update event.

Default: "queueMemberUpdate"

EVT_QUEUE_UPDATE

String

The name of the queue update event.

Default: "queueUpdate"

EVT_RELOADED

String

The name of the reloaded event.

Default: "reloaded"

EVT_SERVER_RELOADED

String

The name of the all component reloaded

Default: "serverReloaded"

EVT_STREAMING_SOURCE_UPDATE

String

The name of the streaming source update event.

Default: "streamingSourceUpdate"

EVT_TRUNK_UPDATE

String

The name of the trunk update event.

Default: "trunkUpdate"

EVT_USER_PRESENCE_UPDATE

String

The name of the user presence update event.

Default: "userPresenceUpdate"

EVT_USER_PROFILE_AVATAR_UPDATE

String

The name of the user profile avatar update event.

Default: "userProfileAvatarUpdate"

EVT_WS_CLIENT_CONNECTED

String

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

Default: "wsClientConnected"

EVT_WS_CLIENT_LOGGEDIN

String

The name of the client logged in event.

Default: "wsClientLoggedIn"

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.

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"

USER_AGENT_TYPE

Object private final

The user agent type used to recognize cti client application. The user agent type is set to the socket properties when client login (loginHdlr).

Default: { "MOBILE": "mobile", "DESKTOP": "desktop" }

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). 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 unsecure server port.

wsServer

Object private

The websocket server unsecure (http).

Events

callWebrtc

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

Example:

"0721405516"

Event Payload:

  • to String

    The destination number to be called using WebRTC extension

evtStreamingSourceUpdate

Emitted to a websocket client connection on a streaming source update event.

{ "source": "vs_gate1", "image": "1234abcdef..." }

Event Payload:

  • data Object

    The data about the streaming source update event

extenConnected

Emitted to the extension involved in a connected conversation.

Example:

{ "extenConnected": "223" }

Event Payload:

  • data Object

    The data about the event

extenUpdate

Emitted to a websocket client connection on extension update.

Example:

                    {
                       "ip": "",
                       "cf": "",
                       "dnd": false,
                       "cfVm": "",
                       "port": "",
                       "name": "user",
                       "exten": "602",
                       "status": "offline",
                       "chanType": "sip",
                       "sipuseragent": "",
                       "conversations": { Conversation.toJSON() }
                    }

Event Payload:

  • exten Object

    The data about the extension

meetmeConfEnd

Emitted to a websocket client connection on a meetme conference end event.

{ id: "201" }

Event Payload:

  • data Object

    The data about the meetme conference end event

meetmeConfUpdate

Emitted to a websocket client connection on a meetme conference update event.

                    {
                     "id": "201",
                     "users": {
                       "201": {
                         "id": "1",
                         "name": "John",
                         "owner": false,
                         "muted": false,
                         "extenId": "201"
                       }
                     }

Event Payload:

  • data Object

    The data about the meetme conference update event

parkingUpdate

Emitted to a websocket client connection on parking update.

Example:

                    {
                       "name": "71",
                       "parking": "71"
                       "timeout": 45
                       "parkedCaller": { ParkedCaller.toJSON() }
                    }

Event Payload:

  • parking Object

    The data about the parking

queueMemberUpdate

Emitted to a websocket client connection on queue member update.

Example:

                    {
                       "type":                   "static",
                       "name":                   "Name",
                       "queue":                  "401",
                       "member":                 "214",
                       "paused":                 true,          // the paused status
                       "loggedIn":               true,          // if the member is logged in or not
                       "callsTakenCount":        0,             // the number of taken calls
                       "lastCallTimestamp":      1365590191     // the timestamp of the last taken call
                       "lastPausedInReason":     "some reason"  // the reason description of the last started pause
                       "lastPausedInTimestamp":  1365591191     // the timestamp of the last started pause
                       "lastPausedOutTimestamp": 1365594191     // the timestamp of the last ended pause
                    }

Event Payload:

  • queueMember Object

    The data about the queue member

queueUpdate

Emitted to a websocket client connection on queue update.

Example:

                    {
                       "name":                   "Coda401",
                       "queue":                  "401",
                       "members":                { QueueMember.toJSON() } // the keys is the extension numbers
                       "avgHoldTime":            "37"
                       "avgTalkTime":            "590",
                       "waitingCallers":         { QueueWaitingCaller.toJSON() } // the keys is the channel identifier
                       "abandonedCallsCount":    "26",
                       "completedCallsCount":    "11"
                       "serviceLevelTimePeriod": "60"
                       "serviceLevelPercentage": "100.0"
                    }

Event Payload:

  • queue Object

    The data about the queue

reloaded

Fired when the componente has been reloaded.

serverReloaded

Emitted to a websocket client connection on all components reloaded.

trunkUpdate

Emitted to a websocket client connection on trunk update.

Example:

                    {
                       "ip": "",
                       "port": "",
                       "name": "",
                       "exten": "2001",
                       "status": "offline",
                       "chanType": "sip",
                       "maxChannels": 4,
                       "sipuseragent": "",
                       "conversations": { Conversation.toJSON() }
                    }

Event Payload:

  • trunk Object

    The data about the trunk

userPresenceUpdate

Emitted to a websocket client connection on a user presence update. The event can contains three different keys: "presence", "presence_onbusy" or "presence_onunavailable".

The "presence" is the presence status of the user.

The "presence_onbusy" is the presence status of the user when he is busy in a conversation.

The "presence_onunavailable" is the presence status of the user when he does not answer to an incoming call.

Example:

                    {
                      "presence": {
                        "username": "ale",
                        "status": "dnd"
                      }
                    }
                    
                    {
                      "presence_onbusy": {
                        "username": "ale",
                        "status": "callforward",
                        "to": "190"
                      }
                    }
                    
                    {
                      "presence_onunavailable": {
                        "username": "ale",
                        "status": "callforward",
                        "to": "190"
                      }
                    }

Event Payload:

  • data Object

    The data about the user presence update

userProfileAvatarUpdate

Emitted to a websocket client connection on a user profile avatar update.

{ "username": "ale", "avatar": "1234abcdef..." }

Event Payload:

  • data Object

    The data about the user profile avatar update

wsClientConnected

Fired when a client websocket has been connected.

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.