【发布时间】:2020-01-31 17:49:14
【问题描述】:
我在 Azure Functions 中创建了协商和发送消息函数(类似于下面的示例)以合并 SignalR 服务。我正在使用自定义身份验证机制在SignalRMessage 上设置UserId。
[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