Constructor
new Socket(server, host)
Properties:
Name | Type | Description |
---|---|---|
host |
string | The host WebSocket address. Example: |
connected |
bool | Will be true if the server is connected to the WebSocket, and false otherwise. |
server |
object | The |
ws |
object | The WebSocket class provided by the |
acknowledgements |
array | List of acknowledgements received from the server. Used to recognize when the server successfully processes a message. |
Parameters:
Name | Type | Description |
---|---|---|
server |
Server | The |
host |
string | Websocket address. Example: |
Methods
disconnect()
Disconnects from the WebSocket.
send(type, message)
Sends a raw message to the WebSocket
Parameters:
Name | Type | Description |
---|---|---|
type |
string | |
message |
object |
Events
disconnect
Fired when the WebSocket disconnects.
error
Used internally for when the WebSocket experiences an error.
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | The error that occured. |
event
Used internally for when a raw event is received from the server. It isn't recommended to use this event in your code.
Parameters:
Name | Type | Description |
---|---|---|
json |
object | The message data sent by the server. |
raw
Fired when a WebSocket packet is received.
Parameters:
Name | Type | Description |
---|---|---|
data |
Buffer | Raw data sent by the server. |
ready
Fired when the connection to the server has been established.