2021年4月27日星期二

Sendmessage is not sending to a declared group in SignalRMessage.GroupName

I'm not receiving any group messages when message is being sent to group in signalrhub. stack: JS Client using axios library azure functions signalr service

based on this article and project: https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-azure-functions-csharp

added this function to try and join a group and call sendmessage to send to azure function:

      joinGroup(data.username, 'melmack');          function joinGroup(userId, group) {            return axios.post(`${apiBaseUrl}/api/${group}/add/${userId}`, {})                .then(resp => { if (resp.status == 200) { confirm("Added Successfully.") } });        }        function sendMessage(sender, messageText) {        return axios.post(`${apiBaseUrl}/api/melmack/send`, {          sender: sender,          text: messageText        }).then(resp => resp.data);      }

group function is defined here:

       [FunctionName("SendMessage")]      public static Task SendMessage(      [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "{group}/send")] object message,      string group,      [SignalR(HubName = "chat")] IAsyncCollector<SignalRMessage> signalRMessages)      {          return signalRMessages.AddAsync(              new SignalRMessage              {                  GroupName = group,                  Target = "newMessage",                  Arguments = new[] { message }              });      }        [FunctionName("joinGroup")]      public static Task JoinGroup(      [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "{group}/add/{userId}")] HttpRequest req,      string group,      string userId,      [SignalR(HubName = "chat")] IAsyncCollector<SignalRGroupAction> signalRGroupActions)      {          return signalRGroupActions.AddAsync(              new SignalRGroupAction              {                   UserId = userId,                  GroupName = group,                  Action = GroupAction.Add              });      }  

Everything seems to be working fine until I try and evoke "SendMessage" with the GroupName set to the value. I comment out the GroupName property in the SignalRMessage object and it works fine and loads to all my clients.

Would like some troubleshooting help or a link to a more straightforward article defining how to use azure functions, SignalR Service and clients. My eventual goal is to implement a xamarin forms client library for my app. I've scoured the web for bits and pieces of how signalr service works over azure functions and it's been difficult.

https://stackoverflow.com/questions/67294072/sendmessage-is-not-sending-to-a-declared-group-in-signalrmessage-groupname April 28, 2021 at 01:07PM

没有评论:

发表评论