tabs-broadcast

2.1.11 • Public • Published

Tabs broadcast system.

This package allows you to communicate arbitrary data between browser tabs, as well as transfer events between them. This solution is supported in Chrome, Firefox and Opera. The exact version support can be found in caniuse.com


Install

Using npm

npm install tabs-broadcast

Using yarn

yarn add tabs-broadcast

Use plugin (ES6)

Return the class that you want to initialize

import TabsBroadcast from 'tabs-broadcast'

Methods

.$emit( message: {String}, data: {String} ) - sends any event with arbitrary data to the browser
.$on( message: {String}, callback: {Function} ) - listens for events within the browser
.$once( message: {String}, callback: {Function} ) - listens for events within the browser. Deletes the subscription to the event after a call to callback
.$off( message: {String} ) - unsubscribes from wiretapping events of the specified method


Example

// Written in a file that handles authorization 
TabsBroadcast.$emit('USER-IS-AUTH', { userData: {username: 'Ravy'}})
 
// It is written in the file that causes authorization
TabsBroadcast.$on('USER-IS-AUTH', (data) => {
    console.log('UserData on event', data)
})
 
// Will cause a colback and remove the listener. Will be executed only once
TabsBroadcast.$once('USER-IS-AUTH', (data) => {
    console.log('UserData once callback', data)
})
 
// Removes a listener
TabsBroadcast.$off('USER-IS-AUTH')

Package Sidebar

Install

npm i tabs-broadcast

Weekly Downloads

2

Version

2.1.11

License

GPL

Unpacked Size

39.1 kB

Total Files

4

Last publish

Collaborators

  • ravy