1.0.3 • Published 2 years ago

client-broadcast-pub-sub v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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.

nametypedata typeneeddescription
broadcastFuncparamFnctionyesbroadcast event name
listenerFuncparamUndefined/Functionnocallback function

broadCastLogout()

Broadcast the event registered in registerLogout

Build

LICENSE

MIT

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago