mirror of https://github.com/embarklabs/embark.git
move module js code to its own folder
This commit is contained in:
parent
37a126a6b8
commit
fe186a4443
|
@ -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);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*global EmbarkJS, Web3 */
|
||||
/*global EmbarkJS, Web3, __MessageEvents */
|
||||
|
||||
// for the whisper v5 and web3.js 1.0
|
||||
let __embarkWhisperNewWeb3 = {};
|
||||
|
@ -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)];
|
|
@ -1,4 +1,4 @@
|
|||
/*global EmbarkJS, Web3 */
|
||||
/*global EmbarkJS, Web3, __MessageEvents */
|
||||
|
||||
// for the old version of whisper and web3.js
|
||||
let __embarkWhisperOld = {};
|
||||
|
@ -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));
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
let __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();
|
||||
};
|
||||
|
Loading…
Reference in New Issue