[英]Check in Azure Functions if client is still connected to SignalR Service
我在 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 指導是什么?
看看這個功能: Azure SignalR 服務引入了事件網格集成功能,其中SignalR 服務發出以下兩種事件類型:
Microsoft.SignalRService.ClientConnectionConnected
Microsoft.SignalRService.ClientConnectionDisconnected
更多細節在這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.