如果客户端仍连接到SignalR Service,请检查Azure Functions

问题描述 投票:1回答:1

我已经在Azure Functions中创建了协商和发送消息功能(类似于以下示例),以整合SignalR服务。我正在使用自定义身份验证机制在UserId上设置SignalRMessage

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service?tabs=csharp

[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
    [HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req, 
    [SignalRConnectionInfo
        (HubName = "chat", UserId = "{headers.x-ms-client-principal-id}")]
        SignalRConnectionInfo connectionInfo)
{
    // connectionInfo contains an access key token with a name identifier claim set to the authenticated user
    return connectionInfo;
}

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            // the message will only be sent to this user ID
            UserId = "userId1",
            Target = "newMessage",
            Arguments = new [] { message }
        });
}

如果客户端不再连接,我想发送推送通知,而不是向IAsyncCollector添加新对象。我还正确设置了AppCenter推送框架,但我遇到了一个问题。是否有简单的方法来找出哪个UserId仍连接到集线器?这样,我可以决定发送推送。 Microsoft在此问题上的建议指南是什么?

c# push-notification signalr azure-functions visual-studio-app-center
1个回答
0
投票

查看此功能:Azure SignalR Service introduces Event Grid integration feature,其中SignalR服务发出以下两种事件类型:

Microsoft.SignalRService.ClientConnectionConnected

Microsoft.SignalRService.ClientConnectionDisconnected

更多详细信息here

© www.soinside.com 2019 - 2024. All rights reserved.