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

cross-channel

v0.6.2

Published

Cross window messaging

Downloads

14

Readme

CrossChannel

Cross origin messaging channel. Sends messages between different JavaScript contexts.

Installation

In a Browser environment:

<script src="path/to/connexionjs/dist/cross-channel.min.js"></script>
<script>
	var channel = new CrossChannel('name')
	channel.on('message', handler)
	channel.postMessage(message)
</script>

In a CommonJS environment first install it from NPM:

$ npm install cross-channel

then in the source code use

var CrossChannel = require('cross-channel')
var channel = new CrossChannel('name')
channel.on('message', handler)
channel.postMessage(message)

Reference

channel.name: String

The name of a channel

channel.postMessage(message: Object)

Sends a message to all other channel instances with the same name. Message can't be a DOM element or contain a DOM element. The message is cloned between different execution contexts.

channel.on('message', handler: Function)

Attaches listener to a 'message' event. The handler is called only when message is sent from another instances with the same channel name, but not called when postmessage() is called on the same instance. The callback is executed with a single argument of MessageEvent object. The event interface:

MessageEvent {
	type: String
	data: Object|Boolean|String|Number|Null|Undefined
	timeStamp: Number
	origin: String
	sourceChannel: String
}

channel.once('message', handler: Function)

Attaches listener that is executed only once for the very first 'message' event.

channel.addEventListener('message', handler: Function)

The alias to channel.on(). Necessary for a compatibility with BroadcastChannel API when used as a polifyll.

channel.removeEventListener('message', handler: Function)

Removes an event handler of a 'message' event.

channel.removeAllListeners('message')

Removes all event handlers of a 'message' event.

channel.close()

Removes all channel event handlers and closes a channel to reveal memory.

Examle

var channelGreen1 = new CrossChannel('green')
var channelGreen2 = new CrossChannel('green')

channelGreen1.postMessage({text: 'message'})
channelGreen2.on('message', function(event){
	console.log(event.data) // -> {text: 'message'}
})

Use cases:

  • need a BroadcastChannel polifyll;
  • developement of a multiple screen expirience in a browser;
  • development of a JavaScript API for media players that are embedded in an <iframe>;
  • need an unified messaging channel in browser extensions;
  • messaging between all frames with any origins in a browser window;
  • messaging between all windows/frames and background processes on NWJS platform;
  • messaging between "Node" and "Webkit" context on the Node-webkit platform;
  • messaging across tabs of the same origin

Compatibility

Browsers

| Browsers | self | frames | tabs | |----------------------|:------:|:-------:|:----:| | Firefox | ✓ | ✓ | ✓ | | Android Firefox | ✓ | ✓ | ✓ | | Chrome | ✓ | ✓ | ✓ | | Android Chrome | ✓ | ✓ | ✓ | | Opera <=9 | - | - | - | | Opera <=12 | ✓ | ✓ | ✓ | | Opera >=15 | ✓ | ✓ | ✓ | | Android Opera >=15 | ✓ | ✓ | ✓ | | Opera mini | ✓ | ✓ | ✓ | | Safari >=5 | ✓ | ✓ | ✓ | | Safari on iOS >= 8 | ✓ | ✓ | ✓ |

| Android Browser >=4.1| ✓ | ✓ | ✓ |

| IE >=9 | ✓ | ✓ | ~ | | Mobile IE >=10 | ✓ | ✓ | - | | Edge | ✓ | ✓ | ✓ | | Worker | | | |

Extensions

| Browsers | self | background | content | popup | options | |----------------------|:------:|:-----------:|:-------:|:-----:|:-------:| | Chrome extension | ✓ | ✓ | ✓ | ✓ | ✓ | | Firefox WebExtension | ✓ | ✓ | ✓ | ✓ | ✓ | | Edge WebExtension | | | | | | | Safari extension | - | - | - | - | - |

Applications

| Platforms | self | frames | tabs | webview | background | NodeJS | |----------------------|:------:|:------:|:----:|:-------:|:----------:|:------:| | Node-webkit <=0.11 | ✓ | ✓ | - | o | o | ✓ | | NWJS >=0.13 | ✓ | ✓ | ✓ | | ✓ | - | | Electron | | | | | | | | Chrome app | | | | | | | | Windows Universal app| | | | | | | | Cordova | | | | | | | | Firefox OS app | | | | | | |

Server side

| Platforms | self | children | parallel | forks | |----------------------|:------:|:--------:|:--------:|:-----:| | NodeJS | - | - | - | - |