| @@ -41,7 +41,9 @@ | |||
| "scripts": [], | |||
| "allowedCommonJsDependencies": [ | |||
| "leaflet", | |||
| "leaflet.markercluster" | |||
| "leaflet.markercluster", | |||
| "mqtt-browser", | |||
| "rtsp-relay/browser" | |||
| ] | |||
| }, | |||
| "configurations": { | |||
| @@ -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); | |||
| @@ -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'; | |||
| @@ -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, | |||
| @@ -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); | |||
| } | |||
| } | |||
| } | |||
| @@ -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(); | |||
| // 创建连接 | |||