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

@osome/iframe-channel

v2.1.1

Published

Provides communication between iFrame and parent window (or web app) via postMessage

Downloads

14

Readme

Channel

Provides communication between iFrame and parent window (or web app) via postMessage

Install

npm i --save @osome/iframe-channel

Package API

init channel:

import { getWidgetChannel, getParentChannel } from '@osome/channel';

// in widget:
const channel = getWidgetChannel();

// in parent:
const widgetIFrame = document.getElementById('widget-iframe');
const channel = getParentChannel(widgetIFrame);

methods & events:

// on widget side:
channel.sendInit();
channel.sendReady();
channel.sendToChat(payload);
channel.sendClose();
channel.onInitData();
const initData = channel.initData;

// on parent side:
channel.onInit(console.log);
channel.onReady(console.log);
channel.onChatData(console.log);
channel.onClose(console.log);
channel.sendInitData();

direct work with channel:

window.channel.setTransport(callbackFn) // listen events

window.channel.passMessage({event: 'initData', payload: {colorTheme: 'red'}}) // sendData

Channel API

Channel sends data in stringified JSON:

{
  "event": "event_type",
  "payload": "event_data"
}

Events from iframe to parent:

init (optional) - widget's html and js is loaded and widget is ready to receive init data from parent (see onInit event in #events-from-parent-to-iframe)

ready (required) - widget is ready to be displayed

sendToChat - widget sends data for chat. Payload should have:

  1. message - to be sent to chat behalf of current user
  2. data - should have widget field with the widget code and any fields with widget specific information

For example, SSIC Widget will send:

{
  "event": "sendToChat",
  "payload": {
    "message": "46900 - Wholesale trade of a variety of goods without a dominant product;\n62090 - Other information technology and computer service activities",
    "data": {
      "action": "submitCodes",
      "widget": "SSIC",
      "parameters": { "codes": ["46900", "62090"], "ids": [10229, 10408] }
    }
  }
}

with the appropriate backend data:

({
  "id": 9679,
  "code": "01492",
  "title": "Bird breeding",
  "name": "Bird breeding, 01492",
  "status": "active"
},
{
  "id": 9680,
  "code": "01493",
  "title": "Crocodile farms",
  "name": "Crocodile farms, 01493",
  "status": "active"
})

closeWebview - iframe should be closed

Events from parent to iframe

initData (optional) - initial data for widget. payload could be : {"themeColor": "blue"}

initData could also be set by query string: http://localhost:3000/?themeColor=blue (if you send then initData event it will be overridden)

initData is available as channel.initData