Skip to content

Commit

Permalink
feat: remove exchange and support active driving mode (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
mghilardelli authored Nov 15, 2024
1 parent de45cfd commit ba8f9a2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Optional<OperationMode> selectOperationMode(List<OperationMode> incomingO
return getObserver(statusReportEnabled);
}
if (validModes.contains(driver)) {
return Optional.empty();
return Optional.of(driver);
}
if (validModes.contains(observer)) {
return getObserver(!statusReportEnabled);
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/app/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class AuthService {

}

/**
* deprecated
*/
exchange(ru: string = '', train: string = '', role: string = ''): Observable<string> {
return this.httpClient.get(`${environment.backendUrl}/customClaim/requestToken`, {
params: new HttpParams().set('ru', ru).set('train', train).set('role', role),
Expand Down
5 changes: 2 additions & 3 deletions webapp/src/app/mqtt-playground/mqtt-playground.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { MqService } from "../mq.service";
import { SbbIcon } from "@sbb-esta/angular/icon";
import { AsyncPipe } from "@angular/common";
import { MqttConnectionState } from "ngx-mqtt";
import { AuthService } from "../auth.service";
import { firstValueFrom, map } from "rxjs";
import { OidcSecurityService } from "angular-auth-oidc-client";

Expand All @@ -23,8 +22,8 @@ import { OidcSecurityService } from "angular-auth-oidc-client";
})
export class MqttPlaygroundComponent implements OnDestroy {

constructor(public mqService: MqService, private authService: AuthService, private oidcSecurityService: OidcSecurityService) {
this.authService.exchange().subscribe(async token => {
constructor(public mqService: MqService, private oidcSecurityService: OidcSecurityService) {
this.oidcSecurityService.getAccessToken().subscribe(async token => {
const userName = await firstValueFrom(this.oidcSecurityService.getUserData().pipe(map((data) => data?.preferred_username)));
this.mqService.connect(userName, token)
});
Expand Down
8 changes: 2 additions & 6 deletions webapp/src/app/sfera-observer/sfera-observer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { SbbFormFieldModule } from "@sbb-esta/angular/form-field";
import { SbbInputModule } from "@sbb-esta/angular/input";
import { MqService } from "../mq.service";
import { SbbButtonModule } from "@sbb-esta/angular/button";
import { SimpleXmlComponent } from "../simple-xml/simple-xml.component";
import { AuthService } from "../auth.service";
import { firstValueFrom, map, Subscription } from "rxjs";
import { CommonModule } from "@angular/common";
import { MqttConnectionState } from "ngx-mqtt";
Expand All @@ -27,7 +25,6 @@ import { SbbAccordionModule } from "@sbb-esta/angular/accordion";
SbbInputModule,
SbbButtonModule,
SbbCheckboxModule,
SimpleXmlComponent,
MessageTableComponent,
SbbAccordionModule,
],
Expand Down Expand Up @@ -55,7 +52,6 @@ export class SferaObserverComponent implements OnDestroy {
protected readonly MqttConnectionState = MqttConnectionState;

constructor(private oidcSecurityService: OidcSecurityService,
private authService: AuthService,
protected mqService: MqService) {
}

Expand All @@ -65,9 +61,9 @@ export class SferaObserverComponent implements OnDestroy {
this.g2bTopic = customTopicPrefix + '90940/2/G2B/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value;
this.b2gTopic = customTopicPrefix + '90940/2/B2G/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value;
this.eventTopic = customTopicPrefix + '90940/2/event/' + this.companyControl.value + '/' + trainOperation;
const exchangeToken = await firstValueFrom(this.authService.exchange(this.companyControl.value, trainOperation, 'read-only'));
const token = await firstValueFrom(this.oidcSecurityService.getAccessToken());
const username = await firstValueFrom(this.oidcSecurityService.getUserData().pipe(map((data) => data?.preferred_username)));
await this.mqService.connect(username, exchangeToken);
await this.mqService.connect(username, token);

this.g2bSubscription = this.mqService.observe(this.g2bTopic)
.subscribe(value => {
Expand Down

0 comments on commit ba8f9a2

Please sign in to comment.