leader-tab
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

leader-tab

An algorithm for selecting a leader from all the open tabs of a website. Uses the Broadcast Channel API for synchronization.

import { elector } from "leader-tab";

const tab = elector({
  onLeaderElected: () => {
    console.log("I am the leader");
  },
  onLeaderDemoted: () => {
    console.log("I got demoted");
  },
});

console.log("Current tab id", tab.getTabId());
console.log("Is current tab the leader", tab.isLeader());
console.log("Stop all synchronization work", tab.destroy());

Package Sidebar

Install

npm i leader-tab

Weekly Downloads

6

Version

0.0.4

License

MIT

Unpacked Size

10.5 kB

Total Files

7

Last publish

Collaborators

  • frectonz