Page MenuHomePhabricator

Add JX.Leader: synchronization over localStorage
ClosedPublic

Authored by epriestley on Jan 6 2015, 5:31 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 11, 3:35 AM
Unknown Object (File)
Wed, Apr 3, 5:07 PM
Unknown Object (File)
Wed, Apr 3, 5:07 PM
Unknown Object (File)
Wed, Apr 3, 5:07 PM
Unknown Object (File)
Thu, Mar 28, 11:21 AM
Unknown Object (File)
Mar 10 2024, 6:37 PM
Unknown Object (File)
Mar 8 2024, 8:19 PM
Unknown Object (File)
Mar 8 2024, 1:53 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.