[您好,我正在尝试使用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库发送相同的消息?
尝试使用Azure Signal R Serverless将消息发送到组
您可以参考this github repo,该示例代码显示了如何使用Azure SignalR Service在Azure功能中实现组广播功能。
使用SignalRGroupAction
类将用户添加到组中
return signalRGroupActions.AddAsync(
new SignalRGroupAction
{
ConnectionId = decodedfConnectionId,
UserId = message.Recipient,
GroupName = message.Groupname,
Action = GroupAction.Add
});
在客户端,向端点发出将用户添加到组的请求
function addGroup(sender, recipient, connectionId, groupName) {
return axios.post(`${apiBaseUrl}/api/addToGroup`, {
connectionId: connectionId,
recipient: recipient,
groupname: groupName
}, getAxiosConfig()).then(resp => {
if (resp.status == 200) {
confirm("Add Successfully")
}
});
}
测试结果]