mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-02 02:15:58 +00:00
add optionnal callback
This commit is contained in:
parent
0cffff067a
commit
41b2741ba5
@ -263,11 +263,11 @@ EmbarkJS.Messages.sendMessage = function(options) {
|
||||
return this.currentMessages.sendMessage(options);
|
||||
};
|
||||
|
||||
EmbarkJS.Messages.listenTo = function(options) {
|
||||
EmbarkJS.Messages.listenTo = function(options, callback) {
|
||||
if (!this.currentMessages) {
|
||||
throw new Error('Messages provider not set; e.g EmbarkJS.Messages.setProvider("whisper")');
|
||||
}
|
||||
return this.currentMessages.listenTo(options);
|
||||
return this.currentMessages.listenTo(options, callback);
|
||||
};
|
||||
|
||||
EmbarkJS.Utils = {
|
||||
|
@ -64,7 +64,7 @@ __embarkWhisperNewWeb3.sendMessage = function (options) {
|
||||
});
|
||||
};
|
||||
|
||||
__embarkWhisperNewWeb3.listenTo = function (options) {
|
||||
__embarkWhisperNewWeb3.listenTo = function (options, callback) {
|
||||
var topics = options.topic || options.topics;
|
||||
|
||||
let promise = new __MessageEvents();
|
||||
@ -82,12 +82,15 @@ __embarkWhisperNewWeb3.listenTo = function (options) {
|
||||
var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload));
|
||||
var data;
|
||||
data = {
|
||||
topic: result.topic,
|
||||
topic: EmbarkJS.Utils.toAscii(result.topic),
|
||||
data: payload,
|
||||
//from: result.from,
|
||||
time: result.timestamp
|
||||
};
|
||||
|
||||
if (callback) {
|
||||
return callback(null, data);
|
||||
}
|
||||
promise.cb(payload, data, result);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user