Browse Source

update refactor

features/add-popup
Trung Nguyen 1 year ago
parent
commit
fb06dd9445
6 changed files with 14 additions and 11 deletions
  1. +3
    -1
      angular.json
  2. +3
    -3
      src/app/app.component.ts
  3. +2
    -0
      src/app/app.constants.ts
  4. +1
    -2
      src/app/app.module.ts
  5. +3
    -3
      src/app/modules/homepage/homepage/home-page.component.ts
  6. +2
    -2
      src/app/shared/services/mqtt-client.service.ts

+ 3
- 1
angular.json View File

@@ -41,7 +41,9 @@
"scripts": [],
"allowedCommonJsDependencies": [
"leaflet",
"leaflet.markercluster"
"leaflet.markercluster",
"mqtt-browser",
"rtsp-relay/browser"
]
},
"configurations": {

+ 3
- 3
src/app/app.component.ts View File

@@ -5,7 +5,7 @@ import {
import {MqttClientService} from "./shared/services/mqtt-client.service";
import {takeUntil} from "rxjs/operators";
import {filter, Subject} from "rxjs";
import {TOPIC_SETTING} from "./app.constants";
import {TOPIC_GETTING, TOPIC_SETTING} from "./app.constants";

@Component({
selector: 'app-root',
@@ -25,8 +25,8 @@ export class AppComponent implements OnInit {
this.isConnected = isConnected;
this.mqtt$.getSetting();
this.mqtt$.getLog();
this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''}, TOPIC_SETTING);
this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''}, TOPIC_SETTING);
this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''}, TOPIC_GETTING);
this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''}, TOPIC_GETTING);
this.mqtt$.setting$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => {
if (message.id == '0' && message.whistletime) {
localStorage.setItem('whistletime', message.whistletime);

+ 2
- 0
src/app/app.constants.ts View File

@@ -1,3 +1,5 @@
export const TOPIC_SETTING = 'isoft/node 4/setting4';
export const TOPIC_GETTING = 'isoft/node 4/getting4';

export const TOPIC_LOG = 'isoft/node 4/log4';
export const TOPIC_INFO = 'isoft/node 4/in4';

+ 1
- 2
src/app/app.module.ts View File

@@ -15,12 +15,11 @@ export const connection: IMqttServiceOptions = {
connectTimeout: 4000, // 超时时间
reconnectPeriod: 4000, // 重连时间间隔
// 认证信息
clientId: 'pm-1720539453210',
clientId: 'iot-' + Date.parse(new Date().toString()),
protocol: 'ws',
connectOnCreate: false,
}


@NgModule({
declarations: [
AppComponent,

+ 3
- 3
src/app/modules/homepage/homepage/home-page.component.ts View File

@@ -2,7 +2,7 @@ import {Component, OnDestroy, OnInit} from '@angular/core';
import {Subject, filter} from "rxjs";
import {MqttClientService} from "../../../shared/services/mqtt-client.service";
import {takeUntil} from "rxjs/operators";
import {TOPIC_SETTING} from "../../../app.constants";
import {TOPIC_GETTING, TOPIC_SETTING} from "../../../app.constants";

@Component({
selector: 'app-homepage',
@@ -46,10 +46,10 @@ export class HomePageComponent implements OnInit, OnDestroy {
if (this.isConnected) {
if (type === 'whistle') {
this.whistle.time = event;
this.mqtt$.sendPublish({id: '0', type: 'set', whistletime: event.toString()}, TOPIC_SETTING);
this.mqtt$.sendPublish({id: '0', type: 'set', whistletime: event.toString()}, TOPIC_GETTING);
} else if (type === 'alarm') {
this.alarm.time = event;
this.mqtt$.sendPublish({id: '0', type: 'set', arlamtime: event.toString()}, TOPIC_SETTING);
this.mqtt$.sendPublish({id: '0', type: 'set', arlamtime: event.toString()}, TOPIC_GETTING);
}
}
}

+ 2
- 2
src/app/shared/services/mqtt-client.service.ts View File

@@ -8,7 +8,7 @@ import {
} from 'ngx-mqtt';
import { IClientSubscribeOptions } from 'mqtt-browser';
import {BehaviorSubject, Observable, Subject, Subscription} from 'rxjs';
import {TOPIC_INFO, TOPIC_LOG, TOPIC_SETTING} from "../../app.constants";
import {TOPIC_GETTING, TOPIC_INFO, TOPIC_LOG, TOPIC_SETTING} from "../../app.constants";

@Injectable({
providedIn: 'root'
@@ -34,7 +34,7 @@ export class MqttClientService {
public status$ = this.statusSubject.asObservable();
private messagesSubject$ = new BehaviorSubject(null);
public messages$ = this.messagesSubject$.asObservable();
private settingSubject$ = new Subject();
private settingSubject$ = new BehaviorSubject(null);
public setting$ = this.settingSubject$.asObservable();

// 创建连接

Loading…
Cancel
Save