Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServerlessHub OnConnected Issue - Resolved #1926

Open
moehoward003 opened this issue Apr 6, 2024 · 1 comment
Open

ServerlessHub OnConnected Issue - Resolved #1926

moehoward003 opened this issue Apr 6, 2024 · 1 comment

Comments

@moehoward003
Copy link

moehoward003 commented Apr 6, 2024

@vicancy seems you may have closed this issue: #1122 in error.

No where in the thread did it note to name the function of the method needs to be, "OnConnected" AND to use parameter constructor for "SignalRTrigger()" AND if you are running locally, you should try using Azure SignalR Emulator , as in the following that works:

    [FunctionName("AnyNameYouWantHereIsFine")]
    public async Task OnConnected([SignalRTrigger()] InvocationContext invocationContext, ILogger logger)
    {
        logger.LogInformation($"{invocationContext.ConnectionId} connected");
        await Task.CompletedTask;
    }

If you were not able to repro, you should have posted your working code and not any differences for those that posted comments of their non-working code.

I was having this issue for a long time as others, and the above worked for me.

Please update the original noted issue to either note this thread or the details provided above. Thanks

Complete class that worked for me (I also used Azure SignalR Emulator):

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace TestServerlessHub
{
    public class MyServerlessHub : ServerlessHub
    {

        [FunctionName("negotiate")]
        public static SignalRConnectionInfo GetSignalRInfo(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            [SignalRConnectionInfo(HubName = "MyServerlessHub")] SignalRConnectionInfo connectionInfo)
        {
            return connectionInfo;
        }

        [FunctionName("AnyNameYouWantHereIsFine")]
        public async Task OnConnected([SignalRTrigger()] InvocationContext invocationContext, ILogger logger)
        {
            logger.LogInformation($"{invocationContext.ConnectionId} connected");
            await Task.CompletedTask;
        }

        [FunctionName("AnyNameYouWantHereIsFine2")]
        public async Task OnDisconnected([SignalRTrigger()] InvocationContext invocationContext, ILogger logger)
        {
            logger.LogInformation($"{invocationContext.ConnectionId} connected");
            await Task.CompletedTask;
        }
    }
}
@Y-Sindo
Copy link
Member

Y-Sindo commented Apr 13, 2024

No where in the thread did it note to name the function of the method needs to be, "OnConnected" AND to use parameter constructor for "SignalRTrigger()" AND if you are running locally, you should try using Azure SignalR Emulator

The doc here shows that the method name restriction and the parameterless ctor is required.

The doc here shows the usage of emulator. We will consider making it more clear for users.

If you were not able to repro, you should have posted your working code

You can find a complete class sample here : https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-concept-serverless-development-config?tabs=in-process#class-based-model

Also, doc here shows working samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants