new WebSocketMetrics(webSocket, syncClock)
WebSocketMetrics class.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
webSocket |
Grape2D.WebSocket | WebSocket to bind. | |
syncClock |
Grape2D.utils.SynchronizedClock |
<optional> |
A clock synchronized with the server. |
- Source:
Members
-
<static, constant> PING_PREFIX :string
-
Prefix of the ping message. Any message with this prefix is treated as a ping message.
Type:
- string
- Source:
-
<private> bytesReceived :number
-
Total number of bytes received.
Type:
- number
- Source:
-
<private> bytesSent :number
-
Total number of bytes sent.
Type:
- number
- Source:
-
<private> lastPing :number
-
Last time the ping value was registered.
Type:
- number
- Source:
-
<private> lastReceived :number
-
Bytes of the last message received.
Type:
- number
- Source:
-
<private> lastSent :number
-
Bytes of the last message sent.
Type:
- number
- Source:
-
<private> pingAc :number
-
Accumulated ping.
Type:
- number
- Source:
-
<private> pingSamples :number
-
Ping samples to send to the server.
Type:
- number
- Source:
-
<private> pingSamplesReceived :number
-
Ping responses received.
Type:
- number
- Source:
-
<private> pingValue :number
-
Last ping value registered.
Type:
- number
- Source:
-
<private> start :number
-
Time when the web socket was opened.
Type:
- number
- Source:
-
<private> syncAc :number
-
Accumulative clock synchronization.
Type:
- number
- Source:
-
<private> syncClock :Grape2D.utils.SynchronizedClock
-
Synchronized clock with the server.
Type:
- Source:
-
ws :Grape2D.WebSocket
-
Web Socket binded.
Type:
- Source:
Methods
-
getBytesReceived() → {number}
-
Gets the total number of bytes received.
- Source:
Returns:
Bytes received.- Type
- number
-
getBytesReceivedPerSec() → {number}
-
Gets the number of bytes sent per second. Average between the total number of bytes sent and the time since the web socket was open.
- Source:
Returns:
Average bytes per second.- Type
- number
-
getBytesSent() → {number}
-
Gets the total number of bytes sent.
- Source:
Returns:
Bytes sent.- Type
- number
-
getBytesSentPerSec() → {number}
-
Gets the number of bytes sent per second. Average between the total number of bytes sent and the time since the web socket was open.
- Source:
Returns:
Average bytes per second.- Type
- number
-
getLastBytesReceived() → {number}
-
Gets the number of bytes received, on the last message.
- Source:
Returns:
Bytes received.- Type
- number
-
getLastBytesSent() → {number}
-
Gets the number of bytes sent, on the last message.
- Source:
Returns:
Bytes sent.- Type
- number
-
getLastPing() → {number}
-
Gets the last time a pong response was received.
- Source:
Returns:
Timestamp, in milliseconds.- Type
- number
-
getPing() → {number}
-
Gets the network latency, in milliseconds.
- Source:
Returns:
Ping value.- Type
- number
-
ping()
-
Sends a ping message.
- Source:
-
pong(message)
-
Sends back a pong message.
Parameters:
Name Type Description message
string Ping message, received. - Source:
-
pongReceived(message)
-
Pong message handler. This is used to calculate the ping and synchronize the clock with the server.
Parameters:
Name Type Description message
string Pong response message. - Source: