internal async Task ConnectToSignalRHub(GameService service, PvPDiceGameLogic pvPDiceGameLogic, JoinRequest joinRequest) { var neotigation = await _urlHelper.GetSignalRNeogation(_baseUrl, _client); await ConnectToSignalRHubImpl(service, neotigation, pvPDiceGameLogic); _urlHelper.SetGub(_hubConnection); joinRequest.TechnicalClientId = neotigation.accessToken; }
private async Task ConnectToSignalRHubImpl(GameService service, SignalRNeogation info, PvPDiceGameLogic logic) { try { if (info.accessToken == null) { _hubConnection = new HubConnectionBuilder() .WithUrl(info.url) .Build(); } else { _hubConnection = new HubConnectionBuilder() .WithUrl(info.url, option => GetSignalROptions(info, option)) .Build(); } _hubConnection.On("join", (Action <JoinRequest>)((join) => { logic.JoinCallback(service, join); })); _hubConnection.On("StartGame", (Action <string>)((gameid) => logic.StartgameCallback(service, gameid))); _hubConnection.On("move", (Action <MoveInfo>)((move) => { logic.MoveCallback(move); })); _hubConnection.Closed += _hubConnection_Closed; await _hubConnection.StartAsync(); } catch (Exception ex) { if (info.accessToken == null) { throw new Exception("Failed to init SignalR Hub on '" + info.url + "': " + ex.Message, ex); } throw new Exception("Failed to init SignalR Hub (without token) on '" + info.url + "': " + ex.Message, ex); } }