import EmbarkJS from 'Embark/EmbarkJS'; import React from 'react'; import { Alert, Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; class Whisper extends React.Component { constructor(props) { super(props); this.state = { listenTo: '', channel: '', message: '', subscribedChannels: [], messageList: [], logs: [] } } handleChange(e, name){ this.state[name] = e.target.value; this.setState(this.state); } sendMessage(e){ e.preventDefault(); EmbarkJS.Messages.sendMessage({topic: this.state.channel, data: this.state.message}); this.addToLog("EmbarkJS.Messages.sendMessage({topic: '" + this.state.channel + "', data: '" + this.state.message + "'})"); } listenToChannel(e){ e.preventDefault(); this.state.subscribedChannels.push(`subscribed to ${this.state.listenTo} now try sending a message`); EmbarkJS.Messages.listenTo({topic: [this.state.listenTo]}) .then(message => this.state.messageList.push(`channel: ${this.state.listenTo} message: ${message}`)) this.addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.listenTo + "']}).then(function(message) {})"); } addToLog(txt){ this.state.logs.push(txt); this.setState({logs: this.state.logs}); } render(){ return ( { !this.props.enabled ? The node you are using does not support Whisper The node uses an unsupported version of Whisper : '' }

Listen To channel

this.handleChange(e, 'listenTo')} />
{ this.state.subscribedChannels.map((item, i) =>

{item}

) }

messages received:

{ this.state.messageList.map((item, i) =>

{item}

) }

Send Message

this.handleChange(e, 'channel')} /> this.handleChange(e, 'message')} />

Javascript calls being made:

EmbarkJS.Messages.setProvider('whisper')

{ this.state.logs.map((item, i) =>

{item}

) }
); } } export default Whisper;