Class WebSocketMessageEventWearable Only

Event type for WebSocket message events. This event fires when a message has been received from the server. Listen for this event by using addEventListener with message, or by setting the onmessage property.

websocket.onmessage = async (event) => {
if (event.data instanceof Blob) {
// Binary frame, can be retrieved as either Uint8Array or string
let bytes = await event.data.bytes();
let text = await event.data.text();

print("Received binary message, printing as text: " + text);
} else {
// Text frame
let text = event.data;
print("Received text message: " + text);
}
};

Hierarchy (View Summary)

Constructors

Properties

Methods

Constructors

Properties

data: string | Blob

The data received from the server. For binary messages, this is of type Blob. For text messages, this is a string.

type: string

The type of the data received, text or binary, returned as a string.

Methods

  • Returns true if the object matches or derives from the passed in type.

    Parameters

    • type: string

    Returns boolean

  • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

    Parameters

    Returns boolean