aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/inpage.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-10-13 03:35:55 +0800
committerkumavis <aaron@kumavis.me>2016-10-13 03:35:55 +0800
commita1c3c944cf534fff8bfb9560347a03ba2a2bda00 (patch)
tree29888693645c9ad04f4b703f1fb0c0dfdac0da60 /app/scripts/inpage.js
parent0182f8a4e91b8a9b0951967d2c075955bfb4f24f (diff)
downloadtangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.gz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.bz2
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.lz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.xz
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.tar.zst
tangerine-wallet-browser-a1c3c944cf534fff8bfb9560347a03ba2a2bda00.zip
dapp reload - fixed disconnect detection via polling
Diffstat (limited to 'app/scripts/inpage.js')
-rw-r--r--app/scripts/inpage.js21
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) {