Show:

BO.WSocketWrapper Class

Creates a wrapper for various websocket implementations to unify the interface.

Constructor

BO.WSocketWrapper

(
  • host
  • port
  • protocol
)

Parameters:

  • host String

    The host address of the web server.

  • port Number

    The port to connect to on the web server. native websocket implementation.

  • protocol String

    The websockt protocol definition (if necessary).

Methods

addEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

dispatchEvent

(
  • type
  • optionalParams
)

Parameters:

  • type Event

    The Event object.

  • optionalParams Object

    Optional parameters passed as an object. return {boolean} True if dispatch is successful, false if not.

hasEventListener

(
  • type
)

Parameters:

  • type String

    The event type return {boolean} True is listener exists for this type, false if not.

init

(
  • self
)
private

Initialize the websocket

Parameters:

  • self Object

    A reference to this websocket object.

removeEventListener

(
  • type
  • listener
)

Parameters:

  • type String

    The event type

  • listener Function

    The function to be called when the event is fired

send

(
  • message
)
private

Send a message TO DO: support sending ArrayBuffers and Blobs For now, forward any calls to sendString

Parameters:

  • message String

    The message to send

sendString

(
  • message
)

Send a message

Parameters:

  • message String

    The message to send

Properties

readyState

String

[read-only] Wrapper for the readyState method of the native websocket implementation

CONNECTING = 0, OPEN = 1, CLOSING = 2, CLOSED = 3

Events

webSocketClosed

BO.WebsocketEvent.CLOSE

The webSocketClosed event is dispatched the websocket connection is closed.

Event Payload:

webSocketConnected

BO.WebsocketEvent.CONNECTED

The webSocketConnected event is dispatched when a connection with the websocket is established.

Event Payload:

webSocketMessage

BO.WebsocketEvent.MESSAGE

The webSocketMessage event is dispatched when a websocket message is received.

Event Payload:

  • target BO.WSocketWrapper

    A reference to the WSocketWrapper object.

  • message String

    The websocket data