Socket
Book a DemoInstallSign in
Socket

connexionjs

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connexionjs

Event emitter library

0.7.1
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
2
Weekly downloads
 
Created
Source

ConnexionJS

Emit and listen for events across different frames and execution contexts. Automatically synchronizes event history if any context is attached or created during runtime.

Installation

In a Browser environment include the instance of the ConnexionJS in every frame that should work with events:

<script src="path/to/connexionjs/dist/connexion.min.js"></script>

Then in the source code use global variable in the context of a frame

connexion.listen('event', function(){})
connexion.emit('event')

In a CommonJS environment first install it from NPM:

$ npm install connexionjs

then in the source code use

	var connexion = require('connexionjs')
	connexion.listen('event', function(){})
	connexion.emit('event')

Usage

Include a library in any window. Start listening and emitting events.

In a main frame

connexion.emit('main-event')
connexion.listen('main-event' , function(eventDetail){
	console.log(eventDetail) //undefined
})
connexion.listen('frame-event' , function(eventDetail){
	console.log(eventDetail) //{a: 1, b: 2}
})

In any child frame

connexion.emit('frame-event', {a: 1, b: 2})
connexion.listen('main-event' , function(eventDetail){
	console.log(eventDetail) //undefined
})
connexion.listen('frame-event' , function(eventDetail){
	console.log(eventDetail) //{a: 1, b: 2}
})

API reference:

connexion.emit(eventType: String, [eventDetail: Object])

Emits event with an object attached to it. An event detail is optional.

connexion.listen(eventType: String, handler: Function)

Listens events that are emitted.

connexion.observe(eventType: String, handler: Function)

Observes events that are emitted. Like connexion.listen() but additionally calls handler in a moment of attachment with the latest data of event. Suitable for handling of events from the past.

connexion.unsubscribe(eventType: String, [handler: Function])

Removes event handler for a given event type. If handler is not provided then all handlers of a given event type are removed.

connexion.version: String

The version of the library. Sinse the version is important for compatibility between different instancies of ConnexionJS this property can be checked programmatically to see if they match. Versions are compatible if "patch" versions match (e.g. 1.1.x)

Use cases

  • Communiation between iframes and main window on any direction even across different origins;
  • Communication between different tabs/windows of the same origin;
  • Communication between different script contexts in browser extensions: background scripts, content scripts, popup scripts;
  • Communication between Node and Webkit context on the Node-Webkit platform;
  • Mediator object in a Browser web application;
  • Mediator object in a NodeJS application.

Compatibility

Browsersupport
self
frames
tabs
workers
Node-webkit <=0.11support
self
frames
windows-
NodeJS
NWJS >=0.13support
self
frames
windows
NodeJS-
Browser extensionsupport
self
background
content
popup
NodeJS >=0.10support
self
child processes-
parallel processes-

Polyfills that may be required for old platforms:

  • Array indexOf() (IE <=8)
  • Function bind() (IE <=8, FF <=3.6, SF <=5.0.5, CH <6, OP <=11.50)
  • Object.keys() (IE <=8, FF <=3.6, SF <=4.0.5, OP <=11.50)

Keywords

connexion

FAQs

Package last updated on 15 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.