[英]Check in Azure Functions if client is still connected to SignalR Service
I've created negotiate and send message functions in Azure Functions (similar to the samples below) to incorporate the SignalR Service.我在 Azure Functions 中创建了协商和发送消息函数(类似于下面的示例)以合并 SignalR 服务。 I'm setting
UserId
on the SignalRMessage
by using a custom authentication mechanism.我正在使用自定义身份验证机制在
SignalRMessage
上设置UserId
。
https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-signalr-service?tabs=csharp 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 }
});
}
I'd like to send a push notification if the client is no longer connected instead of adding a new object to the IAsyncCollector
.如果客户端不再连接而不是向
IAsyncCollector
添加新对象,我想发送推送通知。 I've also set up AppCenter
push framework properly, but I'm facing an issue.我还正确设置了
AppCenter
推送框架,但我遇到了一个问题。 Is there an easy way to find out which UserId
is still connected to the hub?有没有一种简单的方法可以找出哪个
UserId
仍然连接到集线器? This way, I could decide to send a push.这样,我可以决定发送推送。 What is the recommended Microsoft guidance on this issue?
关于此问题的建议 Microsoft 指导是什么?
Have a look at this feature: Azure SignalR Service introduces Event Grid integration feature , where the SignalR Service emits two following event types:看看这个功能: Azure SignalR 服务引入了事件网格集成功能,其中SignalR 服务发出以下两种事件类型:
Microsoft.SignalRService.ClientConnectionConnected
Microsoft.SignalRService.ClientConnectionDisconnected
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.