Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: MessageEvent
Source: JSObjects/MessageEvent.cs
MDN Reference: MessageEvent on MDN
The MessageEvent interface represents a message received by a target object. https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
| Signature | Description |
|---|---|
MessageEvent(SpawnJSObjectReference _ref) |
Deserialization constructor |
MessageEvent(SpawnJSObjectReference _ref) |
Deserialization constructor |
| Property | Type | Access | Description |
|---|---|---|---|
Data |
TData |
get | Message data as type TData |
TypeOfData |
string? |
get | non-standard method returns the typeof this.data returns "String", "Blob", or "ArrayBuffer" (could also return "Object", "Boolean", "Number", other?) |
Origin |
string |
get | A string representing the origin of the message emitter. |
LastEventId |
string |
get | A string representing a unique ID for the event. |
Ports |
Array<MessagePort> |
get | An array of MessagePort objects representing the ports associated with the channel the message is being sent through (where appropriate, e.g. in channel messaging or when sending a message to a shared worker). |
| Method | Return Type | Description |
|---|---|---|
GetData() |
T |
The data sent by the message emitter. (data property with TValue typed get accessor) Type to get property as |
GetSource() |
T |
A MessageEventSource (which can be a WindowProxy, MessagePort, or ServiceWorker object) representing the message emitter. (source property with TValue typed get accessor) Type to get property as |
SpawnDev.SpawnJS Mapping Note: The JavaScript examples below show the standard Web API usage. In SpawnDev.SpawnJS, the same API is available with C# conventions:
- Properties and methods use PascalCase (e.g.,
readyStatebecomesReadyState)- Events use ActionEvent with
+=/-=(e.g.,addEventListener("click", fn)becomesOnClick += handler)- Async methods return
Task<T>instead ofPromise<T>- Objects should be disposed with
usingstatements- Access via
JS.Get<MessageEvent>(...)or constructornew MessageEvent(...)
const myWorker = new SharedWorker("worker.js");myWorker.port.start();[first, second].forEach((input) => {
input.onchange = () => {
myWorker.port.postMessage([first.value, second.value]);
console.log("Message posted to worker");
};
});
myWorker.port.onmessage = (e) => {
result1.textContent = e.data;
console.log("Message received from worker");
};