aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-08-12 05:04:20 +0800
committerkumavis <aaron@kumavis.me>2016-08-12 05:04:20 +0800
commitd7dffedf4825c468d32f389935fcac6e242a2232 (patch)
tree97a390facaaa6ca90df9fc1d5f54737d1e0ec18b /app/scripts
parent53b1334d37c2792e76e2a114acb3e7b47399e8aa (diff)
downloadtangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar.gz
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar.bz2
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar.lz
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar.xz
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.tar.zst
tangerine-wallet-browser-d7dffedf4825c468d32f389935fcac6e242a2232.zip
deps - local-message-stream extracted as module post-message-stream
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/contentscript.js2
-rw-r--r--app/scripts/inpage.js2
-rw-r--r--app/scripts/lib/local-message-stream.js56
3 files changed, 2 insertions, 58 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js
index 1eb04059d..de2cf263b 100644
--- a/app/scripts/contentscript.js
+++ b/app/scripts/contentscript.js
@@ -1,4 +1,4 @@
-const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
+const LocalMessageDuplexStream = require('post-message-stream')
const PortStream = require('./lib/port-stream.js')
const ObjectMultiplex = require('./lib/obj-multiplex')
const extension = require('./lib/extension')
diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js
index 055235671..7c508c66f 100644
--- a/app/scripts/inpage.js
+++ b/app/scripts/inpage.js
@@ -1,7 +1,7 @@
/*global Web3*/
cleanContextForImports()
require('web3/dist/web3.min.js')
-const LocalMessageDuplexStream = require('./lib/local-message-stream.js')
+const LocalMessageDuplexStream = require('post-message-stream')
const setupDappAutoReload = require('./lib/auto-reload.js')
const MetamaskInpageProvider = require('./lib/inpage-provider.js')
restoreContextAfterImports()
diff --git a/app/scripts/lib/local-message-stream.js b/app/scripts/lib/local-message-stream.js
deleted file mode 100644
index 821e51046..000000000
--- a/app/scripts/lib/local-message-stream.js
+++ /dev/null
@@ -1,56 +0,0 @@
-const Duplex = require('readable-stream').Duplex
-const inherits = require('util').inherits
-
-module.exports = LocalMessageDuplexStream
-
-inherits(LocalMessageDuplexStream, Duplex)
-
-function LocalMessageDuplexStream (opts) {
- Duplex.call(this, {
- objectMode: true,
- })
-
- // this._origin = opts.origin
- this._name = opts.name
- this._target = opts.target
-
- // console.log('LocalMessageDuplexStream ('+this._name+') - initialized...')
- window.addEventListener('message', this._onMessage.bind(this), false)
-}
-
-// private
-
-LocalMessageDuplexStream.prototype._onMessage = function (event) {
- var msg = event.data
- // console.log('LocalMessageDuplexStream ('+this._name+') - heard message...', event)
- // validate message
- if (event.origin !== location.origin) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (event.origin !== location.origin) ')
- if (typeof msg !== 'object') return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (typeof msg !== "object") ')
- if (msg.target !== this._name) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (msg.target !== this._name) ', msg.target, this._name)
- if (!msg.data) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (!msg.data) ')
- // console.log('LocalMessageDuplexStream ('+this._name+') - accepted', msg.data)
- // forward message
- try {
- this.push(msg.data)
- } catch (err) {
- this.emit('error', err)
- }
-}
-
-// stream plumbing
-
-LocalMessageDuplexStream.prototype._read = noop
-
-LocalMessageDuplexStream.prototype._write = function (data, encoding, cb) {
- // console.log('LocalMessageDuplexStream ('+this._name+') - sending message...')
- var message = {
- target: this._target,
- data: data,
- }
- window.postMessage(message, location.origin)
- cb()
-}
-
-// util
-
-function noop () {}