3

I want to close the circuit from the server-side when a user is inactive for a long time. The connection must be terminated to save Azure SignalR resources.

I have created a js-script, simple timer that tracked onmousemove and onkeypress events and calls C# method when time has expired.

function CloseCircuit()
{
    dotNetHelper.invokeMethodAsync('CloseCircuit');
}

I've read about the CircuitHandler implementation, but I don't need to handle the event of closing or opening a connection. I have to somehow initiate the closing of this connection from my BlazorServer app. I'd appreciate any advice

mvidas
  • 31
  • 3

1 Answers1

0

If you are using SignalR Core, you can use the Context.Abort() available via the Hub class. E.G:

   public class MyHub : Hub
    {
        public void CloseCircuit()
        {
            // This will close the connection of the caller
            Context.Abort();
        }
    }

If you are not using SignalR core, I believe there is no way to do this yet. In that case, why not just stop the connection from the client side, because you are already doing the timer there?

Hedgybeats
  • 297
  • 1
  • 4
  • 16
  • 1
    Thanks for the advice. I thought about breaking the connection on the client side, but it is created in "blazor.server.js". So I don't know how to get the circuit created by Blazor from my own script. – mvidas Feb 23 '22 at 14:48