fix whisper demo

This commit is contained in:
Jonathan Rainville 2018-05-02 12:24:16 -04:00
parent 41b2741ba5
commit f303d3d839

View File

@ -1,6 +1,6 @@
import EmbarkJS from 'Embark/EmbarkJS'; import EmbarkJS from 'Embark/EmbarkJS';
import React from 'react'; import React from 'react';
import { Alert, Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; import {Alert, Form, FormGroup, FormControl, Button} from 'react-bootstrap';
class Whisper extends React.Component { class Whisper extends React.Component {
@ -14,7 +14,7 @@ class Whisper extends React.Component {
subscribedChannels: [], subscribedChannels: [],
messageList: [], messageList: [],
logs: [] logs: []
} };
} }
handleChange (e, name) { handleChange (e, name) {
@ -31,10 +31,23 @@ class Whisper extends React.Component {
listenToChannel (e) { listenToChannel (e) {
e.preventDefault(); e.preventDefault();
this.state.subscribedChannels.push(`subscribed to ${this.state.listenTo} now try sending a message`); const subscribedChannels = this.state.subscribedChannels;
subscribedChannels.push(<span>Subscribed to <b>{this.state.listenTo}</b>. Now try sending a message</span>);
this.setState({
subscribedChannels
});
EmbarkJS.Messages.listenTo({topic: [this.state.listenTo]}) EmbarkJS.Messages.listenTo({topic: [this.state.listenTo]}, (error, message) => {
.then(message => this.state.messageList.push(`channel: ${this.state.listenTo} message: ${message}`)) const messageList = this.state.messageList;
if (error) {
messageList.push(<span className="alert-danger">Error: {error}</span>);
} else {
messageList.push(<span>Channel: <b>{message.topic}</b> | Message: <b>{message.data}</b></span>);
}
this.setState({
messageList
});
});
this.addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.listenTo + "']}).then(function(message) {})"); this.addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.listenTo + "']}).then(function(message) {})");
} }