import React, { useEffect, useState } from 'react'; import { Handle, Position } from 'reactflow'; interface IData { message: string; channel: string description: string mqttClient?: any; autoClient?: any; } interface PublishNodeProps { data: IData } export const PublishNode: React.FunctionComponent = ({ data: { message , channel, description, mqttClient, autoClient }, }) => { const [topic, setTopic] = useState(channel || ''); const [payload, setPayload] = useState(message || ''); const [qos, setQos] = useState(0); const client = mqttClient || autoClient const handleClick = () => { if (client) { client.publish(topic, payload, { qos: qos }, function (err) { console.log(topic,payload,"T&Pwhild publishing") if (err) { console.error(err); } }); } }; useEffect(() => { if(autoClient){ autoClient.connect() } }, []) return (
YOU CAN PUBLISH

{channel}

{description && (
{description}
)}

Messages Payloads you can publish using this channel
console.log('handle onConnect', params)} />
setTopic(e.target.value)} style={{ appearance: 'none', display: 'block', width: '100%', backgroundColor: '#edf2f7', color: '#4a5568', border: '1px solid #edf2f7', borderRadius: '0.25rem', padding: '0.75rem 1rem', marginBottom: '0.75rem', lineHeight: '1.5', outline: 'none' }} />
); }; export default PublishNode;