Page MenuHomePhabricator

Add JX.Leader: synchronization over localStorage
ClosedPublic

Authored by epriestley on Jan 6 2015, 5:31 AM.
Tags
None
Referenced Files
F18622453: D11235.id27057.diff
Mon, Sep 15, 11:54 AM
F18600239: D11235.id26980.diff
Sat, Sep 13, 9:17 AM
F18594233: D11235.diff
Fri, Sep 12, 5:31 PM
F18590105: D11235.diff
Fri, Sep 12, 5:13 AM
F18504679: D11235.id.diff
Thu, Sep 4, 11:58 PM
F18496258: D11235.diff
Thu, Sep 4, 5:18 PM
F18405306: D11235.diff
Fri, Aug 29, 11:20 PM
F18386035: D11235.id27057.diff
Fri, Aug 29, 1:54 AM
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.