Page MenuHomePhabricator

Add JX.Leader: synchronization over localStorage
ClosedPublic

Authored by epriestley on Jan 6 2015, 5:31 AM.

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 3649
Build 3659: [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
127–131

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.