dev
This commit is contained in:
parent
26f08d9dc1
commit
4b921835e4
|
|
@ -11,88 +11,7 @@ using System.Diagnostics;
|
||||||
|
|
||||||
namespace KoogleApp.Hub
|
namespace KoogleApp.Hub
|
||||||
{
|
{
|
||||||
public class HubConnectionService : IAsyncDisposable
|
|
||||||
{
|
|
||||||
private readonly NavigationManager _navigationManager;
|
|
||||||
private readonly AuthenticationStateProvider _authenticationStateProvider;
|
|
||||||
private HubConnection? _hubConnection;
|
|
||||||
private string? _userName;
|
|
||||||
|
|
||||||
public HubConnectionService(NavigationManager navigationManager,
|
|
||||||
AuthenticationStateProvider authenticationStateProvider)
|
|
||||||
{
|
|
||||||
_navigationManager = navigationManager;
|
|
||||||
_authenticationStateProvider = authenticationStateProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HubConnection Connection => _hubConnection
|
|
||||||
?? throw new InvalidOperationException("Connection not initialized");
|
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
|
||||||
{
|
|
||||||
if (_hubConnection != null)
|
|
||||||
await _hubConnection.DisposeAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task ConnectToHub(IDispatcher dispatcher)
|
|
||||||
{
|
|
||||||
var authState = await _authenticationStateProvider.GetAuthenticationStateAsync();
|
|
||||||
var user = authState.User;
|
|
||||||
var isAuthenticated = user.Identity?.IsAuthenticated ?? false;
|
|
||||||
_userName = isAuthenticated ? user.Identity?.Name : "Gast";
|
|
||||||
|
|
||||||
|
|
||||||
_hubConnection = new HubConnectionBuilder()
|
|
||||||
.WithUrl(_navigationManager.ToAbsoluteUri("/sharedmodelhub"))
|
|
||||||
.WithAutomaticReconnect()
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_hubConnection.On<ThrowPanelState>("ReceiveThrowPanelState", state =>
|
|
||||||
{
|
|
||||||
dispatcher.Dispatch(new ReceiveStateFromServerAction(state));
|
|
||||||
});
|
|
||||||
|
|
||||||
// _hubConnection.On<string>("ReceiveTextUpdate", (newText) =>
|
|
||||||
// {
|
|
||||||
// _sharedText = newText;
|
|
||||||
// InvokeAsync(StateHasChanged);
|
|
||||||
// });
|
|
||||||
|
|
||||||
await _hubConnection.StartAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task HandelBroadcastThrowPanelStateAction(BroadcastThrowPanelStateAction action, IDispatcher dispatcher)
|
|
||||||
{
|
|
||||||
if (_hubConnection?.State != HubConnectionState.Connected)
|
|
||||||
{
|
|
||||||
//_logger.LogWarning("Cannot add activity: not connected");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_hubConnection is not null)
|
|
||||||
{
|
|
||||||
await _hubConnection.SendAsync("BroadcastThrowPanelState", action.State);
|
|
||||||
}
|
|
||||||
|
|
||||||
//await Clients.Others.SendAsync("ReceiveThrowPanelState", new ThrowPanelState());
|
|
||||||
|
|
||||||
//await _hubConnection.InvokeAsync("StartStopAction", stopAction);
|
|
||||||
|
|
||||||
// Der Server wird ActivityAdded an alle Clients senden,
|
|
||||||
// einschließlich diesem. Dann wird ActivityAddedAction dispatched.
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//_logger.LogError(ex, "Failed to add activity");
|
|
||||||
// Optional: Error-Handling Action dispatchen
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SharedModelHub : Microsoft.AspNetCore.SignalR.Hub
|
public class SharedModelHub : Microsoft.AspNetCore.SignalR.Hub
|
||||||
{
|
{
|
||||||
private readonly IGameStatusDataService _dataService;
|
private readonly IGameStatusDataService _dataService;
|
||||||
|
|
@ -111,8 +30,6 @@ namespace KoogleApp.Hub
|
||||||
_authenticationStateProvider = authenticationStateProvider;
|
_authenticationStateProvider = authenticationStateProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task UpdateThrowPanelState(ThrowPanelState panelState, string username)
|
public async Task UpdateThrowPanelState(ThrowPanelState panelState, string username)
|
||||||
{
|
{
|
||||||
await Clients.All.SendAsync("UpdateThrowPanelState", panelState);
|
await Clients.All.SendAsync("UpdateThrowPanelState", panelState);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
public class GameStatus
|
public class GameStatus
|
||||||
{
|
{
|
||||||
public string Content { get; set; }
|
public ThrowPanelState? ThrowPanelState { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//public class DataSnapshot
|
//public class DataSnapshot
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace KoogleApp.Services
|
||||||
{
|
{
|
||||||
Status = new GameStatus
|
Status = new GameStatus
|
||||||
{
|
{
|
||||||
Content = "Willkommen! Starte die Zusammenarbeit.",
|
|
||||||
},
|
},
|
||||||
Version = 1,
|
Version = 1,
|
||||||
LastModified = DateTime.Now,
|
LastModified = DateTime.Now,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
using Fluxor;
|
||||||
|
using KoogleApp.Model;
|
||||||
|
using KoogleApp.Store.Game.ThrowPanel;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
|
||||||
|
namespace KoogleApp.Services
|
||||||
|
{
|
||||||
|
public class HubConnectionService : IAsyncDisposable
|
||||||
|
{
|
||||||
|
private readonly NavigationManager _navigationManager;
|
||||||
|
private readonly AuthenticationStateProvider _authenticationStateProvider;
|
||||||
|
private HubConnection? _hubConnection;
|
||||||
|
private string? _userName;
|
||||||
|
|
||||||
|
public HubConnectionService(NavigationManager navigationManager,
|
||||||
|
AuthenticationStateProvider authenticationStateProvider)
|
||||||
|
{
|
||||||
|
_navigationManager = navigationManager;
|
||||||
|
_authenticationStateProvider = authenticationStateProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HubConnection Connection => _hubConnection
|
||||||
|
?? throw new InvalidOperationException("Connection not initialized");
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
if (_hubConnection != null)
|
||||||
|
await _hubConnection.DisposeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ConnectToHub(IDispatcher dispatcher)
|
||||||
|
{
|
||||||
|
var authState = await _authenticationStateProvider.GetAuthenticationStateAsync();
|
||||||
|
var user = authState.User;
|
||||||
|
var isAuthenticated = user.Identity?.IsAuthenticated ?? false;
|
||||||
|
_userName = isAuthenticated ? user.Identity?.Name : "Gast";
|
||||||
|
|
||||||
|
|
||||||
|
_hubConnection = new HubConnectionBuilder()
|
||||||
|
.WithUrl(_navigationManager.ToAbsoluteUri("/sharedmodelhub"))
|
||||||
|
.WithAutomaticReconnect()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_hubConnection.On<ThrowPanelState>("ReceiveThrowPanelState", state =>
|
||||||
|
{
|
||||||
|
dispatcher.Dispatch(new ReceiveStateFromServerAction(state));
|
||||||
|
});
|
||||||
|
|
||||||
|
// _hubConnection.On<string>("ReceiveTextUpdate", (newText) =>
|
||||||
|
// {
|
||||||
|
// _sharedText = newText;
|
||||||
|
// InvokeAsync(StateHasChanged);
|
||||||
|
// });
|
||||||
|
|
||||||
|
await _hubConnection.StartAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task HandelBroadcastThrowPanelStateAction(BroadcastThrowPanelStateAction action, IDispatcher dispatcher)
|
||||||
|
{
|
||||||
|
if (_hubConnection?.State != HubConnectionState.Connected)
|
||||||
|
{
|
||||||
|
//_logger.LogWarning("Cannot add activity: not connected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (_hubConnection is not null)
|
||||||
|
{
|
||||||
|
await _hubConnection.SendAsync("BroadcastThrowPanelState", action.State);
|
||||||
|
}
|
||||||
|
|
||||||
|
//await Clients.Others.SendAsync("ReceiveThrowPanelState", new ThrowPanelState());
|
||||||
|
|
||||||
|
//await _hubConnection.InvokeAsync("StartStopAction", stopAction);
|
||||||
|
|
||||||
|
// Der Server wird ActivityAdded an alle Clients senden,
|
||||||
|
// einschließlich diesem. Dann wird ActivityAddedAction dispatched.
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//_logger.LogError(ex, "Failed to add activity");
|
||||||
|
// Optional: Error-Handling Action dispatchen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -11,29 +11,32 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
||||||
public class ThrowPanelEffects : IDisposable
|
public class ThrowPanelEffects : IDisposable
|
||||||
{
|
{
|
||||||
private readonly ILogger<ThrowPanelEffects> _logger;
|
private readonly ILogger<ThrowPanelEffects> _logger;
|
||||||
private readonly HubConnectionService _sharedModelHub;
|
private readonly HubConnectionService _sharedHubService;
|
||||||
private readonly IState<ThrowPanelState> _state;
|
private readonly IState<ThrowPanelState> _state;
|
||||||
private readonly SessionStorage _sessionStorage;
|
private readonly SessionStorage _sessionStorage;
|
||||||
private readonly string _dataFilePath = "ThrowPanelState.json";
|
private readonly string _dataFilePath = "ThrowPanelState.json";
|
||||||
private readonly AuthenticationStateProvider _authenticationStateProvider;
|
private readonly AuthenticationStateProvider _authenticationStateProvider;
|
||||||
|
private readonly IGameStatusDataService _dataService;
|
||||||
|
|
||||||
public ThrowPanelEffects(
|
public ThrowPanelEffects(
|
||||||
ILogger<ThrowPanelEffects> logger,
|
ILogger<ThrowPanelEffects> logger,
|
||||||
HubConnectionService sharedModelHub,
|
HubConnectionService sharedHubService,
|
||||||
IState<ThrowPanelState> state,
|
IState<ThrowPanelState> state,
|
||||||
AuthenticationStateProvider authenticationStateProvider,
|
AuthenticationStateProvider authenticationStateProvider,
|
||||||
|
IGameStatusDataService dataService,
|
||||||
SessionStorage sessionStorage)
|
SessionStorage sessionStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_sharedModelHub = sharedModelHub;
|
_sharedHubService = sharedHubService;
|
||||||
_state = state;
|
_state = state;
|
||||||
_sessionStorage = sessionStorage;
|
_sessionStorage = sessionStorage;
|
||||||
|
_dataService = dataService;
|
||||||
_authenticationStateProvider = authenticationStateProvider;
|
_authenticationStateProvider = authenticationStateProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
//_sharedModelHub?.Dispose();
|
//_sharedHubService?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
//[EffectMethod(typeof(StartStopAction))]
|
//[EffectMethod(typeof(StartStopAction))]
|
||||||
|
|
@ -83,7 +86,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _sharedModelHub.ConnectToHub(dispatcher);
|
await _sharedHubService.ConnectToHub(dispatcher);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -105,7 +108,8 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
||||||
{
|
{
|
||||||
var username = await GetUsername();
|
var username = await GetUsername();
|
||||||
Console.WriteLine(username);
|
Console.WriteLine(username);
|
||||||
////_dataService.UpdateData(state, _userName);
|
|
||||||
|
_dataService.UpdateData(new GameStatus{ ThrowPanelState = action.State}, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,7 +162,7 @@ namespace KoogleApp.Store.Game.ThrowPanel
|
||||||
[EffectMethod]
|
[EffectMethod]
|
||||||
public async Task HandelBroadcastThrowPanelStateAction(BroadcastThrowPanelStateAction action, IDispatcher dispatcher)
|
public async Task HandelBroadcastThrowPanelStateAction(BroadcastThrowPanelStateAction action, IDispatcher dispatcher)
|
||||||
{
|
{
|
||||||
await _sharedModelHub.HandelBroadcastThrowPanelStateAction(action, dispatcher);
|
await _sharedHubService.HandelBroadcastThrowPanelStateAction(action, dispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,25 @@
|
||||||
{
|
{
|
||||||
"IsStated": true,
|
"IsStated": true,
|
||||||
"BellValue": false,
|
"BellValue": false,
|
||||||
"Pin1Value": true,
|
"Pin1Value": false,
|
||||||
"Pin2Value": true,
|
"Pin2Value": false,
|
||||||
"Pin3Value": false,
|
"Pin3Value": false,
|
||||||
"Pin4Value": true,
|
"Pin4Value": false,
|
||||||
"Pin5Value": false,
|
"Pin5Value": false,
|
||||||
"Pin6Value": false,
|
"Pin6Value": false,
|
||||||
"Pin7Value": false,
|
"Pin7Value": false,
|
||||||
"Pin8Value": false,
|
"Pin8Value": false,
|
||||||
"Pin9Value": false,
|
"Pin9Value": false,
|
||||||
"Pin1Disabled": true,
|
"Pin1Disabled": false,
|
||||||
"Pin2Disabled": true,
|
"Pin2Disabled": false,
|
||||||
"Pin3Disabled": false,
|
"Pin3Disabled": false,
|
||||||
"Pin4Disabled": true,
|
"Pin4Disabled": false,
|
||||||
"Pin5Disabled": false,
|
"Pin5Disabled": false,
|
||||||
"Pin6Disabled": false,
|
"Pin6Disabled": false,
|
||||||
"Pin7Disabled": false,
|
"Pin7Disabled": false,
|
||||||
"Pin8Disabled": false,
|
"Pin8Disabled": false,
|
||||||
"Pin9Disabled": false,
|
"Pin9Disabled": false,
|
||||||
"ThrowsPerRound": 3,
|
"ThrowsPerRound": 3,
|
||||||
"ThrowCounter": 3,
|
"ThrowCounter": 1,
|
||||||
"ThrowMode": 1
|
"ThrowMode": 1
|
||||||
}
|
}
|
||||||
|
|
@ -1,16 +1,72 @@
|
||||||
{
|
{
|
||||||
"CurrentData": {
|
"CurrentData": {
|
||||||
"Status": {
|
"Status": {
|
||||||
"Content": "Willkommen! Starte die Zusammenarbeit."
|
"ThrowPanelState": {
|
||||||
|
"IsStated": true,
|
||||||
|
"BellValue": false,
|
||||||
|
"Pin1Value": false,
|
||||||
|
"Pin2Value": false,
|
||||||
|
"Pin3Value": false,
|
||||||
|
"Pin4Value": false,
|
||||||
|
"Pin5Value": false,
|
||||||
|
"Pin6Value": false,
|
||||||
|
"Pin7Value": false,
|
||||||
|
"Pin8Value": false,
|
||||||
|
"Pin9Value": false,
|
||||||
|
"Pin1Disabled": false,
|
||||||
|
"Pin2Disabled": false,
|
||||||
|
"Pin3Disabled": false,
|
||||||
|
"Pin4Disabled": false,
|
||||||
|
"Pin5Disabled": false,
|
||||||
|
"Pin6Disabled": false,
|
||||||
|
"Pin7Disabled": false,
|
||||||
|
"Pin8Disabled": false,
|
||||||
|
"Pin9Disabled": false,
|
||||||
|
"ThrowsPerRound": 3,
|
||||||
|
"ThrowCounter": 1,
|
||||||
|
"ThrowMode": 1
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Version": 3,
|
"Version": 4,
|
||||||
"LastModified": "2025-11-05T20:53:27.735651+01:00",
|
"LastModified": "2025-11-10T21:34:15.3376837+01:00",
|
||||||
"LastModifiedBy": "test1@test.de"
|
"LastModifiedBy": "test1@test.de"
|
||||||
},
|
},
|
||||||
"UndoHistory": [
|
"UndoHistory": [
|
||||||
{
|
{
|
||||||
"Status": {
|
"Status": {
|
||||||
"Content": "Willkommen! Starte die Zusammenarbeit."
|
"ThrowPanelState": {
|
||||||
|
"IsStated": true,
|
||||||
|
"BellValue": false,
|
||||||
|
"Pin1Value": false,
|
||||||
|
"Pin2Value": false,
|
||||||
|
"Pin3Value": false,
|
||||||
|
"Pin4Value": false,
|
||||||
|
"Pin5Value": false,
|
||||||
|
"Pin6Value": false,
|
||||||
|
"Pin7Value": false,
|
||||||
|
"Pin8Value": false,
|
||||||
|
"Pin9Value": false,
|
||||||
|
"Pin1Disabled": false,
|
||||||
|
"Pin2Disabled": false,
|
||||||
|
"Pin3Disabled": false,
|
||||||
|
"Pin4Disabled": false,
|
||||||
|
"Pin5Disabled": false,
|
||||||
|
"Pin6Disabled": false,
|
||||||
|
"Pin7Disabled": false,
|
||||||
|
"Pin8Disabled": false,
|
||||||
|
"Pin9Disabled": false,
|
||||||
|
"ThrowsPerRound": 3,
|
||||||
|
"ThrowCounter": 1,
|
||||||
|
"ThrowMode": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Version": 3,
|
||||||
|
"LastModified": "2025-11-05T20:53:27.735651+01:00",
|
||||||
|
"LastModifiedBy": "test1@test.de"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Status": {
|
||||||
|
"ThrowPanelState": null
|
||||||
},
|
},
|
||||||
"Version": 2,
|
"Version": 2,
|
||||||
"LastModified": "2025-11-03T19:09:57.4404986+01:00",
|
"LastModified": "2025-11-03T19:09:57.4404986+01:00",
|
||||||
|
|
@ -18,7 +74,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Status": {
|
"Status": {
|
||||||
"Content": "Willkommen! Starte die Zusammenarbeit."
|
"ThrowPanelState": null
|
||||||
},
|
},
|
||||||
"Version": 1,
|
"Version": 1,
|
||||||
"LastModified": "2025-11-03T19:08:40.9909294+01:00",
|
"LastModified": "2025-11-03T19:08:40.9909294+01:00",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue