aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/contentscript.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-05-06 07:04:43 +0800
committerkumavis <aaron@kumavis.me>2016-05-06 07:04:43 +0800
commitaa2816010dc724e3976dc3e639179221cdce7d66 (patch)
tree11bf4022de245eb8f48668bf7e6f666ba06dbeb5 /app/scripts/contentscript.js
parentb863fe16e885e8548f371898532c914a6540ebed (diff)
downloadtangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar.gz
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar.bz2
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar.lz
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar.xz
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.tar.zst
tangerine-wallet-browser-aa2816010dc724e3976dc3e639179221cdce7d66.zip
inpage - automatic dapp reload
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r--app/scripts/contentscript.js23
1 files changed, 17 insertions, 6 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index a256a3f5b..1b7b98ec9 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,5 +1,7 @@
const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
const PortStream = require('./lib/port-stream.js')
+const ObjectMultiplex = require('./lib/obj-multiplex')
+
// inject in-page script
@@ -15,13 +17,22 @@ var pageStream = new LocalMessageDuplexStream({
name: 'contentscript',
target: 'inpage',
})
+pageStream.on('error', console.error.bind(console))
var pluginPort = chrome.runtime.connect({name: 'contentscript'})
var pluginStream = new PortStream(pluginPort)
+pluginStream.on('error', console.error.bind(console))
-// forward communication across
-pageStream.pipe(pluginStream)
-pluginStream.pipe(pageStream)
+// forward communication plugin->inpage
+pageStream.pipe(pluginStream).pipe(pageStream)
-// log errors
-pageStream.on('error', console.error.bind(console))
-pluginStream.on('error', console.error.bind(console)) \ No newline at end of file
+// connect contentscript->inpage control stream
+var mx = ObjectMultiplex()
+mx.on('error', console.error.bind(console))
+mx.pipe(pageStream)
+var controlStream = mx.createStream('control')
+controlStream.on('error', console.error.bind(console))
+
+// if we lose connection with the plugin, trigger tab refresh
+pluginStream.on('close', function(){
+ controlStream.write({ method: 'reset' })
+}) \ No newline at end of file