Page MenuHomePhabricator

Add JX.Leader: synchronization over localStorage
ClosedPublic

Authored by epriestley on Jan 6 2015, 5:31 AM.
Tags
None
Referenced Files
F19659937: D11235.id.diff
Sat, Feb 7, 2:10 AM
F19658326: D11235.id.diff
Fri, Feb 6, 10:53 PM
F19545311: D11235.id27056.diff
Sat, Jan 24, 2:38 AM
F19516408: D11235.id26980.diff
Wed, Jan 14, 11:45 PM
F19516399: D11235.id26980.diff
Wed, Jan 14, 11:40 PM
F19516398: D11235.id26980.diff
Wed, Jan 14, 11:40 PM
F19505690: D11235.id27056.diff
Fri, Jan 9, 1:27 PM
F19233395: D11235.id26980.diff
Dec 21 2025, 5:40 PM
Subscribers
Tokens
"Doubloon" token, awarded by btrahan.

Details

Summary

Ref T6559. Adds a "JX.Leader" primitive to replace the synchronization over Flash. This does a couple of things:

  • Offers an "onBecomeLeader" event, which we can use to open the WebSocket.
  • Offers an "onReceiveMessage" event, which we can use to dispatch notifications and handle requests to play sounds and send desktop notifications.
  • Offers a "broadcast()" method, which we can use to send desktop notification and sound requests.
Test Plan

Added some code like this:

if (!statics.leader) {
  statics.leader = true;

  JX.Leader.listen('onBecomeLeader', function() {
    JX.log("This tab is now the leader.");
  });

  JX.Leader.listen('onReceiveBroadcast', function(message, is_leader) {
    JX.log('[' + (is_leader ? 'As Leader' : 'Not Leader') + '] ' + message);
  });

  JX.Leader.start();
}

Then:

  • Saw first tab open become leader reliably in Safari, Chrome, Firefox.
  • Saw new tab become leader reliably when the first tab was closed.
  • Saw broadcast() work as documented and deliver messages with correct leadership-flag and uniqueness.

Diff Detail

Repository
rP Phabricator
Branch
sync
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 3655
Build 3665: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

epriestley retitled this revision from to [Draft] Leader synchronization over localStorage.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley retitled this revision from [Draft] Leader synchronization over localStorage to Add JX.Leader: synchronization over localStorage.
epriestley updated this object.
epriestley edited the test plan for this revision. (Show Details)
epriestley added reviewers: btrahan, joshuaspence.
  • Provide more useful primitives.
btrahan awarded a token.
btrahan edited edge metadata.
btrahan added inline comments.
webroot/rsrc/externals/javelin/lib/Leader.js
128–132

kk

This revision is now accepted and ready to land.Jan 6 2015, 10:49 PM
webroot/rsrc/externals/javelin/core/init.js
187

Is this any better over if (window.localStorage) {?

epriestley edited edge metadata.
  • Use window.localStorage.
  • Backport tweak from D11143.
This revision was automatically updated to reflect the committed changes.