diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 02c1d74d..ee340614 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -76,6 +76,21 @@ export const processLogs = { failure: (error) => action(PROCESS_LOGS[FAILURE], {error}) }; +export const MESSAGE_LISTEN = createRequestTypes('MESSAGE_LISTEN'); +export const messageListen = { + request: (channel) => action(MESSAGE_LISTEN[REQUEST], {channel}), + success: (message) => action(MESSAGE_LISTEN[SUCCESS], {message}), + failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error}) +}; + +export const MESSAGE_SEND = createRequestTypes('MESSAGE_SEND'); +export const messageSend = { + request: (body) => action(MESSAGE_SEND[REQUEST], {body}), + success: () => action(MESSAGE_SEND[SUCCESS]), + failure: (error) => action(MESSAGE_SEND[FAILURE], {error}) +}; + + export const CONTRACTS = createRequestTypes('CONTRACTS'); export const contracts = { request: () => action(CONTRACTS[REQUEST]), diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index d30b7b3b..e59665b3 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -1,7 +1,6 @@ import axios from "axios"; import constants from '../constants'; - function get(path, params) { return axios.get(constants.httpEndpoint + path, params) .then((response) => { @@ -65,6 +64,14 @@ export function fetchContract(payload) { return get(`/contract/${payload.contractName}`); } +export function sendMessage(payload) { + return post(`/communication/sendMessage`, payload); +} + +export function listenToChannel(channel) { + return new WebSocket(`${constants.wsEndpoint}/communication/listenTo/${channel}`); +} + export function fetchContractProfile(payload) { return get(`/profiler/${payload.contractName}`); } diff --git a/embark-ui/src/containers/CommunicationContainer.js b/embark-ui/src/containers/CommunicationContainer.js index bfd38a06..6efc1b48 100644 --- a/embark-ui/src/containers/CommunicationContainer.js +++ b/embark-ui/src/containers/CommunicationContainer.js @@ -1,5 +1,8 @@ +import PropTypes from "prop-types"; import React, {Component} from 'react'; +import connect from "react-redux/es/connect/connect"; import {Alert, Button, Form, Icon} from 'tabler-react'; +import {messageSend, messageListen} from "../actions"; class CommunicationContainer extends Component { constructor(props) { @@ -23,8 +26,7 @@ class CommunicationContainer extends Component { sendMessage(e) { e.preventDefault(); - // TODO send message via API - console.log('Send', this.state.message); + this.props.messageSend({topic: this.state.channel, message: this.state.message}); this.addToLog("EmbarkJS.Messages.sendMessage({topic: '" + this.state.channel + "', data: '" + this.state.message + "'})"); } @@ -37,20 +39,7 @@ class CommunicationContainer extends Component { subscribedChannels }); - console.log('Listen to', this.state.listenTo); - // TODO listen to channel via API - /*EmbarkJS.Messages.listenTo({topic: [this.state.listenTo]}, (error, message) => { - const messageList = this.state.messageList; - if (error) { - messageList.push(Error: {error}); - } else { - messageList.push(Channel: {message.topic} | Message: {message.data}); - } - this.setState({ - messageList - }); - });*/ - + this.props.messageListen(this.state.listenTo); this.addToLog("EmbarkJS.Messages.listenTo({topic: ['" + this.state.listenTo + "']}).then(function(message) {})"); } @@ -85,16 +74,25 @@ class CommunicationContainer extends Component {
{item}
)}Messages received:
-{item}
)} -Messages received:
+{channelName}
+ {this.props.messages.channels[channelName].messages.map((message, f) => { + return{message}
; + })} +