features/dialog-camera into master 1 year ago
| RUN sed -i 's/index index.html index.htm;/try_files $uri \/index.html;/' /etc/nginx/conf.d/default.conf | RUN sed -i 's/index index.html index.htm;/try_files $uri \/index.html;/' /etc/nginx/conf.d/default.conf | ||||
| COPY /dist/lot-web-ui /usr/share/nginx/html | COPY /dist/lot-web-ui /usr/share/nginx/html | ||||
| #FROM node:18-alpine | |||||
| #WORKDIR /app | |||||
| #COPY dist/ots-landing-page-ssr . | |||||
| #EXPOSE 80 | |||||
| #CMD node server/server.mjs |
| import { SocketService } from './shared/services/socket.service'; | import { SocketService } from './shared/services/socket.service'; | ||||
| import { AlarmSoundService } from './shared/services/alarm-sound.service'; | import { AlarmSoundService } from './shared/services/alarm-sound.service'; | ||||
| import {MqttClientService} from "./shared/services/mqtt-client.service"; | import {MqttClientService} from "./shared/services/mqtt-client.service"; | ||||
| import {takeUntil} from "rxjs/operators"; | |||||
| import {filter, Subject} from "rxjs"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-root', | selector: 'app-root', | ||||
| }) | }) | ||||
| export class AppComponent implements OnInit { | export class AppComponent implements OnInit { | ||||
| title = 'Iot-web-ui'; | title = 'Iot-web-ui'; | ||||
| private unsubscribeAll = new Subject(); | |||||
| isConnected = false; | |||||
| constructor(private socketService$: SocketService, private mqtt$: MqttClientService) {} | constructor(private socketService$: SocketService, private mqtt$: MqttClientService) {} | ||||
| ngOnInit() { | ngOnInit() { | ||||
| // this.socketService$.connect(); | // this.socketService$.connect(); | ||||
| this.mqtt$.createConnection(); | this.mqtt$.createConnection(); | ||||
| this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe( | |||||
| (isConnected: boolean) => { | |||||
| this.isConnected = isConnected; | |||||
| this.mqtt$.getLog(); | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''}); | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''}); | |||||
| this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => { | |||||
| if (message.id == '0' && message.whistletime) { | |||||
| localStorage.setItem('whistletime', message.whistletime); | |||||
| } | |||||
| if (message.id == '0' && message.arlamtime) { | |||||
| localStorage.setItem('alarmtime', message.arlamtime); | |||||
| } | |||||
| }); | |||||
| }, | |||||
| ); | |||||
| } | } | ||||
| } | } |
| } from '@angular/core'; | } from '@angular/core'; | ||||
| import * as L from 'leaflet'; | import * as L from 'leaflet'; | ||||
| import 'leaflet.markercluster'; | import 'leaflet.markercluster'; | ||||
| import { Subscription, take } from 'rxjs'; | |||||
| import {filter, Subject, Subscription, take} from 'rxjs'; | |||||
| import { SocketService } from '../../../shared/services/socket.service'; | import { SocketService } from '../../../shared/services/socket.service'; | ||||
| import { MatDialog } from '@angular/material/dialog'; | import { MatDialog } from '@angular/material/dialog'; | ||||
| import { AlarmSoundService } from '../../../shared/services/alarm-sound.service'; | import { AlarmSoundService } from '../../../shared/services/alarm-sound.service'; | ||||
| import { CameraDialogComponent } from '../../../shared/component/camera-dialog/camera-dialog.component'; | import { CameraDialogComponent } from '../../../shared/component/camera-dialog/camera-dialog.component'; | ||||
| import { alarmData, alarmDemo } from '../data/fake-data'; | import { alarmData, alarmDemo } from '../data/fake-data'; | ||||
| import {takeUntil} from "rxjs/operators"; | |||||
| import {MqttClientService} from "../../../shared/services/mqtt-client.service"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-centralized-security-management', | selector: 'app-centralized-security-management', | ||||
| { | { | ||||
| private map!: L.Map; | private map!: L.Map; | ||||
| private markers!: L.MarkerClusterGroup; | private markers!: L.MarkerClusterGroup; | ||||
| private statusSubscription?: Subscription; | |||||
| private messageSubscription?: Subscription; | |||||
| data = alarmData; | data = alarmData; | ||||
| alarmDemo = alarmDemo; | alarmDemo = alarmDemo; | ||||
| state1 = false; | state1 = false; | ||||
| status2 = false; | status2 = false; | ||||
| state5 = false; | state5 = false; | ||||
| state6 = false; | state6 = false; | ||||
| isReady = true; | |||||
| private unsubscribeAll = new Subject(); | |||||
| constructor( | constructor( | ||||
| private socketService$: SocketService, | private socketService$: SocketService, | ||||
| private dialog: MatDialog, | private dialog: MatDialog, | ||||
| private renderer: Renderer2, | private renderer: Renderer2, | ||||
| private alarmSoundService$: AlarmSoundService, | private alarmSoundService$: AlarmSoundService, | ||||
| private mqtt$: MqttClientService | |||||
| ) {} | ) {} | ||||
| ngOnInit() { | ngOnInit() { | ||||
| this.statusSubscription = this.socketService$.status$.subscribe( | |||||
| this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe( | |||||
| (isConnected) => { | (isConnected) => { | ||||
| if (isConnected) { | if (isConnected) { | ||||
| this.socketService$.sendMessage({ id: '0', type: 'get' }); | |||||
| this.messageSubscription = this.socketService$.messages$.subscribe( | |||||
| (message) => { | |||||
| this.onMessage(message); | |||||
| }, | |||||
| ); | |||||
| this.mqtt$.getLog(); | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get' }); | |||||
| this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe(message => { | |||||
| console.log('map:',message); | |||||
| this.onMessage(message); | |||||
| }); | |||||
| } | } | ||||
| }, | }, | ||||
| ); | ); | ||||
| } | } | ||||
| ngOnDestroy(): void { | ngOnDestroy(): void { | ||||
| this.statusSubscription?.unsubscribe(); | |||||
| this.messageSubscription?.unsubscribe(); | |||||
| this.socketService$.close(); | |||||
| this.alarmSoundService$.stopAlarm(); | this.alarmSoundService$.stopAlarm(); | ||||
| this.unsubscribeAll.next(''); | |||||
| this.unsubscribeAll.complete(); | |||||
| } | } | ||||
| initMap(): void { | initMap(): void { | ||||
| } | } | ||||
| onMessage(message: any) { | onMessage(message: any) { | ||||
| if (message.id == '0' && message.type === 'get') { | |||||
| this.state1 = message.state1 === '0'; // 1 OFF // alarm 12h | |||||
| this.status1 = message.status1 === '1'; // 0 not, 1 ready, 2 error, 3 bypass | |||||
| this.state2 = message.state2 === '0'; // 1 OFF // alarm 1h | |||||
| this.status2 = message.status2 === '1'; // 0 not, 1 ready, 2 error, 3 bypass | |||||
| this.state5 = message.state5 === '1'; // 1 ON, 0 OFF | |||||
| this.isReady = message.ready === '1'; | |||||
| this.alarmSoundService$.startAlarm(this.state5, this.state1,this.status1, this.state2, this.status2); | |||||
| if (message.id == '0' && message.type == 'get') { | |||||
| this.state1 = message.state1 == '0'; // 1 OFF // alarm 12h | |||||
| this.status1 = message.status1 == '1'; // 0 not, 1 ready, 2 error, 3 bypass | |||||
| this.state2 = message.state2 == '0'; // 1 OFF // alarm 1h | |||||
| this.status2 = message.status2 == '1'; // 0 not, 1 ready, 2 error, 3 bypass | |||||
| this.state5 = message.state5 == '1'; // 1 ON, 0 OFF | |||||
| this.alarmSoundService$.startAlarm(this.state5, this.state1, this.status1, this.state2, this.status2); | |||||
| this.updateIcons(); | this.updateIcons(); | ||||
| } | } | ||||
| } | } | ||||
| addMarker(item: any, isDemo: boolean = false): void { | addMarker(item: any, isDemo: boolean = false): void { | ||||
| console.log(this.state5, this.state1, this.status1) | |||||
| const icon = isDemo | const icon = isDemo | ||||
| ? this.getIcon(this.state5, this.state1, this.status1, this.state2, this.status2) | ? this.getIcon(this.state5, this.state1, this.status1, this.state2, this.status2) | ||||
| : this.createIcon(item.warning); | : this.createIcon(item.warning); | ||||
| <div><strong>Địa điểm:</strong> ${item.detail.position}</div> | <div><strong>Địa điểm:</strong> ${item.detail.position}</div> | ||||
| <div><strong>Tọa độ:</strong> ${item.detail.coordinates.lat}, ${item.detail.coordinates.lng}</div> | <div><strong>Tọa độ:</strong> ${item.detail.coordinates.lat}, ${item.detail.coordinates.lng}</div> | ||||
| <div><strong>Thời gian:</strong> ${item.detail.time}</div> | <div><strong>Thời gian:</strong> ${item.detail.time}</div> | ||||
| <a href="/overview/security-system-details" target="_blank">Xem chi tiết</a> | |||||
| <a href="/homepage/security-system-details" target="_blank">Xem chi tiết</a> | |||||
| </div>`; | </div>`; | ||||
| } | } | ||||
| import {Component, OnDestroy, OnInit} from '@angular/core'; | import {Component, OnDestroy, OnInit} from '@angular/core'; | ||||
| import {SocketService} from "../../../shared/services/socket.service"; | import {SocketService} from "../../../shared/services/socket.service"; | ||||
| import {Subscription, Subject} from "rxjs"; | |||||
| import {Subscription, Subject, filter, take} 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"; | ||||
| (isConnected: boolean) => { | (isConnected: boolean) => { | ||||
| this.isConnected = isConnected; | this.isConnected = isConnected; | ||||
| this.mqtt$.getLog(); | this.mqtt$.getLog(); | ||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''}); | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''}); | |||||
| this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll)).subscribe((message: any) => { | |||||
| console.log(message); | |||||
| setTimeout(() => { | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', whistletime: ''}); | |||||
| }, 500); | |||||
| setTimeout(() => { | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get', arlamtime: ''}); | |||||
| }, 1000); | |||||
| this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe((message: any) => { | |||||
| if (message.id == '0' && message.whistletime) { | if (message.id == '0' && message.whistletime) { | ||||
| this.whistle.time = Number(message.whistletime); | this.whistle.time = Number(message.whistletime); | ||||
| } | } | ||||
| emitSetting(type: string, event: any){ | emitSetting(type: string, event: any){ | ||||
| if (this.isConnected) { | if (this.isConnected) { | ||||
| console.log(event); | |||||
| if (type === 'whistle') { | if (type === 'whistle') { | ||||
| this.whistle.time = event; | this.whistle.time = event; | ||||
| this.mqtt$.sendPublish({ id: '0', type: 'set', whistletime: event.toString()}); | this.mqtt$.sendPublish({ id: '0', type: 'set', whistletime: event.toString()}); |
| .sensor-on { | .sensor-on { | ||||
| width: 30px; | width: 30px; | ||||
| height: 30px; | height: 30px; | ||||
| position: absolute; | |||||
| position: relative; | |||||
| background: linear-gradient(#ff0000, #c70039); | background: linear-gradient(#ff0000, #c70039); | ||||
| display: flex !important; | display: flex !important; | ||||
| justify-content: center; | justify-content: center; |
| import {Component, OnDestroy, OnInit} from '@angular/core'; | import {Component, OnDestroy, OnInit} from '@angular/core'; | ||||
| import {Subscription} from "rxjs"; | |||||
| import {debounceTime, filter, Subject, Subscription} from "rxjs"; | |||||
| import {SocketService} from "../../../shared/services/socket.service"; | import {SocketService} from "../../../shared/services/socket.service"; | ||||
| import {CameraDialogComponent} from "../../../shared/component/camera-dialog/camera-dialog.component"; | import {CameraDialogComponent} from "../../../shared/component/camera-dialog/camera-dialog.component"; | ||||
| import {MatDialog} from "@angular/material/dialog"; | import {MatDialog} from "@angular/material/dialog"; | ||||
| import { ConfirmDialogService } from '../../../shared/services/confirm-dialog.service'; | import { ConfirmDialogService } from '../../../shared/services/confirm-dialog.service'; | ||||
| import { AlarmSoundService } from "../../../shared/services/alarm-sound.service"; | import { AlarmSoundService } from "../../../shared/services/alarm-sound.service"; | ||||
| import { MqttClientService } from "../../../shared/services/mqtt-client.service"; | import { MqttClientService } from "../../../shared/services/mqtt-client.service"; | ||||
| import {takeUntil} from "rxjs/operators"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-security-system-details', | selector: 'app-security-system-details', | ||||
| switchArm = false; | switchArm = false; | ||||
| switchWarning = false; | switchWarning = false; | ||||
| isReady = true; | isReady = true; | ||||
| private statusSubscription?: Subscription; | |||||
| private messageSubscription?: Subscription; | |||||
| private intervalId: any; | private intervalId: any; | ||||
| private unsubscribeAll = new Subject(); | |||||
| constructor( | constructor( | ||||
| private socketService$: SocketService, | private socketService$: SocketService, | ||||
| ) {} | ) {} | ||||
| ngOnInit() { | ngOnInit() { | ||||
| this.statusSubscription = this.mqtt$.status$.subscribe((isConnected) => { | |||||
| this.mqtt$.status$.pipe(takeUntil(this.unsubscribeAll)).subscribe((isConnected) => { | |||||
| this.isConnected = isConnected; | this.isConnected = isConnected; | ||||
| if (isConnected){ | if (isConnected){ | ||||
| this.mqtt$.getLog(); | this.mqtt$.getLog(); | ||||
| this.messageSubscription = this.mqtt$.messages$.subscribe(message => { | |||||
| console.log('MQTT sup msg: ',message); | |||||
| this.mqtt$.sendPublish({ id: '0', type: 'get'}); | |||||
| this.mqtt$.messages$.pipe(takeUntil(this.unsubscribeAll), filter((item) => item !== null)).subscribe(message => { | |||||
| console.log('detail:',message); | |||||
| this.onMessage(message); | this.onMessage(message); | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| ngOnDestroy(): void { | ngOnDestroy(): void { | ||||
| if (this.statusSubscription) { | |||||
| this.statusSubscription.unsubscribe(); | |||||
| } | |||||
| if (this.messageSubscription) { | |||||
| this.messageSubscription.unsubscribe(); | |||||
| } | |||||
| this.unsubscribeAll.next(''); | |||||
| this.unsubscribeAll.complete(); | |||||
| if (this.intervalId) { | if (this.intervalId) { | ||||
| clearInterval(this.intervalId); | clearInterval(this.intervalId); | ||||
| } | } | ||||
| this.socketService$.close(); | |||||
| this.alarmSoundService$.stopAlarm(); | this.alarmSoundService$.stopAlarm(); | ||||
| } | } | ||||
| Output, | Output, | ||||
| } from '@angular/core'; | } from '@angular/core'; | ||||
| import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; | ||||
| import {debounceTime, Subject} from 'rxjs'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-slider-range', | selector: 'app-slider-range', | ||||
| @Input() icon: string = ''; | @Input() icon: string = ''; | ||||
| @Input() disable: boolean = false; | @Input() disable: boolean = false; | ||||
| @Output() valueChange = new EventEmitter<number>(); | @Output() valueChange = new EventEmitter<number>(); | ||||
| onChange = (value: number) => {}; | onChange = (value: number) => {}; | ||||
| onTouched = () => {}; | onTouched = () => {}; | ||||
| private valueChangeSubject = new Subject<number>(); | |||||
| constructor() {} | |||||
| constructor() { | |||||
| this.valueChangeSubject.pipe(debounceTime(500)).subscribe(value => { | |||||
| this.valueChange.emit(value); | |||||
| }); | |||||
| } | |||||
| writeValue(value: number): void { | writeValue(value: number): void { | ||||
| this.value = value; | this.value = value; | ||||
| this.value = event.target.value; | this.value = event.target.value; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| onSliderChangeBackground() { | onSliderChangeBackground() { | ||||
| this.value += 10; | this.value += 10; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| } | } | ||||
| this.value -= 10; | this.value -= 10; | ||||
| this.onChange(this.value); | this.onChange(this.value); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.valueChange.emit(this.value); | |||||
| this.valueChangeSubject.next(this.value); | |||||
| } | } | ||||
| } | } | ||||
| } | } |
| isConnection = false; | isConnection = false; | ||||
| private statusSubject = new BehaviorSubject<boolean>(this.isConnection); | private statusSubject = new BehaviorSubject<boolean>(this.isConnection); | ||||
| public status$ = this.statusSubject.asObservable(); | public status$ = this.statusSubject.asObservable(); | ||||
| private messagesSubject$ = new Subject(); | |||||
| private messagesSubject$ = new BehaviorSubject(null); | |||||
| public messages$ = this.messagesSubject$.asObservable(); | public messages$ = this.messagesSubject$.asObservable(); | ||||
| // 创建连接 | // 创建连接 | ||||
| topic: 'isoft/node 4/log4', | topic: 'isoft/node 4/log4', | ||||
| qos: 0, | qos: 0, | ||||
| }; | }; | ||||
| this.client?.observe(topic, { qos } as IClientSubscribeOptions).subscribe((message: IMqttMessage) => { | |||||
| this.client?.observe(topic, { qos, dup: false } as IClientSubscribeOptions).subscribe((message: IMqttMessage) => { | |||||
| try { | try { | ||||
| console.log('Subscribe to topics res', message.payload.toString()); | |||||
| var plainMessage = ""; | |||||
| let plainMessage = ""; | |||||
| for (var i = 0; i < message.payload.length; i++) { | for (var i = 0; i < message.payload.length; i++) { | ||||
| plainMessage += String.fromCharCode(parseInt(String(message.payload[i]))); | plainMessage += String.fromCharCode(parseInt(String(message.payload[i]))); | ||||
| } | } | ||||
| console.log(JSON.parse(plainMessage)); | |||||
| this.messagesSubject$.next(JSON.parse(plainMessage)); | this.messagesSubject$.next(JSON.parse(plainMessage)); | ||||
| }catch (e) { | }catch (e) { | ||||
| console.log(e); | console.log(e); | ||||
| // 发送消息 | // 发送消息 | ||||
| sendPublish(data: any) { | sendPublish(data: any) { | ||||
| this.client?.unsafePublish("isoft/node 4/in4", JSON.stringify(data), {qos: 0} as IPublishOptions); | this.client?.unsafePublish("isoft/node 4/in4", JSON.stringify(data), {qos: 0} as IPublishOptions); | ||||
| // this.client?.publish("isoft/node 4/in4", JSON.stringify(data), {qos: 0} as IPublishOptions).subscribe(); | |||||
| } | } | ||||
| // 断开连接 | // 断开连接 | ||||
| destroyConnection() { | destroyConnection() { |