private static void OnUserSignOut(object sender, API.AuthenticationInfo e) { connectionTimer.Stop(); hubConnection.Stop(); }
private static void InitConnection(API.AuthenticationInfo e) { // var handler = new Handler(Looper.MainLooper); hubConnection = new HubConnection(Resources.APIBaseAddress, true); if (hubConnection.Headers.ContainsKey("Authorization")) { hubConnection.Headers["Authorization"] = $"Bearer {e.AccessToken}"; } else { hubConnection.Headers.Add("Authorization", $"Bearer {e.AccessToken}"); } coreHub = hubConnection.CreateHubProxy("CoreHub"); coreHub.On("OnReservationPaid", (long id) => { handler.Post(() => OnReservationPaid?.Invoke(null, id)); }); coreHub.On("OnReservationRefunded", (long id) => { handler.Post(() => OnReservationRefunded?.Invoke(null, id)); }); coreHub.On("OnReservationPaymentFailed", (long id) => { handler.Post(() => OnPaymentFailed?.Invoke(null, id)); }); #if DEBUG coreHub.On("OnTest", (int count) => { LogHelpers.Write(nameof(RealtimeNotifications), $"Receive test notification: {count}"); }); #endif hubConnection.Error += (err) => { }; hubConnection.StateChanged += (t) => { if (!connectionTimer.Enabled) { connectionTimer.Start(); } if (t.NewState == ConnectionState.Connected) { LogHelpers.Write(nameof(RealtimeNotifications), "Connected to hub successfully!"); } }; // isRegistered = true; hubConnection.Start().ContinueWith(t => { if (t.IsFaulted) { LogHelpers.Write(nameof(RealtimeNotifications), t.Exception.GetBaseException().ToString()); } else { LogHelpers.Write(nameof(RealtimeNotifications), "Connection was successful"); } }); }
private static void OnUserLogin(object sender, API.AuthenticationInfo e) { InitConnection(e); }