Skip to content

WebSocket ​

Supports the standard WebSocket feature. On top of this, the WebSocket constructor is extended, as shown below.

js
    WebSocket WebSocket(url, protocols, caFilePath, extensions)

The constructor returns a WebSocket object.

Parameters

  • string url: the URL to connect to; this should be the URL to which the WebSocket server will respond

  • string | Array<string> protocols: [optional] a single protocol string or an array of protocol strings. These strings are used to specify sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified protocol). If no protocol string is specified, it is an empty string.

  • string caFilePath: [optional] configures the path of the custom certificate supported by wss

  • Object extensions: [optional] extension data, described in the table below

extensions properties:

PropertyTypeRequiredDescription
headerObjectNoHTTP Header; Referer cannot be set in the Header. Defaults to {}
tcpNoDelaybooleanNoTCP_NODELAY setting when establishing the TCP connection. Defaults to false
perMessageDeflatebooleanNoWhether to enable the compression extension. Defaults to false
timeoutnumberNoTimeout, in milliseconds. Defaults to 60000

Return Value

  • WebSocket: returns a WebSocket object.