com_nethcti_ws Class
Core module that communicates with the clients using websocket.
Item Index
Methods
- addWebsocketId
- badRequest
- config
- configPrivacy
- disconnHdlr
- doLogin
- evtStreamingSourceChanged
- evtStreamingSourceSubscribed
- evtStreamingSourceUnsubscribed
- evtUserPresenceChanged
- evtUserProfileAvatarChanged
- extenChanged
- extenConnected
- extenDialing
- extenHangup
- getFilteredCallerIndentity
- getNumConnectedClients
- getWebsocketEndpoint
- loginHdlr
- meetmeConfChanged
- meetmeConfEnd
- on
- onDestroy
- parkingChanged
- queueChanged
- queueMemberChanged
- reload
- removeWebsocketId
- reset
- send401
- sendAllCompReloaded
- sendAnswerWebrtcToClient
- sendAutheSuccess
- sendCallWebrtcToClient
- sendError
- sendEventToAllClients
- sendEvtToUserWithExtenId
- setAstProxy
- setAstProxyListeners
- setAuthe
- setCompAuthorization
- setCompPostit
- setCompStreaming
- setCompUser
- setCompVoicemail
- setLogger static
- setPostitListeners
- setStreamingListeners
- setUserListeners
- setVoicemailListeners
- start
- startWsServer
- trunkChanged
- unauthorized
- updateNewPostitListener
- updateNewVoiceMessagesListener
- updateTokenExpirationOfAllWebsocketUsers
- wsConnHdlr
Properties
- astProxy
- compAuthe
- compAuthorization
- compPostit
- compStreaming
- compUser
- compVoicemail
- CONFIG_PRIVACY_FILEPATH
- emitter
- EVT_ALL_WS_CLIENT_DISCONNECTION
- EVT_CALL_WEBRTC
- EVT_EXTEN_CONNECTED
- EVT_EXTEN_UPDATE
- EVT_MEETME_CONF_END
- EVT_MEETME_CONF_UPDATE
- EVT_PARKING_UPDATE
- EVT_QUEUE_MEMBER_UPDATE
- EVT_QUEUE_UPDATE
- EVT_RELOADED
- EVT_SERVER_RELOADED
- EVT_STREAMING_SOURCE_UPDATE
- EVT_TRUNK_UPDATE
- EVT_USER_PRESENCE_UPDATE
- EVT_USER_PROFILE_AVATAR_UPDATE
- EVT_WS_CLIENT_CONNECTED
- EVT_WS_CLIENT_LOGGEDIN
- IDLOG
- logger
- privacyStrReplace
- updateTokenExpirationInterval
- USER_AGENT
- USER_AGENT_TYPE
- WS_LOG_LEVEL
- WS_ROOM
- wsid
- wsPort
- wsServer
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
StringThe user used as key
-
token
StringThe access token
-
socketId
StringThe client websocket identifier to store in the memory private
badRequest
-
socket
Send response to the client for bad request received.
Parameters:
-
socket
ObjectThe client websocket.
config
-
path
Configurates the websocket server properties by a configuration file. The file must use the JSON syntax.
Parameters:
-
path
StringThe 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
StringThe path of the configuration file
disconnHdlr
-
socket
Websocket disconnection handler.
Parameters:
-
socket
ObjectThe client websocket
doLogin
-
socket
-
obj
Does the login.
Parameters:
-
socket
ObjectThe client websocket
-
obj
ObjectThe data passed by the client
-
accessKeyId
StringThe username of the account
-
token
StringThe token received by the authentication REST request
-
[uaType]
String optionalThe user agent type ("mobile" | "desktop")
-
evtStreamingSourceChanged
-
evt
Handler for the evtStreamingSourceChanged event emitted by streaming component. The streaming source image has been changed, so notifies all clients.
Parameters:
-
evt
Object-
source
StringThe streaming source
-
image
StringThe streaming image in base64 format
-
evtStreamingSourceSubscribed
-
evt
Handler for the evtStreamingSourceSubscribed event emitted by streaming component. The streaming source has been subscribed, so handle streaming sources rooms.
Parameters:
-
evt
Object-
username
StringThe username to subscribe with
-
streamId
StringThe streaming source identifier
-
evtStreamingSourceUnsubscribed
-
evt
Handler for the evtStreamingSourceUnsubscribed event emitted by streaming component. The streaming source has been unsubscribed, so handle streaming sources rooms.
Parameters:
-
evt
Object-
username
StringThe username to subscribe with
-
streamId
StringThe streaming source identifier
-
evtUserPresenceChanged
-
evt
Handler for the userPresenceChanged event emitted by user component. The user presence has changed, so notifies all clients.
Parameters:
-
evt
Object-
username
StringThe username
-
presence
StringThe presence status of the user
-
evtUserProfileAvatarChanged
-
evt
Handler for the evtUserProfileAvatarChanged event emitted by user component. The user avatar picture has been changed, so notifies all clients.
Parameters:
-
evt
Object-
username
StringThe username
-
avatar
StringThe avatar picture in base64 format
-
extenChanged
-
exten
Handler for the extenChanged event emitted by astproxy component. Something has changed in the extension, so notifies all interested clients.
Parameters:
-
exten
ObjectThe extension object
extenConnected
-
data
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
StringThe identy of a part of the conversation
-
num2
ObjectThe identy of other part of the conversation
-
extenDialing
-
data
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
StringThe identifier of the ringing extension
-
callerIdentity
ObjectThe identity data of the caller
-
callerHasConf
BooleanTrue if the caller has an active conference
-
extenHangup
-
data
Handler for the extenHangup event emitted by astproxy component.
Parameters:
-
data
ObjectThe extension hangup data object
getFilteredCallerIndentity
-
username
-
callerIdentity
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
StringThe username
-
callerIdentity
ObjectThe identity of the caller to be filtered
Returns:
The filtered caller identity.
getNumConnectedClients
-
The
Returns the number of connected clients.
Parameters:
-
The
Numbernumber of connected clients.
getWebsocketEndpoint
-
socket
Return the endpoint of the websocket. The endpoint is constructed by ip_address:port.
Parameters:
-
socket
ObjectThe websocket
Returns:
The websocket endpoint as ip_address:port.
loginHdlr
-
socket
-
obj
Websocket login handler.
Parameters:
-
socket
ObjectThe client websocket
-
obj
ObjectThe data passed by the client
-
accessKeyId
StringThe username of the account
-
token
StringThe token received by the authentication REST request
-
[uaType]
String optionalThe user agent type ("mobile" | "desktop")
-
meetmeConfChanged
-
conf
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
ObjectThe conference object
meetmeConfEnd
-
confId
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
StringThe conference identifier
on
-
type
-
cb
Subscribe a callback function to a custom event fired by this object. It's the same of nodejs events.EventEmitter.on method.
Parameters:
-
type
StringThe name of the event
-
cb
FunctionThe callback to execute in response to the event
Returns:
A subscription handle capable of detaching that subscription.
onDestroy
()
Handle the module destroy process.
parkingChanged
-
parking
Handler for the parkingChanged event emitted by astproxy component. Something has changed in the parking, so notifies all interested clients.
Parameters:
-
parking
ObjectThe parking object
queueChanged
-
queue
Handler for the queueChanged event emitted by astproxy component. Something has changed in the queue, so notifies all interested clients.
Parameters:
-
queue
ObjectThe queue object
queueMemberChanged
-
member
Handler for the queueMemberChanged event emitted by astproxy component. Something has changed in the queue member, so notifies all interested clients.
Parameters:
-
member
ObjectThe queue member object
reload
()
private
Reload the component.
removeWebsocketId
-
socketId
Removes the client websocket identifier from the private object wsid.
Parameters:
-
socketId
StringThe client websocket identifier private
reset
()
private
Reload the component.
send401
-
socket
Send 401 unauthorization response through websocket.
Parameters:
-
socket
ObjectThe 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
StringThe name of the client user
-
extenId
StringThe extension identifier
sendAutheSuccess
-
socket
Send authorized successfully response through websocket.
Parameters:
-
socket
ObjectThe client websocket
sendCallWebrtcToClient
-
username
-
to
Sends an event to the client to call the number using webrtc extension.
Parameters:
-
username
StringThe name of the client user
-
to
StringThe 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
ObjectThe client websocket
-
[obj]
String optionalThe 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
StringThe event name
-
data
ObjectThe event data object
-
fn
FunctionThe function to be passed to perform the sending. It will be called passing the "username" associated with websocket
-
[fnData]
Function optionalThe 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
Sends the event only to users with associated extension.
Parameters:
-
evtName
StringThe name of the event
-
evtObj
ObjectThe event data object
-
extenId
StringThe extension identifier
setAstProxy
-
comp
Set the asterisk proxy to be used by the module.
Parameters:
-
comp
ObjectThe 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
ObjectThe authentication module.
setCompAuthorization
-
comp
Sets the authorization module to be used.
Parameters:
-
comp
ObjectThe authorization module.
setCompPostit
-
comp
Sets post-it architect component.
Parameters:
-
comp
ObjectThe post-it architect component.
setCompStreaming
-
comp
Sets the streaming module to be used.
Parameters:
-
comp
ObjectThe user module.
setCompUser
-
comp
Sets the user module to be used.
Parameters:
-
comp
ObjectThe user module.
setCompVoicemail
-
cv
Sets voicemail architect component used by voicemail functions.
Parameters:
-
cv
ObjectThe voicemail architect component.
setLogger
-
log
Set the logger to be used.
Parameters:
-
log
ObjectThe 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
Handler for the trunkChanged event emitted by astproxy component. Something has changed in the trunk, so notifies all interested clients.
Parameters:
-
trunk
ObjectThe trunk object
updateNewPostitListener
-
recipient
-
list
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
StringThe recipient user of the new post-it
-
list
ArrayAll the new post-it messages of the user
updateNewVoiceMessagesListener
-
voicemail
-
list
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
StringThe voicemail identifier
-
list
ArrayThe list of all new voicemail messages
updateTokenExpirationOfAllWebsocketUsers
()
private
Update the token expiration of all users that are connected by websocket (http).
wsConnHdlr
-
socket
Websocket (http) connection handler.
Parameters:
-
socket
ObjectThe 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
StringThe 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
ObjectThe data about the streaming source update event
extenConnected
Emitted to the extension involved in a connected conversation.
Example:
{ "extenConnected": "223" }
Event Payload:
-
data
ObjectThe 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
ObjectThe data about the extension
meetmeConfEnd
Emitted to a websocket client connection on a meetme conference end event.
{ id: "201" }
Event Payload:
-
data
ObjectThe 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
ObjectThe 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
ObjectThe 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
ObjectThe 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
ObjectThe 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
ObjectThe 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
ObjectThe 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
ObjectThe 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
StringThe 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
StringThe name of the user that has been logged in.