I'm confused about the closed event in SignalR
. Apparently, there was some debate about what to call it e.g. onClosed()
, closed()
, etc.
In my SignalR
listener on the client side, I'm trying to implement this event but I keep getting an error that says it's not a function. I tried onClosed()
and closed()
. Same error. How do I detect the closed event on the client side?
const signalRListener = () => {
connection.on('new_message', message => {
// Handle incoming message.
// This is working fine.
})
connection.closed(e => {
// Try to restart connection but I never get here to due error I'm receiving
})
}
What am I doing wrong?
Here's how I start my connection:
export const signalRStart = (token) => {
connection = new signalR.HubConnectionBuilder()
.withUrl("/chat?access_token=" + token)
.configureLogging(signalR.LogLevel.Information)
.build();
// Set connection time out
connection.serverTimeoutInMilliseconds = 30000;
// Start connection
connection.start();
// Invoke listener
signalRListener();
}