Skip to content

Commit

Permalink
send pings from message-bridge to webpage as a keep-alive
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Oct 20, 2016
1 parent 25037aa commit 538f7e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions addon/data/message-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,15 @@ self.port.on('from-addon-to-web', function(data) {
'from-addon-to-web', { bubbles: true, detail: clonedData }
));
});

/*
Emit a ping event every second to tell the webapp that the addon
is still alive. The webapp can use the abscence of these pings
to detect when the addon gets disabled or uninstalled.
*/
setInterval(function() {
const detail = cloneInto({ type: 'ping' }, document.defaultView);
document.documentElement.dispatchEvent(new CustomEvent(
'from-addon-to-web', { bubbles: true, detail }
));
}, 1000);

0 comments on commit 538f7e4

Please sign in to comment.