mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-11 05:06:47 +00:00
When trying to either sending, or listening to whisper channels within Embark's consoles (CLI and Cockpit), the console outputs an error that `EmbarkJS` isn't defined. E.g. running: ``` > EmbarkJS.Messages.listenTo({ topic: ['somechannel']) ``` Outputs: ``` EmbarkJS is not defined ``` This seemed very odd as outputting `EmbarkJS` and all of its members worked totally fine. It turns out that both methods, `listenTo()` and `sendMessage()`, in `EmbarkJS.Messages` are not necessarily what one thinks they are. EmbarkJS decorates both methods to create some options that need to be available in the delegate, two of them being `EmbarkJS.Utils.toAscii` and `EmbarkJS.Utils.fromAscii` (ac76a40a61/packages/embarkjs-whisper/src/index.js (L43-L62)
andac76a40a61/packages/embarkjs-whisper/src/index.js (L64-L73)
) These two global references to `EmbarkJS` are the only ones in `embarkjs-whisper` and they are not the same reference as the `EmbarkJS` sandbox global registered in the VM hereac76a40a61/packages/embark-code-runner/src/index.ts (L33)
. In other words, the `EmbarkJS is not defined` message actually refers to the `EmbarkJS` in the wrapping method, not the one registered with the VM, which is also why inspecting the `EmbarkJS` object through the VM works fine. Since the `toAscii()` and `fromAscii()` methods in use are really just facades around `web3.utils.[fromAscii|toAscii]()`, we can replace the global EmbarkJS dependency with web3 utils that are already available anyways.
embarkjs-whisper
embarkjs plugin to interact with whisper
Visit embark.status.im to get started with Embark.