mirror of https://github.com/embarklabs/embark.git
move js code to its own folder
This commit is contained in:
parent
37a126a6b8
commit
35a4098b82
|
@ -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);
|
||||||
|
|
|
@ -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)];
|
|
@ -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 @@
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue