# Namespace: SockJS

## CB_Net.Sockets. SockJS

Property that contains the functions and properties related with the SockJS client library.

Source:
  - CrossBase/net/sockets/CB_Net_Sockets.js, line 18

### Members

#### <static, readonly> websocketLast :Object|null

  Keeps the last SockJS created.

  ##### Type:

  - Object | null
  Source:
    - CrossBase/net/sockets/CB_Net_Sockets.js, line 31

### Methods

#### <static> close( [websocket] [, onError]) → {undefined|false}

  Tries to close the websockets connection. Using the SockJS client library internally.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `websocket` | function | <optional> | `CB_Net.Sockets.SockJS.websocketLast` | The SockJS object that we want to use. If not provided, it will try to use the last one created (if any) which is stored in `CB_Net.Sockets.SockJS.websocketLast`.
  `onError` | function | <optional> |  | Function for the event "onerror" used by the SockJS object. If provided, it will replace the previous one (if any). Following the same rules as in the SockJS client library documentation.

  Source:
    - CrossBase/net/sockets/CB_Net_Sockets.js, line 135

  ##### Returns:

  Returns undefined (the same as the "close" function of the SockJS object) if the SockJS has been used or false otherwise.

  Type
    undefined | false

#### <static> listen(serverURL [, onOpen] [, onClose] [, onMessage] [, onError] [, options] [, protocols]) → {Object|null}

  Creates the websockets object and sets the listeners. Using the SockJS client library internally.

  ##### Parameters:

  Name | Type | Argument | Description
  --- | --- | --- | ---
  `serverURL` | string |  | The URL of the SockJS server. This will be used as the first parameter when it calls the constructor of SockJS internally. Following the same rules as in the SockJS client library documentation (the parameter is called "url").
  `onOpen` | function | <optional> | Function for the event "onopen" used by the SockJS object. Following the same rules as in the SockJS client library documentation.
  `onClose` | function | <optional> | Function for the event "onclose" used by the SockJS object. Following the same rules as in the SockJS client library documentation.
  `onMessage` | function | <optional> | Function for the event "onmessage" used by the SockJS object. Following the same rules as in the SockJS client library documentation.
  `onError` | function | <optional> | Function for the event "onerror" used by the SockJS object. Following the same rules as in the SockJS client library documentation.
  `options` | Object | <optional> | The desired options for the SockJS object. This will be used as the third parameter when it calls the constructor of SockJS internally. Following the same rules as in the SockJS client library documentation (the parameter is called "options").
  `protocols` | array | <optional> | This will be used as the second parameter when it calls the constructor of SockJS internally. Following the same rules as in the SockJS client library documentation (the parameter is called "_reserved").

  Source:
    - CrossBase/net/sockets/CB_Net_Sockets.js, line 65

  ##### Returns:

  Returns a SockJS object. Read the SockJS client library documentation for more information. In the case of error, returns null.

  Type
    Object | null

#### <static> open()

  Alias for `CB_Net.Sockets.SockJS.listen`.

  Source:
    - CrossBase/net/sockets/CB_Net_Sockets.js, line 48
  See:
    - `CB_Net.Sockets.SockJS.listen`

#### <static> send(message [, websocket] [, onError]) → {undefined|false}

  Sends a websockets message. Using the SockJS client library internally.

  ##### Parameters:

  Name | Type | Argument | Default | Description
  --- | --- | --- | --- | ---
  `message` | string |  |  | The message that we want to send. This will be used as the first and unique parameter when it calls the "send" function of the SockJS object internally. Following the same rules as in the SockJS client library documentation.
  `websocket` | function | <optional> | `CB_Net.Sockets.SockJS.websocketLast` | The SockJS object that we want to use. If not provided, it will try to use the last one created (if any) which is stored in `CB_Net.Sockets.SockJS.websocketLast`.
  `onError` | function | <optional> |  | Function for the event "onerror" used by the SockJS object. If provided, it will replace the previous one (if any). Following the same rules as in the SockJS client library documentation.

  Source:
    - CrossBase/net/sockets/CB_Net_Sockets.js, line 102

  ##### Returns:

  Returns undefined (the same as the "send" function of the SockJS object) if the SockJS has been used or false otherwise.

  Type
    undefined | false

#### Search results