npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

secret-door

v1.1.2

Published

secret-door is an RPC implementation on top of `window.postMessage` for cross context communication in the browser. It can be used, for example, to call functions in a cross domain iframe.

Downloads

6

Readme

secret-door

secret-door is an RPC implementation on top of window.postMessage for cross context communication in the browser. It can be used, for example, to call functions in a cross domain iframe.

secret-door returns promises when executing remote functions and therefore assumes that window.Promise is available.

Install

npm install --save secret-door

Usage

In parent window.

var Channel = require("secret-door");

var channel = new Channel({
  targetWindow: document.querySelectorAll(".some-iframe")[0].contentWindow
}).setHandler({
  foo: function () {},
  bar: function () {}
}, this);

// set an additional handler
channel.setHandler("getAnswer", function (arg1, arg2) {
  // we can return a promise
  return new Promise(function (resolve) {
    return doSomething(arg1 + arg2);
  })
}, this)

// set a catch all handler
channel.setHandler("*", function (command, arg1, arg2, arg3) {
  // all remote command calls that don't have a registered
  // named handler can be handled here
});

// unset a handler
channel.clearHandler("bar");

//call a function within the iframe
channel.execute("getURL").then(function (url) {
  console.log(url);
});

In an iframe.

var channel = new Channel({
  targetWindow: window.parent
}).setHandler({
  getURL: function () {
    return window.location.href;
  }
});
channel.execute("getAnswer", 2, 5).then(function (answer) {
  console.log(answer);
});

API

var channel = new Channel(options)

  • options.targetWindow - The window to send messages to (e.g. iframeEl.contentWindow, window.parent)
  • options.targetOrigin - What the origin of the other window must be for sending messages
  • options.namespace - Allows using multiple instances of secret door on the same page
  • options.filterIncoming - A function that can reject an incoming message by inspecting parsed data and raw messageEvent

channel.setHandler()

channel.setHandler(name, fn, context);
channel.setHandler(obj, context);

Set the handler for incoming commands.

The handler can be named via the first argument. e.g. channel.setHandler('foo', function () {});

The handler can also be an object mapping names to functions. e.g. channel.setHandler({foo: function () {}, bar: function () {}});

Both can be used in combination. Further calls to either will extend the list of channel's handlers.

If a handler with that name already exists, it will be overwritten with the new one.

The last argument can be used to pass the context that the handler functions will be applied in.

To handle all incoming commands for which a named handler is not available, register a handler with name "". e.g. channel.setHandler('', function (command, arg1) { console.log('handling all commands')} );

Handlers can return promises.

channel.execute(fnName, ...args)

Execute a function on the other side of the channel. First argument is the name of the remote function. The rest of the arguments will be passed as arguments to the remote function.

channel.clearHandler(name)

Remove a handler.

channel.clearAllHandlers(name)

Remove all handlers.

Returns a promise.

channel.tap(fn)

Listen in on all requests/responses going through this channel. The callback will be called with 1 object describing the request or response. Only messages that actually go via the channel will be tapped, in other words if the message is in the wrong namespace, wrong origin or is filtered by filterIncoming it won't show up in the tap.

channel.destroy()

Remove handler references and stop listening to events.

Test

npm test

Release

npm run release

Follow semver rules when specifying a new version.