| "scripts": [], | "scripts": [], | ||||
| "allowedCommonJsDependencies": [ | "allowedCommonJsDependencies": [ | ||||
| "leaflet", | "leaflet", | ||||
| "leaflet.markercluster" | |||||
| "leaflet.markercluster", | |||||
| "mqtt-browser", | |||||
| "rtsp-relay/browser" | |||||
| ] | ] | ||||
| }, | }, | ||||
| "configurations": { | "configurations": { |
| import {MqttClientService} from "./shared/services/mqtt-client.service"; | import {MqttClientService} from "./shared/services/mqtt-client.service"; | ||||
| import {takeUntil} from "rxjs/operators"; | import {takeUntil} from "rxjs/operators"; | ||||
| import {filter, Subject} from "rxjs"; | import {filter, Subject} from "rxjs"; | ||||
| import {TOPIC_SETTING} from "./app.constants"; | |||||
| import {TOPIC_GETTING, TOPIC_SETTING} from "./app.constants"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-root', | selector: 'app-root', | ||||
| this.isConnected = isConnected; | this.isConnected = isConnected; | ||||
| this.mqtt$.getSetting(); | this.mqtt$.getSetting(); | ||||
| this.mqtt$.getLog(); | 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) => { | this.mqtt$.setting$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => { | ||||
| if (message.id == '0' && message.whistletime) { | if (message.id == '0' && message.whistletime) { | ||||
| localStorage.setItem('whistletime', message.whistletime); | localStorage.setItem('whistletime', message.whistletime); |
| export const TOPIC_SETTING = 'isoft/node 4/setting4'; | 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_LOG = 'isoft/node 4/log4'; | ||||
| export const TOPIC_INFO = 'isoft/node 4/in4'; | export const TOPIC_INFO = 'isoft/node 4/in4'; |
| connectTimeout: 4000, // 超时时间 | connectTimeout: 4000, // 超时时间 | ||||
| reconnectPeriod: 4000, // 重连时间间隔 | reconnectPeriod: 4000, // 重连时间间隔 | ||||
| // 认证信息 | // 认证信息 | ||||
| clientId: 'pm-1720539453210', | |||||
| clientId: 'iot-' + Date.parse(new Date().toString()), | |||||
| protocol: 'ws', | protocol: 'ws', | ||||
| connectOnCreate: false, | connectOnCreate: false, | ||||
| } | } | ||||
| @NgModule({ | @NgModule({ | ||||
| declarations: [ | declarations: [ | ||||
| AppComponent, | AppComponent, |
| import {Subject, filter} from "rxjs"; | import {Subject, filter} from "rxjs"; | ||||
| import {MqttClientService} from "../../../shared/services/mqtt-client.service"; | import {MqttClientService} from "../../../shared/services/mqtt-client.service"; | ||||
| import {takeUntil} from "rxjs/operators"; | import {takeUntil} from "rxjs/operators"; | ||||
| import {TOPIC_SETTING} from "../../../app.constants"; | |||||
| import {TOPIC_GETTING, TOPIC_SETTING} from "../../../app.constants"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-homepage', | selector: 'app-homepage', | ||||
| if (this.isConnected) { | if (this.isConnected) { | ||||
| if (type === 'whistle') { | if (type === 'whistle') { | ||||
| this.whistle.time = event; | 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') { | } else if (type === 'alarm') { | ||||
| this.alarm.time = event; | 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); | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| } from 'ngx-mqtt'; | } from 'ngx-mqtt'; | ||||
| import { IClientSubscribeOptions } from 'mqtt-browser'; | import { IClientSubscribeOptions } from 'mqtt-browser'; | ||||
| import {BehaviorSubject, Observable, Subject, Subscription} from 'rxjs'; | 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({ | @Injectable({ | ||||
| providedIn: 'root' | providedIn: 'root' | ||||
| public status$ = this.statusSubject.asObservable(); | public status$ = this.statusSubject.asObservable(); | ||||
| private messagesSubject$ = new BehaviorSubject(null); | private messagesSubject$ = new BehaviorSubject(null); | ||||
| public messages$ = this.messagesSubject$.asObservable(); | public messages$ = this.messagesSubject$.asObservable(); | ||||
| private settingSubject$ = new Subject(); | |||||
| private settingSubject$ = new BehaviorSubject(null); | |||||
| public setting$ = this.settingSubject$.asObservable(); | public setting$ = this.settingSubject$.asObservable(); | ||||
| // 创建连接 | // 创建连接 |