1.1.4 • Published 1 year ago

better-postmessage v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Better postMessage

Tired of the window.postMessage() method ? Need fresh new API that support Promises, answers and simple typed handling ? BetterPostMessage will resolve all of that !

Installation

# NPM
npm i --save better-postmessage

# YARN
yarn i --save better-postmessage

# BUN
bun i --save better-postmessage

Usage

First context

import BetterPostMessage from "better-postmessage";

const messenger = new BetterPostMessage<string>(window);
messenger
 .post({ message: "ping" })
 .answer.then((answer) => {
  if (answer === "pong") console.log("Second context is online !");
 })
 .catch(() => {
  console.log("Second context has not responded");
 });

Second context

import BetterPostMessage from "better-postmessage";

const messenger = new BetterPostMessage<string>(window);
messenger.onReceive(({ message }) => {
 if (message === "ping") return "pong";
});

Parameters

Constructor arguments

new BetterPostMessage(context, options?)
Context

The Window-based context where to emit/receive messages

Options?

Not required

The object containing all behavior options of the messenger. Here are the different options :

KEYDESCRIPTIONTYPEDEFAULT VALUE
tunnelSpecify the custom tunnel of the proxy. Handler and message will be only receive/send to this tunnelstring""
answerTimeoutIn milliseconds, the maximum amount of time a message can wait for its answernumber15_000
debugIf you want to view what's appening behind the processbooleanfalse
1.1.1

1 year ago

1.1.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.12

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago