WS

WS

Websockets client

Constructor

new WS(optionsopt)

Source:
Parameters:
Name Type Attributes Description
options object <optional>

config params

Properties
Name Type Attributes Default Description
path string <optional>
/

connect url path name

query object <optional>

query parameters to send on connect in the url

retry_timeout number <optional>
250

ms between retries to connect

retry_factor number <optional>

multiplier for retry timeout

max_timeout number <optional>
30000

ms for max timeout on retries, once reached restart with retry_timeout

max_retries number <optional>

how many retries to perform until connected

max_pending number <optional>
10

how many request to keep in pending queue until connected

ping_interval number <optional>
300000

ms between pings

Example
app.$ready(async () => {

  app.ws = new app.WS({ path: "/ws" });
  app.ws.connect();
  app.ws.on("ws:message", (data) => { ...});

});
....

app.ws.send("/route/action")
app.ws.send({ path: "/some/path", data: { ...} })

Methods

close(disableopt)

Description:
  • Closes and possibly disables WS connection, to reconnect again must delete .disabled property

Source:
Parameters:
Name Type Attributes Description
disable boolean <optional>

connect()

Description:
  • Open a new websocket connection

Source:

online()

Description:
  • Check the status of websocket connection, reconnect if needed

Source:

ping()

Description:
  • Send a ping and shcedule next one

Source:

send(data)

Description:
  • Send a string data or an object

Source:
Parameters:
Name Type Description
data object | string

timer(timeout)

Description:
  • Restart websocket reconnect timer, increase timeout according to reconnect policy (retry_factor, max_timeout)

Source:
Parameters:
Name Type Description
timeout number