Class: WebSocket

Grape2D. WebSocket

new WebSocket(options)

WebSocket abstraction. This, unlike the browser implementation, doesn't (try to) establish the connection immediately. Instead the method open() must be called.
Parameters:
Name Type Description
options Object Setup options.
Properties
Name Type Argument Description
address string Address of the web socket server.
protocol string <optional>
Web socket protocol.
clock Grape2D.utils.SynchronizedClock <optional>
A clock, to to be synchronized with the clock of the server.
Source:

Members

<private> address :string

Address to connect.
Type:
  • string
Source:

<private> metrics :Grape2D.WebSocketMetrics

Network metrics.
Type:
Source:

<private> oncloseCallback :!Array.<!Function>

List of callback for the on close event.
Type:
  • !Array.<!Function>
Source:

<private> onmessageCallback :!Array.<!Function>

List of callback for the on message event.
Type:
  • !Array.<!Function>
Source:

<private> onopenCallback :!Array.<!Function>

List of callback for the on open event.
Type:
  • !Array.<!Function>
Source:

<private> onsendCallback :!Array.<!Function>

List of callback for messages sent.
Type:
  • !Array.<!Function>
Source:

<private> protocol :string|undefined

Connection's protocol.
Type:
  • string | undefined
Source:

<private> ws :WebSocket

Web socket.
Type:
  • WebSocket
Source:

Methods

addOnClose(callback)

Adds a callback for the on close event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

addOnMessage(callback)

Adds a callback for the on message event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

addOnOpen(callback)

Adds a callback for the on open event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

addOnSend(callback)

Adds a callback for the sned event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

close()

Closes the connection.
Source:

getMetrics() → {Grape2D.WebSocketMetrics}

Gets the metrics of this web socket.
Source:
Returns:
Web socket's metrics.
Type
Grape2D.WebSocketMetrics

isOpen() → {boolean}

Checks if the web socket is open.
Source:
Returns:
True if it's open.
Type
boolean

open()

Opens the connection. This method must be called, for the connection to be established.
Source:

removeOnClose(callback)

Removes a callback for the on close event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

removeOnMessage(callback)

Removes a callback for the on message event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

removeOnOpen(callback)

Removes a callback for the on open event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

removeOnSend(callback)

Removes a callback for the send event.
Parameters:
Name Type Description
callback Function Callback function.
Source:

send(msg)

Sends a message to the web socket.
Parameters:
Name Type Description
msg string Message to send.
Source: