https://github.com/frectonz/leader-tab
An algorithm for selecting a leader from all the open tabs of a website.
https://github.com/frectonz/leader-tab
distributed-systems leader-election
Last synced: 5 months ago
JSON representation
An algorithm for selecting a leader from all the open tabs of a website.
- Host: GitHub
- URL: https://github.com/frectonz/leader-tab
- Owner: frectonz
- License: mit
- Created: 2025-04-14T19:21:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-15T15:03:41.000Z (about 1 year ago)
- Last Synced: 2026-01-17T06:48:16.735Z (5 months ago)
- Topics: distributed-systems, leader-election
- Language: TypeScript
- Homepage:
- Size: 103 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `leader-tab`
An algorithm for selecting a leader from all the open tabs of a website. Uses the [Broadcast Channel](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API) API for synchronization.
```typescript
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());
```