protected override async Task OnInitializedAsync() { bool IsNewConnection = false; if (!Networker.IsConnected) { IsNewConnection = true; await Networker.Connect(NavigationManager.ToAbsoluteUri("/gamehub")); } if (Networker.IsConnected) { if (!IsNewConnection) { MessageReset(); } Networker.hubConnection.On <string, string>("Load:GM", GoToRoom); Networker.hubConnection.On <string, string>("Load:Player", GoToRoom); Networker.hubConnection.On("Get:PlayerName", async() => { view = "player"; StateHasChanged(); await FocusElement("#name"); }); Networker.hubConnection.On("Error:RoomNotFound", async() => { errorMessage = "Room not found"; room.RoomCode = ""; StateHasChanged(); await FocusElement("#okay-button"); }); Networker.hubConnection.On("Error:RoomIsLocked", async() => { errorMessage = "Room " + room.RoomCode.ToUpper() + " is locked"; StateHasChanged(); await FocusElement("#okay-button"); }); } await FocusElement("#roomCode"); }
public async Task Connect(string roomCode, RoomBase room, NavigationManager navManager, IJSRuntime jsRuntime, Tabletop tabletop) { JSRuntime = jsRuntime; NavigationManager = navManager; RoomCode = roomCode; Room = room; Tabletop = tabletop; bool newConnection = false; if (!Networker.IsConnected) { newConnection = true; await Networker.Connect(NavigationManager.ToAbsoluteUri("/gamehub")); } if (Networker.IsConnected) { if (!newConnection) { MessageReset(); } Networker.hubConnection.On("Error:RoomNotFound", Redirect); Networker.hubConnection.On("Error:PlayerNotFound", Redirect); Networker.hubConnection.On <bool, List <PlayerEntity>, string, bool, List <Image> >("Sync:TabletopInfo", Room.SyncTabletop); Networker.hubConnection.On <List <Entity> >("Sync:CombatOrder", Room.UpdateCombatOrder); Networker.hubConnection.On <string>("Set:PlayerUID", UpdateUID); Networker.hubConnection.On <bool, string, string>("Set:PlayerStatus", Room.UpdatePlayerStatus); Networker.hubConnection.On <Message>("Set:Message", Room.RenderMessage); Networker.hubConnection.On("Player:Kick", HandleKick); Networker.hubConnection.On <String, string, int[], int, int[], List <Cell>, bool, bool>("Tabletop:LoadImage", Room.RenderTabletopFromImage); Networker.hubConnection.On("Tabletop:Clear", Room.ClearTabletop); Networker.hubConnection.On <List <PlayerEntity> >("Tabletop:RenderPlayerEntities", Room.RenderPlayerEntities); Networker.hubConnection.On <List <Creature> >("Tabletop:RenderCreatureEntities", Room.RenderCreatureEntities); Networker.hubConnection.On <List <NPC> >("Tabletop:RenderNPCEntities", Room.RenderNPCEntities); Networker.hubConnection.On <int, string>("Tabletop:SyncCells", Room.SyncCells); Networker.hubConnection.On <string, int[]>("Tabletop:UpdateEntityPosition", UpdateEntityPosition); Networker.hubConnection.On <bool>("Tabletop:UpdateLock", Room.UpdateLock); Networker.hubConnection.On <Image>("Tabletop:LoadPopupImage", RenderPopupImage); Networker.hubConnection.On <bool>("Tabletop:ToggleVisibility", Room.SetTabletopVisibility); Networker.hubConnection.On <List <Light> >("Tabletop:RenderLightEntities", Room.RenderLightEntities); Networker.hubConnection.On <bool>("Tabletop:UpdateDiceRolls", Room.UpdateDiceRolls); Networker.hubConnection.On <string>("Notification:PlayerConnected", ConnectedNotification); Networker.hubConnection.On <string, string>("Notification:PlayerDisconnected", DisconnectedNotification); Networker.hubConnection.On <string>("Notification:PlayerReconnected", ReconnectedNotification); Networker.hubConnection.On <string>("Notification:PlayerKicked", KickNotification); Networker.hubConnection.On("Notification:TakeTurn", TakeTurnNotification); Networker.hubConnection.On("Notification:OnDeck", OnDeckNotification); Networker.hubConnection.On <string>("Notification:EntityOnDeck", EntityOnDeckNotification); Networker.hubConnection.On <int, int>("Notification:Ping", Room.RenderPing); Networker.hubConnection.On <int, string, string, string>("Notification:Roll", Room.RenderRollNotification); Networker.hubConnection.On <string>("Entity:RenderDeathCelebration", RenderDeathCelebration); Networker.hubConnection.On <Entity, string>("Entity:UpdateCondition", Room.UpdateEntityCondition); Networker.hubConnection.On <Entity>("Entity:ToggleVisibility", Room.UpdateEntityVisibility); Networker.hubConnection.On <string, int>("Entity:UpdateFoV", Room.UpdateEntityFoV); } if (newConnection && Networker.IsConnected) { string uid = await JSRuntime.InvokeAsync <string>("GetPlayerUID"); Tabletop.UID = uid; if (String.IsNullOrEmpty(uid)) { Redirect(); } else { await Networker.hubConnection.SendAsync("Player:Resync", RoomCode, uid); } } await Networker.hubConnection.SendAsync("Player:GetStatus"); await Networker.hubConnection.SendAsync("Player:SyncTabletopInfo"); }