diff options
author | kumavis <kumavis@users.noreply.github.com> | 2016-10-13 04:52:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-13 04:52:32 +0800 |
commit | 8d5b2478e3aa939cb4b0a58b20b199cded62769e (patch) | |
tree | b287ae4a264fd29f5ec8b5fe2c97564fb80f62f8 /app/scripts/inpage.js | |
parent | f68673e84ac48c5574b642b3b779d4d43954d98f (diff) | |
parent | 465cff78c33385c7f108e7539f484119f7a03767 (diff) | |
download | tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar.gz tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar.bz2 tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar.lz tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar.xz tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.tar.zst tangerine-wallet-browser-8d5b2478e3aa939cb4b0a58b20b199cded62769e.zip |
Merge pull request #730 from MetaMask/i695-dapp-reload
dapp reload - fixed disconnect detection via polling
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r-- | app/scripts/inpage.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 28a1223ac..ef199946c 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -2,6 +2,8 @@ cleanContextForImports() require('web3/dist/web3.min.js') const LocalMessageDuplexStream = require('post-message-stream') +const PingStream = require('ping-pong-stream/ping') +const endOfStream = require('end-of-stream') const setupDappAutoReload = require('./lib/auto-reload.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() @@ -29,13 +31,22 @@ web3.setProvider = function () { console.log('MetaMask - overrode web3.setProvider') } console.log('MetaMask - injected web3') +// export global web3, with usage-detection reload fn +var triggerReload = setupDappAutoReload(web3) -// -// export global web3 with auto dapp reload -// - +// listen for reset requests from metamask var reloadStream = inpageProvider.multiStream.createStream('reload') -setupDappAutoReload(web3, reloadStream) +reloadStream.once('data', triggerReload) + +// setup ping timeout autoreload +// LocalMessageDuplexStream does not self-close, so reload if pingStream fails +var pingChannel = inpageProvider.multiStream.createStream('pingpong') +var pingStream = new PingStream({ objectMode: true }) +// wait for first successful reponse +metamaskStream.once('data', function(){ + pingStream.pipe(pingChannel).pipe(pingStream) +}) +endOfStream(pingStream, triggerReload) // set web3 defaultAcount inpageProvider.publicConfigStore.subscribe(function (state) { |