Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 1.89 KB

File metadata and controls

49 lines (37 loc) · 1.89 KB

PushMessageData

Namespace: SpawnDev.SpawnJS.JSObjects
Inherits: SpawnJSObject
Source: JSObjects/PushMessageData.cs
MDN Reference: PushMessageData on MDN

The PushMessageData interface of the Push API provides methods which let you retrieve the push data sent by a server in various formats. https://developer.mozilla.org/en-US/docs/Web/API/PushMessageData

Constructors

Signature Description
PushMessageData(SpawnJSObjectReference _ref) Default deserialize constructor

Methods

Method Return Type Description
ArrayBuffer() ArrayBuffer Extracts the data as an ArrayBuffer object.
Blob() Blob Extracts the data as a Blob object.
Json() T Extracts the data as a JSON object.
Text() string Extracts the data as a plain text string.

Examples

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., readyState becomes ReadyState)
  • Events use ActionEvent with +=/-= (e.g., addEventListener("click", fn) becomes OnClick += handler)
  • Async methods return Task<T> instead of Promise<T>
  • Objects should be disposed with using statements
  • Access via JS.Get<PushMessageData>(...) or constructor new PushMessageData(...)
self.addEventListener("push", (event) => {
  const obj = event.data.json();

  if (obj.action === "subscribe" || obj.action === "unsubscribe") {
    fireNotification(obj, event);
    port.postMessage(obj);
  } else if (obj.action === "init" || obj.action === "chatMsg") {
    port.postMessage(obj);
  }
});

See full example on MDN