{"id":18356327,"url":"https://github.com/mente/jleader","last_synced_at":"2025-04-10T01:48:23.376Z","repository":{"id":6588111,"uuid":"7830608","full_name":"mente/jleader","owner":"mente","description":"leader election plugin to choose master tab among all same cross origin tabs","archived":false,"fork":false,"pushed_at":"2013-12-11T13:18:57.000Z","size":128,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T18:03:48.732Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mente.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-25T23:35:52.000Z","updated_at":"2018-02-04T11:10:38.000Z","dependencies_parsed_at":"2022-08-31T04:21:56.587Z","dependency_job_id":null,"html_url":"https://github.com/mente/jleader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mente%2Fjleader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mente%2Fjleader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mente%2Fjleader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mente%2Fjleader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mente","download_url":"https://codeload.github.com/mente/jleader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142635,"owners_count":21054666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T22:09:43.242Z","updated_at":"2025-04-10T01:48:23.353Z","avatar_url":"https://github.com/mente.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"jleader\n=======\n\nleader election plugin to choose master tab among all same cross origin tabs\n\n### Introduction\n\nCommon case for leader election is long-polling apps. jleader lets you offload server and client by sending connections only from leader tab.\nUsage:\n```javascript\n\t//Subscribe to leader updates. Callback will be fired when current tab changes it's state.\n\tleader.subscribe(function(newValue) {\n\t\tif (newValue) {\n\t\t\talert('This tab became master');\n\t\t} else {\n\t\t\t//Tab can lose it's master state if another tab use forces (explicitly calls electMe())\n\t\t\talert('This tab is not master anymore');\n\t\t}\n\t});\n\t//Announce this tab as a peer. Check whether master is online. If not - elect this tab as master\n\tleader.announce();\n\t//current state is stored here\n\tif (!leader.isMaster) {\n\t\t//You can force this tab to become master\n\t\tleader.electMe()\n\t}\n```\n\n\n### How Does it Work?\n\nPlugin is based on HTML5 localStorage fire state event. [jStorage](https://github.com/andris9/jStorage) is used underneath.\n[Shared Worker](http://www.w3.org/TR/workers/#shared-workers-introduction) is the best approach but it's [not yet implemented](http://caniuse.com/#feat=sharedworkers) in major browsers. Code should work in all browsers that are supported by jStorage but not all of them were tested.\n\nTested browsers:\n* Chrome (24+)\n* Firefox (18+)\n* Safari (6+)\n* IE (9+)\n\n\n__Warning__ jleader is not thread safe as localStorage is not thread safe among different tabs. However everything works just fine. There is a [mutex implementation](http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/) and it will be added if someone encounters problems with thread safeness.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmente%2Fjleader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmente%2Fjleader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmente%2Fjleader/lists"}