First commit

This commit is contained in:
uwap 2017-09-12 19:17:33 +02:00
commit 9d69521b26
14 changed files with 3636 additions and 0 deletions

22
src/mqtt.js Normal file
View file

@ -0,0 +1,22 @@
// @flow
import mqtt from "mqtt";
import { MQTT_MESSAGE, MQTT_CONNECT, MQTT_DISCONNECT } from "./stateActions";
import { Store } from "redux";
import Config from "./config";
import R from "ramda";
export default function connectMqtt(url: string, store: Store<*,*>) {
const client = mqtt.connect(url);
client.on("connect", () => {
store.dispatch({
type: MQTT_CONNECT, mqtt: client
});
R.forEachObjIndexed(v =>
client.subscribe(v.state), Config.topics);
});
client.on("message", (topic, message) => {
store.dispatch({
type: "mqtt_message", message: message, topic: topic
});
});
}