繁体   English   中英

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

[英]Check in Azure Functions if client is still connected to SignalR Service

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

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 指导是什么?

看看这个功能: Azure SignalR 服务引入了事件网格集成功能,其中SignalR 服务发出以下两种事件类型:

Microsoft.SignalRService.ClientConnectionConnected

Microsoft.SignalRService.ClientConnectionDisconnected

更多细节在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM