SES-101 Added Login to Signalr on GM

This commit is contained in:
Łukasz Góreczny 2020-12-19 18:43:21 +01:00
parent 3d33b981fe
commit 6145d9f594
5 changed files with 48 additions and 19 deletions

View File

@ -1,5 +1,6 @@
import { Component } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {animateText, onSideNavChange} from '../../shared/animations/sidenav-animations'; import {animateText, onSideNavChange} from '../../shared/animations/sidenav-animations';
import {GMSignalRService} from '../../shared/signalR-service/gm-signalR.service';
@Component({ @Component({
selector: 'app-game-master-dashboard', selector: 'app-game-master-dashboard',
@ -7,13 +8,17 @@ import {animateText, onSideNavChange} from '../../shared/animations/sidenav-anim
styleUrls: ['./game-master-dashboard.component.css'], styleUrls: ['./game-master-dashboard.component.css'],
animations: [onSideNavChange, animateText] animations: [onSideNavChange, animateText]
}) })
export class GameMasterDashboardComponent { export class GameMasterDashboardComponent implements OnInit {
leftSidenavExpanded = false; leftSidenavExpanded = false;
leftSidenavTextExpanded = false; leftSidenavTextExpanded = false;
rightSidenavExpanded = false; rightSidenavExpanded = false;
rightSidenavTextExpanded = false; rightSidenavTextExpanded = false;
constructor() {} constructor(private signalRService: GMSignalRService) {}
ngOnInit() {
this.signalRService.Login();
}
UpdateSidenavStatus(sidenav: string, newValue: boolean) { UpdateSidenavStatus(sidenav: string, newValue: boolean) {
switch (sidenav) { switch (sidenav) {

View File

@ -27,15 +27,19 @@ export class SignalRService {
public startConnection() { public startConnection() {
if (this.hubConnection.state === HubConnectionState.Connected) { if (this.hubConnection.state === HubConnectionState.Connected) {
return; return true;
} }
this.hubConnection.start().then( this.hubConnection.start().then(
() => { () => {
console.log('Hub connection started!'); console.log('Hub connection started!');
this.connectionEstablished$.next(true); this.connectionEstablished$.next(true);
return true;
}, },
error => console.error(error) error => {
console.error(error);
return false;
}
); );
} }
} }

View File

@ -8,7 +8,16 @@ export class GMSignalRService {
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();
}
public Login() {
this.signalR.startConnection(); this.signalR.startConnection();
this.signalR.connectionEstablished$.subscribe(() => {
if (this.signalR.connectionEstablished$.getValue() === true) {
this.signalR.hubConnection.send('GameMasterLogin');
}
});
} }
private registerOnServerEvents(): void { private registerOnServerEvents(): void {

View File

@ -11,7 +11,16 @@ export class PlayerSignalRService {
this.signalR.startConnection(); this.signalR.startConnection();
} }
private registerOnServerEvents(): void { public Login() {
this.signalR.startConnection();
this.signalR.connectionEstablished$.subscribe(() => {
if (this.signalR.connectionEstablished$.getValue() === true) {
this.signalR.hubConnection.send('GameMasterLogin');
}
});
}
private registerOnServerEvents(): void {
} }
} }

View File

@ -11,6 +11,13 @@
<param name="characterId">Identyfikator postaci</param> <param name="characterId">Identyfikator postaci</param>
<returns>ViewModel Postaci/ErrorResponse</returns> <returns>ViewModel Postaci/ErrorResponse</returns>
</member> </member>
<member name="M:SessionCompanion.Controllers.CharacterController.GetCharacterListForUser(System.Int32)">
<summary>
Metoda zwraca listę postaci przypisanych do danego użytkownika
</summary>
<param name="userId"> Identyfikator użytkownika </param>
<returns> Lista postać lub wiadomość błędu </returns>
</member>
<member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)"> <member name="M:SessionCompanion.Controllers.UserController.Login(System.String,System.String)">
<summary> <summary>
Metoda przyjmuje login oraz hasło i sprawdza czy istnieje użytkownik o podanych parametrach Metoda przyjmuje login oraz hasło i sprawdza czy istnieje użytkownik o podanych parametrach
@ -32,14 +39,9 @@
</summary> </summary>
<returns>true jesli ktoś jest już zalogowany i false jeśli nie</returns> <returns>true jesli ktoś jest już zalogowany i false jeśli nie</returns>
</member> </member>
<member name="F:SessionCompanion.Hubs.SessionHub.ConnectedCharacters"> <member name="F:SessionCompanion.Hubs.SessionHub.sessionHubData">
<summary> <summary>
Lista zalogowanych graczy i identyfikator wybranej postaci Klasa zawierająca wszystkie dane potrzebne w SignalR odnośnie aktualnej sesji
</summary>
</member>
<member name="F:SessionCompanion.Hubs.SessionHub.GameMasterConnected">
<summary>
Status, czy GM został już zalogowany
</summary> </summary>
</member> </member>
<member name="M:SessionCompanion.Hubs.SessionHub.OnDisconnectedAsync(System.Exception)"> <member name="M:SessionCompanion.Hubs.SessionHub.OnDisconnectedAsync(System.Exception)">