如何将消息从js库发送到Azure SignalR Serverless中的组

您好,我正在尝试使用Azure Signal R无服务器JS客户端Js Library向组发送消息。

我可以从Azure无服务器功能中简单地做到这一点:

await signalRMessages.AddAsync(
                new SignalRMessage
                {
                    GroupName = m.GroupName,Target = m.Target,Arguments = new[] { m.Message }
                });

*其中signalRMessages = IAsyncCollector signalRMessages

如何从js库发送相同的消息?

bbsoft123 回答:如何将消息从js库发送到Azure SignalR Serverless中的组

  

尝试使用Azure Signal R Serverless将消息发送到组

您可以参考this github repo,该示例代码显示了如何使用Azure SignalR Service在Azure功能中实现组广播功能。

使用private executeReq(method: string,url: string,req: any) { return this.http[method](url,req); } 类将用户添加到组

SignalRGroupAction

在客户端,向端点发出将用户添加到组的请求

return signalRGroupActions.AddAsync(
    new SignalRGroupAction
    {
        ConnectionId = decodedfConnectionId,UserId = message.Recipient,GroupName = message.Groupname,Action = GroupAction.Add
    });

测试结果

enter image description here

已更新:

Q:“直接从套接字发送来自JS客户端的消息。”

A:从here,我们可以找到:

  

尽管SignalR SDK允许客户端应用程序在SignalR集线器中调用后端逻辑,但是当您将SignalR Service与Azure Functions一起使用时,尚不支持此功能。使用HTTP请求来调用Azure功能。

,

现在看来这是可能的...

https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-concept-serverless-development-config#sending-messages-from-a-client-to-the-service

从客户端向服务发送消息(如果上游) 为您的SignalR资源配置,您可以从 使用任何SignalR客户端将客户端连接到Azure函数。这是一个 JavaScript中的示例:

JavaScript

connection.send('method1','arg1','arg2');

本文链接:https://www.f2er.com/3135347.html

大家都在问