React MQTT Workflow Manager is a React component library designed to wrap all the MQTT sub-logic behind the scenes and must be used to work with Workflow API Layer. It only deals with events, not commands. The manager communicates with your broker to dispatch actions in your front-end application.
- Installation
- Dependencies
- Usage
- Example of usage
- Properties
- WorkflowManagerConfig
- Hooks
- Running locally
- Authors
- License
npm install @flowbuild/react-mqtt-workflow-manager --saveor
yarn add @flowbuild/react-mqtt-workflow-managerThe WorkflowManager component peer depends on the React and React DOM in version 18.
npm i react@18 react-dom@18- Before using the component, set the store with
WorkflowManagerConfig.setStore.
// App.tsx
import * as React from 'react';
import { WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
import { store } from './store'; // Your redux store
WorkflowManagerConfig.setStore(store);
// ...- Wrap your application with
WorkflowManager.
// App.tsx
import * as React from 'react';
import { Provider } from 'react-redux';
import { WorkflowManager, WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
import { store } from './store'; // Your redux store
WorkflowManagerConfig.setStore(store);
export const App: React.FC = () => {
return (
<Provider store={store}>
<WorkflowManager
brokerUrl="ws://broker.mqttdashboard.com:8000/mqtt"
options={{
clientId: `clientId-${Math.random().toString(36).substring(2, 9)}`,
keepalive: 60,
}}
>
{/* Your child component here */}
</WorkflowManager>
</Provider>
);
};- Lastly, set
workflowManagerReduceron your store reducers.
import { configureStore, createSlice } from '@reduxjs/toolkit';
import { workflowManagerReducer, WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
const myAppSlice = createSlice({
name: '@myApp',
...
});
export const store = configureStore({
reducer: { myApp: myAppSlice.reducer, workflowManagerReducer },
});A complete example of how to use it can be found here.
| Property | Type | Required | Description |
|---|---|---|---|
brokerUrl |
string | true | URL to connect to broker. Use full URL like wss://... |
options |
IClientOptions | false | MQTT client options. See options config here. |
The library also provides methods and utilities for your commodity. They can be used outside the context of react components.
The library uses your redux store to dispatch actions. This is used to control and dispatch internal actions for your application.
A utility method that can be used outside the context of react components. Be careful; the method must be able to return null if an error occurs when setting connect. See client config here.
Works exactly like mqtt#subscribe, but the library implements validations and internal rules.
Works exactly like mqtt#unsubscribe, but the library implements validations and internal rules.
Some hooks are exported for commodity.
The hook returns a object contaning client, status and error.
| Property | Type | Default value | Description |
|---|---|---|---|
client |
MqttClient | null |
See client here. |
status |
string | offline |
connecting, connected, disconnected, reconnecting, offline or error. |
error |
Error | null |
Returns WorkflowManagerConfig.subscribe for your commodity.
Returns WorkflowManagerConfig.unsubscribe for your commodity.
Clone the project
git clone https://github.com/flow-build/react-mqtt-workflow-manager.gitGo to the project directory
cd react-mqtt-workflow-managerInstall dependencies
npm installStart the development server
npm run devGo to the project example directory
cd appInstall de example dependencies
npm installStart the example application
npm run start