Browse Source

More good changes

update-deps
Alex Mikhalev 7 years ago
parent
commit
ddc834d2f3
  1. 3
      app/index.tsx
  2. 2
      app/state/index.ts
  3. 9
      common/logger.ts
  4. 11
      common/mqtt.ts
  5. 2
      server/app/serveApp.ts
  6. 16
      server/index.ts
  7. 5
      server/log.ts
  8. 2
      tslint.json

3
app/index.tsx

@ -4,6 +4,9 @@ import { AppContainer } from "react-hot-loader"; @@ -4,6 +4,9 @@ import { AppContainer } from "react-hot-loader";
import App from "@app/components/App";
import { ProvideState, State } from "@app/state";
import log, { setLogger } from "@common/log";
setLogger(log.child({ name: "sprinklers3/app" }));
const state = new State();
state.start();

2
app/state/index.ts

@ -11,7 +11,7 @@ export interface IState { @@ -11,7 +11,7 @@ export interface IState {
}
export class State implements IState {
sprinklersApi: ISprinklersApi = new MqttApiClient();
sprinklersApi: ISprinklersApi = new MqttApiClient(`ws://${location.hostname}:1884`);
uiStore = new UiStore();
constructor() {

9
common/logger.ts

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
import * as pino from "pino";
let logger: pino.Logger = pino();
export function setLogger(newLogger: pino.Logger) {
logger = newLogger;
}
export default logger;

11
common/mqtt.ts

@ -11,16 +11,17 @@ import { @@ -11,16 +11,17 @@ import {
SectionRunner,
SprinklersDevice,
TimeOfDay,
} from "@common/sprinklers";
import { checkedIndexOf } from "@common/utils";
} from "./sprinklers";
import { checkedIndexOf } from "./utils";
export class MqttApiClient implements ISprinklersApi {
readonly mqttUri: string;
client: mqtt.Client;
connected: boolean;
devices: { [prefix: string]: MqttSprinklersDevice } = {};
constructor() {
// (this.client as any).trace = (m => console.log(m));
constructor(mqttUri: string) {
this.mqttUri = mqttUri;
}
private static newClientId() {
@ -30,7 +31,7 @@ export class MqttApiClient implements ISprinklersApi { @@ -30,7 +31,7 @@ export class MqttApiClient implements ISprinklersApi {
start() {
const clientId = MqttApiClient.newClientId();
console.log("connecting to mqtt with client id %s", clientId);
this.client = mqtt.connect(`ws://${location.hostname}:1884`, {
this.client = mqtt.connect(this.mqttUri, {
clientId,
});
this.client.on("message", this.onMessageArrived.bind(this));

2
server/app/serveApp.ts

@ -3,7 +3,7 @@ import * as webpack from "webpack"; @@ -3,7 +3,7 @@ import * as webpack from "webpack";
import * as webpackMiddleware from "webpack-dev-middleware";
import * as webpackHotMiddleware from "webpack-hot-middleware";
import logger from "../log";
import logger from "../../common/logger";
const log = logger.child({ source: "webpack" });
/* tslint:disable-next-line:no-var-requires */

16
server/index.ts

@ -1,16 +1,14 @@ @@ -1,16 +1,14 @@
import { Server } from "http";
import log, { setLogger } from "../common/logger";
import app from "./app";
import log from "./log";
import * as mqtt from "mqtt";
setLogger(log.child({ name: "sprinklers3/server" }));
const mqttClient = mqtt.connect("mqtt://localhost:1882");
mqttClient.on("connect", () => {
log.info("mqtt connected");
});
mqttClient.on("error", (err) => {
log.error("mqtt error: ", err);
});
import * as mqtt from "../common/mqtt";
const mqttClient = new mqtt.MqttApiClient("mqtt://localhost:1882");
mqttClient.start();
const server = new Server(app);

5
server/log.ts

@ -1,5 +0,0 @@ @@ -1,5 +0,0 @@
import * as pino from "pino";
const log = pino();
export default log;

2
tslint.json

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
"jsRules": {},
"rules": {
"no-console": [
false
true
],
"max-classes-per-file": [
false

Loading…
Cancel
Save