Skip to main content

WebSocket

Accessing the WebSocket Object

The WebSocket object can be accessed through the MooMoo.ws property in your code. This property represents the WebSocket connection currently established with the server. You can use this property to perform various actions, such as sending raw packets, adding event listeners, and getting information.

Examples of the WebSocket Object

Here's an example of how you can access the WebSocket object:

let ws = MooMoo.ws

// Adding an event listener

ws.addEventListener("message", (e) => {
console.log(e.data);
})

// Sending a raw packet
ws.send(new Uint8Array([0, 0]));

// getting information

let socketurl = ws.url
let socketstate = ws.readyState

Sending Packets

To send packets which will be encoded automatically, you can use the sendPacket method to send raw packets, which will be automatically encoded by the API.

For example, if you want to send a chat message, you can use the sendPacket method like this:

MooMoo.sendPacket("ch", "Hello, world!");