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
|
// TODO: possible race condition could be a concern
|
||||||
this.events.request("version:get:web3", function(web3Version) {
|
this.events.request("version:get:web3", function(web3Version) {
|
||||||
let code = "";
|
let code = "";
|
||||||
|
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
||||||
|
|
||||||
if (web3Version[0] === "0") {
|
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);";
|
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);";
|
||||||
} else {
|
} 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);";
|
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperNewWeb3);";
|
||||||
}
|
}
|
||||||
self.embark.addCodeToEmbarkJS(code);
|
self.embark.addCodeToEmbarkJS(code);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*global EmbarkJS, Web3 */
|
/*global EmbarkJS, Web3, __MessageEvents */
|
||||||
|
|
||||||
// for the whisper v5 and web3.js 1.0
|
// for the whisper v5 and web3.js 1.0
|
||||||
let __embarkWhisperNewWeb3 = {};
|
let __embarkWhisperNewWeb3 = {};
|
||||||
|
@ -60,26 +60,9 @@ __embarkWhisperNewWeb3.sendMessage = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkWhisperNewWeb3.listenTo = function(options) {
|
__embarkWhisperNewWeb3.listenTo = function(options) {
|
||||||
var topics, messageEvents;
|
var topics = options.topic || options.topics;
|
||||||
messageEvents = function() {
|
|
||||||
this.cb = function() {};
|
|
||||||
};
|
|
||||||
|
|
||||||
messageEvents.prototype.then = function(cb) {
|
let promise = new __MessageEvents();
|
||||||
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();
|
|
||||||
|
|
||||||
if (typeof topics === 'string') {
|
if (typeof topics === 'string') {
|
||||||
topics = [this.web3.utils.toHex(topics).slice(0, 10)];
|
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
|
// for the old version of whisper and web3.js
|
||||||
let __embarkWhisperOld = {};
|
let __embarkWhisperOld = {};
|
||||||
|
@ -63,26 +63,10 @@ __embarkWhisperOld.sendMessage = function(options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
__embarkWhisperOld.listenTo = function(options) {
|
__embarkWhisperOld.listenTo = function(options) {
|
||||||
var topics, _topics, messageEvents;
|
var topics, _topics;
|
||||||
topics = options.topic || options.topics;
|
topics = options.topic || options.topics;
|
||||||
_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') {
|
if (typeof topics === 'string') {
|
||||||
_topics = [topics];
|
_topics = [topics];
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,7 +78,7 @@ __embarkWhisperOld.listenTo = function(options) {
|
||||||
topics: topics
|
topics: topics
|
||||||
};
|
};
|
||||||
|
|
||||||
let promise = new messageEvents();
|
let promise = new __MessageEvents();
|
||||||
|
|
||||||
let filter = this.web3.shh.filter(filterOptions, function(err, result) {
|
let filter = this.web3.shh.filter(filterOptions, function(err, result) {
|
||||||
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
|
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