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.sendMessage = this.sendMessage.bind(this); this.listenToChannel = this.listenToChannel.bind(this); 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(); let listenTo = this.state.listenTo; this.state.subscribedChannels.push(`subscribed to ${listenTo} now try sending a message`); EmbarkJS.Messages.listenTo({topic: [listenTo]}) .then(message => this.state.messageList.push(`channel: ${listenTo} message: ${message}`)) this._addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.channel + "']}).then(function(message) {})"); } _addToLog(txt){ this.state.logs.push(txt); this.setState({logs: this.state.logs}); } render(){ return ( { !this.state.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;