All Projects â†’ hustcc â†’ post-messenger

hustcc / post-messenger

Licence: other
đŸ‘ļ ~1 Kb wrapper of window.postMessage for cross-document communication.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to post-messenger

trainmanjs
TrainmanJS - Cross-Origin Communication Library
Stars: ✭ 16 (-42.86%)
Mutual labels:  communication, iframe, postmessage
ibridge
Typesafe iframe bridge for easy parent child bidirectional communication
Stars: ✭ 25 (-10.71%)
Mutual labels:  communication, iframe, postmessage
Postmate
📭 A powerful, simple, promise-based postMessage library.
Stars: ✭ 1,638 (+5750%)
Mutual labels:  iframe, postmessage
rx-postmessenger
Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.
Stars: ✭ 27 (-3.57%)
Mutual labels:  iframe, postmessage
PostEvent
A Cross-Domain Event Handler javascript library. Pure Vanilla JS, no dependencies.
Stars: ✭ 14 (-50%)
Mutual labels:  iframe, postmessage
ember-window-messenger
This aims to be an simple window postMessage services provider.
Stars: ✭ 17 (-39.29%)
Mutual labels:  communication, postmessage
iframe-communication
Basic two way iframe communication
Stars: ✭ 88 (+214.29%)
Mutual labels:  communication, iframe
Post Me
📩 Use web Workers and other Windows through a simple Promise API
Stars: ✭ 398 (+1321.43%)
Mutual labels:  communication, iframe
chronosjs
JS Channels (Events / Commands / Reqest-Response / Courier) Mechanism
Stars: ✭ 35 (+25%)
Mutual labels:  communication, postmessage
Packetserial
An Arduino Library that facilitates packet-based serial communication using COBS or SLIP encoding.
Stars: ✭ 177 (+532.14%)
Mutual labels:  communication
Pjon
PJON (Padded Jittering Operative Network) is an experimental, arduino-compatible, multi-master, multi-media network protocol.
Stars: ✭ 2,615 (+9239.29%)
Mutual labels:  communication
Mqttnet
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
Stars: ✭ 2,486 (+8778.57%)
Mutual labels:  communication
Opentok Ios Sdk Samples
Example applications that use the OpenTok iOS SDK
Stars: ✭ 186 (+564.29%)
Mutual labels:  communication
Restcomm Connect
The Open Source Cloud Communications Platform
Stars: ✭ 232 (+728.57%)
Mutual labels:  communication
Betterposter Latex Template
LaTeX Template for Mike Morrison's #betterposter
Stars: ✭ 171 (+510.71%)
Mutual labels:  communication
get-css-data
A micro-library for collecting stylesheet data from link and style nodes
Stars: ✭ 29 (+3.57%)
Mutual labels:  iframe
Node Ethernet Ip
A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.
Stars: ✭ 163 (+482.14%)
Mutual labels:  communication
Diztl
Share, discover & download files in your network đŸ’Ĩ
Stars: ✭ 162 (+478.57%)
Mutual labels:  communication
GenuineChannels
Collection of custom .NET Remoting channels
Stars: ✭ 29 (+3.57%)
Mutual labels:  communication
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (+53.57%)
Mutual labels:  communication

post-messenger

A simple wrapper of window.postMessage for cross-document communication with each other.

一ä¸ĒįŽ€å•įš„ window.postMessage 封čŖ…īŧŒį”¨äēŽčˇ¨æ–‡æĄŖįš„双向数捎通äŋĄã€‚

Build Status Coverage Status npm npm gzip

Feature

  • Simple wrapper for postMessage.
  • Use it just like event emitter.
  • Event channel namespace supported.

Install

npm i --save post-messenger

or import it by script in HTML, then get PostMessenger on window.

<script src="https://unpkg.com/post-messenger/dist/post-messenger.min.js"></script>

Usage

  • In parent document.
import PostMessenger from 'post-messenger';

// connect to iframe
const pm = PostMessenger('chat', window.iframe_name.contentWindow);

const listener = message => {
  console.log(message);
}

// listen the messages
pm.once('room1.*', listener);

pm.on('room1.user1', listener);
  • In iframe document.
import PostMessenger from 'post-messenger';

// connect to parent
const pm = PostMessenger('chat', window.parent);

const listener = message => {
  console.log(message);
}

// send messages
pm.send('room1', 'All users of room1 will received.');

pm.send('*', 'broadcast message.');

Full example can be found here, and code here.

API

There is only one function named PostMessenger, you can get the instance by:

// projectId: the unique id of communication.
// targetDocument: the document which you want to connect and communicate.
const pm = PostMessenger(projectId, targetContentWindow);

The instance has 4 apis.

  • pm.once(channel, listener)

Add a message listener on channel for once.

  • pm.on(channel, listener)

Add a message listener on channel.

  • pm.off([channel, listener])

Remove listener, if channel and listener are all undefined, remove all.

  • pm.send(channel, message)

Send a message to the channel.

Scenes

The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.

The communicate target can be:

  • Window.open
  • Window.opener
  • HTMLIFrameElement.contentWindow
  • Window.parent
  • Window.frames

Reference here.

License

MIT@hustcc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].