Message
A structured WebSocket message object for typed payload exchange over WebConnect.
import { Message } from "@schukai/monster/source/net/webconnect/message.mjs";Message is the transport wrapper used around WebConnect payloads. It keeps the message body in one explicit object that can be serialized to JSON, queued, logged and reconstructed later.
Use it when the realtime boundary needs a stable shape. A dedicated message object is easier to inspect in tests, easier to persist in queues and safer to hand to tooling than a loose collection of plain objects.
The class is deliberately minimal: it stores the payload, exposes it through getData() and toJSON(), and restores it through fromJSON(). Application semantics stay in the payload itself.
Serialize And Restore A Structured Message
import { Message } from "@schukai/monster/source/net/webconnect/message.mjs";
const output = document.getElementById("message-output");
document.getElementById("message-run").addEventListener("click", () => {
const source = new Message({
type: "notification",
payload: {
id: "evt-1",
severity: "info",
},
});
const json = JSON.stringify(source);
const restored = Message.fromJSON(json);
output.textContent = JSON.stringify(
{
serialized: json,
restored: restored.getData(),
},
null,
2,
);
});Keep Nested Payload Data Intact Through Serialization
import { Message } from "@schukai/monster/source/net/webconnect/message.mjs";
const output = document.getElementById("message-nested-output");
document.getElementById("message-nested-run").addEventListener("click", () => {
const source = new Message({
type: "presence",
payload: {
users: [
{ id: "u-1", status: "online" },
{ id: "u-2", status: "away" },
],
meta: {
room: "alpha",
revision: 3,
},
},
});
const restored = Message.fromJSON(JSON.stringify(source));
output.textContent = JSON.stringify(restored.getData(), null, 2);
});Use A Message Shape That Is Ready For Queue Inspection And Logging
import { Message } from "@schukai/monster/source/net/webconnect/message.mjs";
const output = document.getElementById("message-queue-output");
document.getElementById("message-queue-run").addEventListener("click", () => {
const queue = [
new Message({ type: "joined", payload: { room: "alpha", user: "u-1" } }),
new Message({ type: "typing", payload: { room: "alpha", user: "u-2" } }),
];
output.textContent = JSON.stringify(
queue.map((entry) => entry.toJSON()),
null,
2,
);
});Access Raw Message Data Through GetData And ToJSON
import { Message } from "@schukai/monster/source/net/webconnect/message.mjs";
const output = document.getElementById("message-object-output");
document.getElementById("message-object-run").addEventListener("click", () => {
const message = new Message({
type: "notification",
payload: {
severity: "warn",
id: "evt-8",
},
});
output.textContent = JSON.stringify(
{
fromGetData: message.getData(),
fromToJSON: message.toJSON(),
},
null,
2,
);
});Exported
MessageDerived from
BaseOptions
The Options listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the Base.
Properties
The Properties listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits Properties from these parent classes. If you cannot find a specific Properties in this list, we recommend consulting the documentation of the Base.
Methods
The methods listed in this section are defined directly within the class. This class is derived from several parent classes. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the Base.
Constructor
constructor(data)data{object}: data
{TypeError}value is not a object
Structural methods
getData()- {object}
Static methods
fromJSON(json)json{string}: json
- {Message}
{TypeError}value is not a string
Other methods
toJSON()- {*}
Events
This component does not fire any public events. It may fire events that are inherited from its parent classes.