mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-12 05:36:46 +00:00
1. get rid of the whisper layer and handle everything in the communication layer 2. Create a gethWhisper and a parityWhisper plugin that has the same files as packages/embark/src/lib/modules/geth, except with a whisperClient instead of gethClient, and will include most of https://github.com/embark-framework/embark/blob/master/packages/plugins/whisper/src/index.js. 3. Get rid of any whisper registration in geth. 4. In the whisperGeth and whisperParity plugins, modify the request for communication:node:register, to end up calling `startWhisperNode`
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import EmbarkJS from "embarkjs";
|
|
import EmbarkJSWhisper from "embarkjs-whisper";
|
|
|
|
class API {
|
|
|
|
constructor(embark) {
|
|
this.embark = embark;
|
|
this.communicationConfig = embark.config.communicationConfig;
|
|
}
|
|
|
|
async initEmbarkJSWhisper() {
|
|
if (Object.keys(EmbarkJS.Messages.Providers).includes("whisper")) return;
|
|
|
|
EmbarkJS.Messages.registerProvider("whisper", EmbarkJSWhisper);
|
|
EmbarkJS.Messages.setProvider("whisper", this.communicationConfig.connection);
|
|
}
|
|
|
|
async registerAPICalls() {
|
|
this.initEmbarkJSWhisper();
|
|
this.registerSendMessageCall();
|
|
this.registerListenToCall();
|
|
}
|
|
|
|
async registerSendMessageCall() {
|
|
this.embark.registerAPICall(
|
|
"post",
|
|
"/embark-api/communication/sendMessage",
|
|
(req, res) => {
|
|
EmbarkJS.Messages.sendMessage({ topic: req.body.topic, data: req.body.message }, (err, result) => {
|
|
if (err) {
|
|
return res.status(500).send({ error: err });
|
|
}
|
|
res.send(result);
|
|
});
|
|
});
|
|
}
|
|
|
|
async registerListenToCall() {
|
|
this.embark.registerAPICall(
|
|
"ws",
|
|
"/embark-api/communication/listenTo/:topic",
|
|
(ws, req) => {
|
|
EmbarkJS.Messages.listenTo({ topic: req.params.topic }).subscribe(data => {
|
|
ws.send(JSON.stringify(data));
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = API;
|