Browse Source

check state

features/sensor
Trung Nguyen 1 year ago
parent
commit
0cc9b6e9c5
4 changed files with 13 additions and 20 deletions
  1. +1
    -1
      src/app/modules/overview/overall-ground/overall-ground.component.scss
  2. +6
    -17
      src/app/modules/overview/overall-ground/overall-ground.component.ts
  3. +3
    -2
      src/app/shared/services/socket.service.ts
  4. +3
    -0
      src/config.ts

+ 1
- 1
src/app/modules/overview/overall-ground/overall-ground.component.scss View File

@@ -76,7 +76,7 @@ p {
/*.button:hover {background-color: #0f8b8d}*/
.button:active {
background-color: #0f8b8d;
box-shadow: 2 2px #CDCDCD;
box-shadow: 2px 2px #CDCDCD;
transform: translateY(2px);
}


+ 6
- 17
src/app/modules/overview/overall-ground/overall-ground.component.ts View File

@@ -1,4 +1,4 @@
import {ChangeDetectorRef, Component, OnChanges, OnDestroy, OnInit, SimpleChanges} from '@angular/core';
import { Component, OnDestroy, OnInit } from '@angular/core';
import {SocketService} from "../../../shared/services/socket.service";
import {Subscription} from "rxjs";

@@ -8,16 +8,9 @@ import {Subscription} from "rxjs";
styleUrls: ['./overall-ground.component.scss']
})
export class OverallGroundComponent implements OnInit, OnDestroy{
isClicked = false;
isConnected = false;
state1 = '';
state2 = '';
state3 = '';
state4 = '';
state5 = '';
state6 = '';
Sstate1 = false;
Sstate2 = false;
private statusSubscription?: Subscription;
private messageSubscription?: Subscription;
private intervalId: any;
@@ -27,7 +20,7 @@ export class OverallGroundComponent implements OnInit, OnDestroy{
}

ngOnInit() {
this.socketService$.connect();
this.socketService$.connect();
this.statusSubscription = this.socketService$.status$.subscribe(isConnected => {
this.isConnected = isConnected;
if (this.isConnected) {
@@ -39,10 +32,6 @@ export class OverallGroundComponent implements OnInit, OnDestroy{
});
}

toggleColor(): void {
this.isClicked = !this.isClicked;
}

ngOnDestroy(): void {
if (this.statusSubscription) {
this.statusSubscription.unsubscribe();
@@ -61,14 +50,14 @@ export class OverallGroundComponent implements OnInit, OnDestroy{
this.socketService$.sendMessage(str);
}
toggleState1() {
this.Sstate1 = (this.state5 !== 'ON'); // toggle on when state 5 off.
let str = { id: '0', type: 'cmd', state1: this.Sstate1.toString() };
const state = (this.state5 !== 'ON'); // toggle on when state 5 off.
let str = { id: '0', type: 'cmd', state1: state.toString() };
this.socketService$.sendMessage(str);
}

toggleState2() {
this.Sstate2 = (this.state6 !== 'ON'); // toggle on when state 6 off.
let str = { id: '0', type: 'cmd', state2: this.Sstate2.toString() };
const state = (this.state6 !== 'ON'); // toggle on when state 6 off.
let str = { id: '0', type: 'cmd', state2: state.toString() };
this.socketService$.sendMessage(str);
}


+ 3
- 2
src/app/shared/services/socket.service.ts View File

@@ -1,12 +1,13 @@
import { Injectable } from '@angular/core';
import { webSocket, WebSocketSubject } from 'rxjs/webSocket';
import {BehaviorSubject, catchError, delayWhen, Observable, retryWhen, Subject, tap, timer} from "rxjs";
import { BehaviorSubject, Subject } from "rxjs";
import { config } from "../../../config";

@Injectable({
providedIn: 'root'
})
export class SocketService {
gateway = 'ws:/socket.aztrace.vn/ws';
gateway = config.gateway;
websocket$!: WebSocketSubject<any> ;
private isConnected: boolean = false;
private messagesSubject$ = new Subject();

+ 3
- 0
src/config.ts View File

@@ -0,0 +1,3 @@
export const config = {
gateway: 'ws:/socket.aztrace.vn/ws'
};

Loading…
Cancel
Save