1.0.3 • Published 3 years ago
client-broadcast-pub-sub v1.0.3
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 CommandExample (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