我已经在Azure Functions中创建了协商和发送消息功能(类似于以下示例),以整合SignalR服务。我正在使用自定义身份验证机制在UserId
上设置SignalRMessage
。
[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 Service introduces Event Grid integration feature,其中SignalR服务发出以下两种事件类型:
Microsoft.SignalRService.ClientConnectionConnected
Microsoft.SignalRService.ClientConnectionDisconnected
更多详细信息here。