configuration stuff not yet working
This commit is contained in:
parent
af10384cb7
commit
3168b084d3
@ -11,6 +11,7 @@ let accessLogStream = fs.createWriteStream(path.join(__dirname, '/../../../acces
|
||||
app.use(morgan('combined', {stream: accessLogStream}))
|
||||
|
||||
app.use('/', express.static(path.join(__dirname, '/../../../dist')))
|
||||
app.use('/config', express.static(path.join(__dirname, '/.././../config')))
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log('smartclient app listening on port 3000!')
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { HttpClientModule } from '@angular/common/http'
|
||||
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import { MatExpansionModule } from '@angular/material/expansion';
|
||||
@ -8,6 +9,7 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
|
||||
import { MqttclientService } from './mqttclient.service'
|
||||
import { ConfigService } from './config.service'
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { LedindicatorComponent } from './ledindicator/ledindicator.component';
|
||||
@ -31,13 +33,15 @@ import { LedBoxComponent } from './led-box/led-box.component';
|
||||
imports: [
|
||||
BrowserModule,
|
||||
BrowserAnimationsModule,
|
||||
HttpClientModule,
|
||||
MatTabsModule,
|
||||
MatExpansionModule,
|
||||
MatButtonModule,
|
||||
MatDividerModule
|
||||
],
|
||||
providers: [
|
||||
MqttclientService
|
||||
MqttclientService,
|
||||
ConfigService
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
|
15
src/app/config.service.spec.ts
Normal file
15
src/app/config.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { ConfigService } from './config.service';
|
||||
|
||||
describe('ConfigService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ConfigService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ConfigService], (service: ConfigService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
25
src/app/config.service.ts
Normal file
25
src/app/config.service.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
export interface Config {
|
||||
mqttUrl: string
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class ConfigService {
|
||||
|
||||
private configUrl : string = 'assets/smartclient.json'
|
||||
private observableConfig : Observable<Config> = undefined
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
|
||||
}
|
||||
|
||||
getConfig() : Observable<Config> {
|
||||
if (this.observableConfig == undefined) {
|
||||
this.observableConfig = this.http.get<Config>(this.configUrl)
|
||||
}
|
||||
return this.observableConfig
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ConfigService, Config } from './config.service'
|
||||
import * as Mqtt from 'mqtt'
|
||||
|
||||
type callbackFunc = (message: string) => void
|
||||
@ -7,8 +8,9 @@ type callbackFunc = (message: string) => void
|
||||
export class MqttclientService {
|
||||
private mqttClient : Mqtt.MqttClient
|
||||
private callbacks : Map<string, callbackFunc> = new Map()
|
||||
private config : Config
|
||||
|
||||
constructor() {
|
||||
constructor(private configService: ConfigService) {
|
||||
this.mqttClient = Mqtt.connect('ws://127.0.0.1:9001')
|
||||
this.mqttClient.on('connect', () => {
|
||||
console.log('MQTT connected')
|
||||
|
3
src/assets/smartclient.json
Normal file
3
src/assets/smartclient.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"mqttUrl": "ws://127.0.0.1:9100"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user