I have problem with calling function on signalr hub disconnect.
here are my js references
<script src="~/js/jquery.min.js"></script>
<script src="~/SignalR/dist/browser/signalr.min.js"></script>
script inside cshtml file
var connection = new signalR.HubConnectionBuilder()
.withUrl("/chatt", {
accessTokenFactory: () => "testing"
})
.build();
connection.start().then(function () {
connection.invoke('GetConnectionId')
.then(function (connectionId) {
//alert(connectionId);
//removeConnectionID(connectionId);
})
}).catch(err => console.error(err));
$.connection.hub.disconnected(function () {
removeConnectionID();
})
async function removeConnectionID() {
await $.get("/Chat/Test") ;
}
on $.connection.hub.disconnected i get
Uncaught TypeError: Cannot read property 'hub' of undefined.
When i start typing $.connection. i dont see hub property at all.
here is my configure services
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<mojDbContext>(options=> options.UseSqlServer(Configuration.GetConnectionString("IB150198T")));
services.AddControllersWithViews();
services.AddMvc();
services.AddDistributedMemoryCache();
services.AddSession();
services.AddSignalR();
// services.AddSingleton<IUserIdProvider, UserProvider>();
}
I saw somewhere that I should have reference to js file that is named something like "/SignalR/Hubs" but cant find it in client side library for signalR
any help is appreciated!!!
question from:
https://stackoverflow.com/questions/65891862/uncaught-typeerror-cannot-read-property-hub-of-undefined 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…