SES-140 connected Player with SignalR #61

Merged
s426134 merged 2 commits from SES-140 into dev 2021-01-09 22:24:29 +01:00
3 changed files with 18 additions and 20 deletions

View File

@ -1,15 +1,27 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { AbilityViewModel } from "../../../types/viewmodels/ability-viewmodels/AbilityViewModel"; import { AbilityViewModel } from "../../../types/viewmodels/ability-viewmodels/AbilityViewModel";
import { PlayerSignalRService } from "../../shared/signalR-service/player-signalR.service";
import { first } from "rxjs/operators";
import { Store } from '@ngrx/store';
import { AppState } from 'src/app/store/models/app-state.model';
@Component({ @Component({
selector: 'app-player-dashboard', selector: 'app-player-dashboard',
templateUrl: './player-dashboard.component.html', templateUrl: './player-dashboard.component.html',
styleUrls: ['./player-dashboard.component.css'], styleUrls: ['./player-dashboard.component.css'],
}) })
export class PlayerDashboardComponent { export class PlayerDashboardComponent implements OnInit {
isExpanded = false; isExpanded = false;
selected = false; selected = false;
constructor(private signalRService: PlayerSignalRService, private store: Store<AppState>) {}
ngOnInit() {
this.store.select(s => s.playerStore.characterId).pipe(first()).subscribe((id) => {
this.signalRService.Login(id);
});
}
ability: AbilityViewModel = { ability: AbilityViewModel = {
id: 1, id: 1,
name: 'Strength', name: 'Strength',
@ -26,10 +38,6 @@ export class PlayerDashboardComponent {
] ]
} }
collapse() {
this.isExpanded = false;
}
toggle() { toggle() {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
} }

View File

@ -3,10 +3,9 @@ import { FormGroup, Validators, FormBuilder } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import {UserService} from '../../../services/user.service'; import {UserService} from '../../../services/user.service';
import {ErrorResponse} from '../../../types/ErrorResponse'; import {ErrorResponse} from '../../../types/ErrorResponse';
import {Observable, Subscription} from 'rxjs'; import {Subscription} from 'rxjs';
import {HttpErrorResponse} from '@angular/common/http'; import {HttpErrorResponse} from '@angular/common/http';
import {AppStoreModel} from '../../store/models/app-store.model'; import {Store} from '@ngrx/store';
import {select, Store} from '@ngrx/store';
import {AddUserId} from '../../store/actions/app.actions'; import {AddUserId} from '../../store/actions/app.actions';
import {AppState} from 'src/app/store/models/app-state.model'; import {AppState} from 'src/app/store/models/app-state.model';
import {first} from "rxjs/operators"; import {first} from "rxjs/operators";
@ -18,9 +17,6 @@ import {first} from "rxjs/operators";
}) })
export class SignInComponent implements OnDestroy, OnInit { export class SignInComponent implements OnDestroy, OnInit {
allSubscriptions = new Subscription(); allSubscriptions = new Subscription();
role$: Observable<AppStoreModel>;
isExpanded = false; isExpanded = false;
apiError = false; apiError = false;
apiErrorMessage = ''; apiErrorMessage = '';
@ -39,7 +35,6 @@ export class SignInComponent implements OnDestroy, OnInit {
}); });
ngOnInit() { ngOnInit() {
this.role$ = this.store.select(s => s.appStore);
} }
onLoginButtonClick() { onLoginButtonClick() {
@ -77,10 +72,6 @@ export class SignInComponent implements OnDestroy, OnInit {
this.router.navigate(['']); this.router.navigate(['']);
} }
collapse() {
this.isExpanded = false;
}
toggle() { toggle() {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
} }

View File

@ -8,15 +8,14 @@ export class PlayerSignalRService {
constructor(@Inject('BASE_URL') baseUrl: string) { constructor(@Inject('BASE_URL') baseUrl: string) {
this.signalR = new SignalRService(baseUrl); this.signalR = new SignalRService(baseUrl);
this.registerOnServerEvents(); this.registerOnServerEvents();
this.signalR.startConnection();
} }
public Login() { public Login(characterId: number) {
this.signalR.startConnection(); this.signalR.startConnection();
this.signalR.connectionEstablished$.subscribe(() => { this.signalR.connectionEstablished$.subscribe(() => {
if (this.signalR.connectionEstablished$.getValue() === true) { if (this.signalR.connectionEstablished$.getValue() === true) {
this.signalR.hubConnection.send('GameMasterLogin'); this.signalR.hubConnection.send('PlayerCharacterLogin', characterId);
} }
}); });
} }