mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-23 06:35:13 +01:00
fixes for hub
This commit is contained in:
parent
c7e2f979dd
commit
ef9a633aa4
4 changed files with 33 additions and 24 deletions
|
@ -38,6 +38,7 @@ using BTCPayServer.Logging;
|
|||
using BTCPayServer.HostedServices;
|
||||
using Meziantou.AspNetCore.BundleTagHelpers;
|
||||
using System.Security.Claims;
|
||||
using BTCPayServer.Hubs;
|
||||
using BTCPayServer.Payments.Changelly;
|
||||
using BTCPayServer.Security;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
@ -73,6 +74,7 @@ namespace BTCPayServer.Hosting
|
|||
services.TryAddSingleton<TokenRepository>();
|
||||
services.TryAddSingleton<EventAggregator>();
|
||||
services.TryAddSingleton<CoinAverageSettings>();
|
||||
services.TryAddSingleton<CrowdfundHubStreamer>();
|
||||
services.TryAddSingleton<ApplicationDbContextFactory>(o =>
|
||||
{
|
||||
var opts = o.GetRequiredService<BTCPayServerOptions>();
|
||||
|
|
|
@ -14,17 +14,18 @@ using BTCPayServer.Services.Rates;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
namespace BTCPayServer.Hubs
|
||||
{
|
||||
public class CrowdfundHub: Hub
|
||||
{
|
||||
private readonly AppsPublicController _AppsPublicController;
|
||||
private readonly IServiceProvider _ServiceProvider;
|
||||
|
||||
public CrowdfundHub(AppsPublicController appsPublicController)
|
||||
public CrowdfundHub(IServiceProvider serviceProvider)
|
||||
{
|
||||
_AppsPublicController = appsPublicController;
|
||||
_ServiceProvider = serviceProvider;
|
||||
}
|
||||
public async Task ListenToCrowdfundApp(string appId)
|
||||
{
|
||||
|
@ -42,11 +43,16 @@ namespace BTCPayServer.Hubs
|
|||
|
||||
}
|
||||
|
||||
public async Task<string> CreateInvoice(ContributeToCrowdfund model)
|
||||
public async Task CreateInvoice(ContributeToCrowdfund model)
|
||||
{
|
||||
model.RedirectToCheckout = false;
|
||||
var result = await _AppsPublicController.ContributeToCrowdfund(Context.Items["app"].ToString(), model);
|
||||
return (result as OkObjectResult)?.Value.ToString();
|
||||
using (var scope = _ServiceProvider.CreateScope())
|
||||
{
|
||||
var controller = scope.ServiceProvider.GetService<AppsPublicController>();
|
||||
model.RedirectToCheckout = false;
|
||||
var result = await controller.ContributeToCrowdfund(Context.Items["app"].ToString(), model);
|
||||
await Clients.Caller.SendCoreAsync("InvoiceCreated", new[] {(result as OkObjectResult)?.Value.ToString()});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task PaymentReceived()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
var app = null;
|
||||
var eventAggregator = new Vue();
|
||||
window.onload = function (ev) {
|
||||
|
||||
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
|
||||
var hubListener = function(){
|
||||
|
||||
var statuses = {
|
||||
DISCONNECTED: "disconnected",
|
||||
CONNECTED: "connected",
|
||||
CONNECTING: "connecting"
|
||||
};
|
||||
var status = "disconnected";
|
||||
|
||||
|
||||
var connection = new signalR.HubConnectionBuilder().withUrl("/crowdfundHub").build();
|
||||
var connection = new signalR.HubConnectionBuilder().withUrl("/apps/crowdfund/hub").build();
|
||||
|
||||
connection.onclose(function(){
|
||||
this.status = statuses.DISCONNECTED;
|
||||
eventAggregator.$emit("connection-lost");
|
||||
console.error("Connection was closed. Attempting reconnect in 2s");
|
||||
setTimeout(connect, 2000);
|
||||
});
|
||||
|
||||
|
||||
connection.on("InvoiceCreated", function(invoiceId){
|
||||
eventAggregator.$emit("invoice-created", invoiceId);
|
||||
});
|
||||
|
||||
function connect(){
|
||||
status = statuses.CONNECTING;
|
||||
|
||||
eventAggregator.$emit("connection-pending");
|
||||
connection
|
||||
.start()
|
||||
.then(function(){
|
||||
this.status = statuses.CONNECTED;
|
||||
connection.invoke("ListenToCrowdfundApp", srvModel.appId);
|
||||
|
||||
})
|
||||
.catch(function (err) {
|
||||
this.status = statuses.DISCONNECTED;
|
||||
eventAggregator.$emit("connection-failed");
|
||||
console.error("Could not connect to backend. Retrying in 2s", err );
|
||||
setTimeout(connect, 2000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
eventAggregator.$on("contribute", function(model){
|
||||
connection.invoke("CreateInvoice", model);
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
statuses: statuses,
|
||||
status: status,
|
||||
connect: connect
|
||||
};
|
||||
}();
|
||||
|
|
Loading…
Add table
Reference in a new issue