diff --git a/lib/modules/whisper/index.js b/lib/modules/whisper/index.js index d1a3b80f..9fdef066 100644 --- a/lib/modules/whisper/index.js +++ b/lib/modules/whisper/index.js @@ -42,12 +42,13 @@ class Whisper { // TODO: possible race condition could be a concern this.events.request("version:get:web3", function(web3Version) { let code = ""; + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString(); if (web3Version[0] === "0") { - code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs_old_web3.js')).toString(); + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString(); code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);"; } else { - code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); + code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs.js')).toString(); code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperNewWeb3);"; } self.embark.addCodeToEmbarkJS(code); diff --git a/lib/modules/whisper/embarkjs.js b/lib/modules/whisper/js/embarkjs.js similarity index 86% rename from lib/modules/whisper/embarkjs.js rename to lib/modules/whisper/js/embarkjs.js index 2199bb06..38e0a95b 100644 --- a/lib/modules/whisper/embarkjs.js +++ b/lib/modules/whisper/js/embarkjs.js @@ -60,26 +60,9 @@ __embarkWhisperNewWeb3.sendMessage = function(options) { }; __embarkWhisperNewWeb3.listenTo = function(options) { - var topics, messageEvents; - messageEvents = function() { - this.cb = function() {}; - }; + var topics = options.topic || options.topics; - messageEvents.prototype.then = function(cb) { - this.cb = cb; - }; - - messageEvents.prototype.error = function(err) { - return err; - }; - - messageEvents.prototype.stop = function() { - this.filter.stopWatching(); - }; - - topics = options.topic || options.topics; - - let promise = new messageEvents(); + let promise = new __MessageEvents(); if (typeof topics === 'string') { topics = [this.web3.utils.toHex(topics).slice(0, 10)]; diff --git a/lib/modules/whisper/embarkjs_old_web3.js b/lib/modules/whisper/js/embarkjs_old_web3.js similarity index 87% rename from lib/modules/whisper/embarkjs_old_web3.js rename to lib/modules/whisper/js/embarkjs_old_web3.js index c2f52a4c..51ac2220 100644 --- a/lib/modules/whisper/embarkjs_old_web3.js +++ b/lib/modules/whisper/js/embarkjs_old_web3.js @@ -63,26 +63,10 @@ __embarkWhisperOld.sendMessage = function(options) { }; __embarkWhisperOld.listenTo = function(options) { - var topics, _topics, messageEvents; + var topics, _topics; topics = options.topic || options.topics; _topics = []; - messageEvents = function() { - this.cb = function() {}; - }; - - messageEvents.prototype.then = function(cb) { - this.cb = cb; - }; - - messageEvents.prototype.error = function(err) { - return err; - }; - - messageEvents.prototype.stop = function() { - this.filter.stopWatching(); - }; - if (typeof topics === 'string') { _topics = [topics]; } else { @@ -94,7 +78,7 @@ __embarkWhisperOld.listenTo = function(options) { topics: topics }; - let promise = new messageEvents(); + let promise = new __MessageEvents(); let filter = this.web3.shh.filter(filterOptions, function(err, result) { var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload)); diff --git a/lib/modules/whisper/js/message_events.js b/lib/modules/whisper/js/message_events.js new file mode 100644 index 00000000..0205d8b2 --- /dev/null +++ b/lib/modules/whisper/js/message_events.js @@ -0,0 +1,17 @@ + +var __MessageEvents = function() { + this.cb = function() {}; +}; + +__MessageEvents.prototype.then = function(cb) { + this.cb = cb; +}; + +__MessageEvents.prototype.error = function(err) { + return err; +}; + +__MessageEvents.prototype.stop = function() { + this.filter.stopWatching(); +}; +