client-broadcast-pub-sub
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

hsd-client-broadcast

A library to allow communication between browsing contexts. It can be used to detect user-actions in other tabs like when user logs out. A user action change in one tab will broadcast the message which is listened by other browser tabs and perform the required operation.

Install

npm Command

Example (Same Broadcast and Listner event):

import {BroadCastChannel}  from 'client-broadcast-pub-sub';

const broadcastChannel = new BroadCastChannel();
broadcastChannel.registerLogout(logout);
broadcastChannel.broadCastLogout();


export function logout(): void {
  window.location.href = `/logout`;
}

Example (Different Broadcast and Listner event):

import broadcastChannel from 'client-broadcast-pub-sub';

const broadcastChannel = new BroadCastChannel();
broadcastChannel.registerLogout(SomeFunctionOne,SomeFunctionTwo);
broadcastChannel.broadCastLogout();


export function SomeFunctionOne(): void {
  // Code
}

export function SomeFunctionTwo(): void {
  //Code
}

Method

registerLogout(broadcastFunc,listenerFunc)

Register Broadcast and Listener events.

name type data type need description
broadcastFunc param Fnction yes broadcast event name
listenerFunc param Undefined/Function no callback function

broadCastLogout()

Broadcast the event registered in registerLogout

Build

LICENSE

MIT

Package Sidebar

Install

npm i client-broadcast-pub-sub

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

8.38 kB

Total Files

9

Last publish

Collaborators

  • soubhagya.sp