new WebSocketHandler(IPDwarf)
- Description:
- Create a link to the Api and set the IP address of the Dwarf to connect to
- Source:
Parameters:
| Name |
Type |
Description |
IPDwarf |
string
|
undefined
|
; Set the IP address of the Dwarf to connect to |
Members
closeSocketTimer
- Description:
- closeSocketTimer : Timer could be defined to manage a connection time of the Dwarf that is too long
- Source:
closeSocketTimer : Timer could be defined to manage a connection time of the Dwarf that is too long
closeTimerHandler
- Description:
- closeTimerHandler : function could be defined : to close the timeout timer.
- Source:
closeTimerHandler : function could be defined : to close the timeout timer.
onStopTimerHandler
- Description:
- onStopTimerHandler : function could be defined : this function will be called in case of error during connection
- Source:
onStopTimerHandler : function could be defined : this function will be called in case of error during connection
Methods
(async) cleanup(forceStop) → {Promise.<void>}
- Description:
- cleanup function : Stop all the functions
- Source:
Parameters:
| Name |
Type |
Default |
Description |
forceStop |
boolean
|
false
|
; if true do not try a reconnection, false by default |
Returns:
-
Type
-
Promise.<void>
(async) close() → {Promise.<void>}
- Description:
- Force close the socket connection with the Dwarf
- Source:
Returns:
-
Type
-
Promise.<void>
(async) handleClose() → {Promise.<void>}
- Description:
- Handle close event of the socket connection with the Dwarf
To call from a timeout function during the connection with the Dwarf
- Source:
Returns:
-
Type
-
Promise.<void>
isConnected() → {boolean}
- Description:
- Verify the status of the connection with the Dwarf
- Source:
Returns:
status of the connection
-
Type
-
boolean
(async) prepare(WS_Packet, senderId, expectedResponseCmd, callbackMessage, callbackConnectState, callbackError, callbackReconnect) → {Promise.<void>}
- Description:
- Prepare function : Define the message to send and the command to listen to and the callbacks functions
- Source:
Parameters:
| Name |
Type |
Description |
WS_Packet |
Object
|
Array.<Object>
|
; Message or Array of Messages from the API to send to the Dwarf |
senderId |
string
|
; identifier of the sender |
expectedResponseCmd |
Array.<string>
|
; List of the Command Id to listen to, can be "*" to get all commands. |
callbackMessage |
function
|
; Callback Fonction (const customMessageHandler = (txt_info:string, result_data:object)) to analyse reponses from the Dwarf |
callbackConnectState |
function
|
; Callback Fonction (const customStateHandler = (state)) to get the status result of the current connection of the Dwarf |
callbackError |
function
|
; Callback Fonction (const customErrorHandler = ()) called after an socket error. |
callbackReconnect |
function
|
; Callback Fonction (const customReconnectHandler = ()) called after a socket reconnection. |
Returns:
-
Type
-
Promise.<void>
(async) run() → {Promise.<boolean>}
- Description:
- Main function, to call after prepare function, send the message and start dialogue with the Dwarf
- Source:
Returns:
false if the IP has not been set or if old Socket can't be closed
-
Type
-
Promise.<boolean>
setDefaultPongError(nbTimes) → {void}
- Description:
- Set the nb of times to stop connection after not receiving pong, default is 10.
- Source:
Parameters:
| Name |
Type |
Description |
nbTimes |
number
|
; |
Returns:
-
Type
-
void
setDefaultReconnect(nbTimes) → {void}
- Description:
- Set the nb of times for trying to reconnect to the Dwarf if the connection closes, default is 5.
- Source:
Parameters:
| Name |
Type |
Description |
nbTimes |
number
|
; |
Returns:
-
Type
-
void
setDeviceIdDwarf(deviceIdDwarf) → {boolean}
- Description:
- Set the device ID of the Dwarf connected (readen from the Dwarf or from the config file on the Dwarf)
- Source:
Parameters:
| Name |
Type |
Description |
deviceIdDwarf |
number
|
; Set the device ID of the Dwarf connected. |
Returns:
status
-
Type
-
boolean
(async) setHttpsMode(useHttps) → {Promise.<void>}
- Description:
- Set the Https mode of the proxy connection, the Dwarf connect to
- Source:
Parameters:
| Name |
Type |
Description |
useHttps |
boolean
|
; true if Https, then wss should be used with a proxy connection |
Returns:
-
Type
-
Promise.<void>
(async) setNewIpDwarf(IPDwarf) → {Promise.<void>}
- Description:
- Set the IP address of the Dwarf to connect to
- Source:
Parameters:
| Name |
Type |
Description |
IPDwarf |
string
|
; Set the IP address of the Dwarf to connect to, force another one that was configured when calling the constructor. |
Returns:
-
Type
-
Promise.<void>
setPingInterval(IntervalInSecond) → {void}
- Description:
- Set the intervall of the build in Ping function defult is 10s
- Source:
Parameters:
| Name |
Type |
Description |
IntervalInSecond |
number
|
; in Seconds |
Returns:
-
Type
-
void
(async) setProxyUrl(proxyURL) → {Promise.<void>}
- Description:
- Set the URL address of the proxy uses to connect to the dwarf,
by default not used, set it to empty param for not using a proxy
- Source:
Parameters:
| Name |
Type |
Description |
proxyURL |
string
|
; Set the URL address of the Proxy the Dwarf to connect to. |
Returns:
-
Type
-
Promise.<void>
stopCallbacks(senderId) → {void}
- Description:
- stopCallbacks function : Stop receiving on the callbacks functions
- Source:
Parameters:
| Name |
Type |
Description |
senderId |
string
|
; Identifier of caller |
Returns:
-
Type
-
void