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";
import App from "@app/components/App"; import App from "@app/components/App";
import { ProvideState, State } from "@app/state"; import { ProvideState, State } from "@app/state";
import log, { setLogger } from "@common/log";
setLogger(log.child({ name: "sprinklers3/app" }));
const state = new State(); const state = new State();
state.start(); state.start();

2
app/state/index.ts

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

9
common/logger.ts

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

2
server/app/serveApp.ts

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

16
server/index.ts

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

5
server/log.ts

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

2
tslint.json

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

Loading…
Cancel
Save