Open ravisankarchalamalasetty opened 3 years ago
Found some bugs in your codes, you're adding user to group with the user name and group name you typed in but sending message to group and user with a specific name SIL01D
if(data.username)
{
addUserToGroup(data.username);
}
...
function addUserToGroup(sender) {
return axios.post(`${apiBaseUrl}/api/addusertogroup`, {
UserName: sender
}).then(
resp => { resp.data;
console.log('response received from /api/addusertogroup POST call -->' + resp.data);
}
).catch((e)=> console.log(e));
}
You passed in data.username
for adding user to group but use a specific name for sending messages to group
const tempGroupName = "SIL01D";
...
function SendMessageToSpecificGroup(sender, messageText) {
return axios.post(`${apiBaseUrl}/api/sendmessagetospecificgroup`, {
sender: sender,
text: messageText,
groupName: tempGroupName,
}).then(
resp => { resp.data;
console.log('response received from /api/sendmessagetospecificgroup POST Call -->' + resp.data);
}
).catch((e)=> console.log(e));
}
So, first you need to change them to the same one. I suggest using tempGroupName
and tempUserId
to make it easier.
Then, a client connection's userId is defined in negotiation, that means you needs to specify userId in Negotiate
function like this. Or, when you try to send to user or add user to group, the userId can't match to your connection.
[FunctionName("negotiate")]
public SignalRConnectionInfo Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req,
ClaimsPrincipal claimsPrincipal,
[SignalRConnectionInfo(HubName = "maintenancehub", UserId = "SIL01D.Ravi")] SignalRConnectionInfo connectionInfo, ILogger log)
{
return connectionInfo;
}
Besides, you have a typo in SaaSApplication.html
. The estateSpecificMessages
should be groupSpecificMessages
let groupCounter = 0;
function GroupSpecificMessageTargetCaller(message) {
message.id = groupCounter++;
data.estateSpecificMessages.unshift(message);
}
After these fixes, I finished to add user to group and send messages to user
@zackliu
Replying long after you did but thanks for your help. I've been looking through docs for serverless signalR for a bit now and your post was the first time i've seen mention of setting the UserID
in the negotiation. ( I probably just missed it before) But thanks, this has really helped me out.
Azure SignalR service + Azure function based hubs
I am just wondering if sending message to specific group within connected clients is working at all for anyone? Broadcast is working well though! Likewise, sending message to a specific user within connected clients is also not working just like sending to a specific group of users. Not sure if I am missing something in this context. Any leads would be appreciated!
The target method i.e. 'GroupSpecificMessageTargetCaller' is never triggering in the client side javascript. On the contrary broadcast message to all connected clients is working well though. Target method 'BroadcastMessageTargetCaller' in the html client is getting triggered in broadcast case.
Client side code
Attaching complete source code for any further investigation. Thanks in advance!
AzureFunctonBasedSignalRService.zip
Server code-->
namespace MyFirstAzureFunction { public class MaintenanceHub : ServerlessHub {
}