Azure SignalR serverless with Azure Functions OnDisconnected not working

Daniel Bordeleau 5 Reputation points
2023-02-21T23:20:15.81+00:00

I'm using Azure Funtions with Azure SignalR serverless with and my client is Typescript.

Everything is working fine but I'd like to know when a user is disconnected.

But my OnDisconnected never gets triggered.

I have setup my Upstream : https://myfuntionsite.azurewebsites.net/runtime/webhooks/signalr?code=[signalr_extension key found in AzureFunction app keys]

Here is my code :

 signalRHub = new HubConnectionBuilder()
        .withUrl(baseAzureFunctionsUrl, {
            withCredentials: false
        })
        .configureLogging(LogLevel.Debug)
            .withAutomaticReconnect()
            .build();

My Azure Functions :

    public class SolohubSignalRHub : ServerlessHub
    {

        [FunctionName("negotiate")]
        public Task<SignalRConnectionInfo> NegotiateAsync([HttpTrigger(AuthorizationLevel.Anonymous)] HttpRequest req)
        {
            return NegotiateAsync(new NegotiationOptions() { EnableDetailedErrors = true, IsDiagnosticClient = true });
        }

        [FunctionName(nameof(OnDisconnected))]
        public async Task OnDisconnected([SignalRTrigger] InvocationContext invocationContext, ILogger logger)
        {
            Console.WriteLine($"########### {invocationContext.ConnectionId} DISCONNECTED.");
        }
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,120 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
120 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Ryan Hill 25,216 Reputation points Microsoft Employee
    2023-02-23T05:44:55.2866667+00:00

    Hi @Daniel Bordeleau have you added server-side logging to your Function app? If you haven't, I suggest starting there. According to the SignalR Hubs API Guides there are certain conditions where OnDisconnected isn't fired but I'm assuming you're not running into that scenario. So, the idea is to see if we see any of possible sequences listed in the doc. Another thing to do is enable Live Tracing.

    Let me know if the troubleshooting and live tracing doesn't yield any results.

    0 comments No comments