I simply try to invoke a message and i get an error:
Unhandled Rejection (Error): An unexpected error occurred invoking ‘SendMessageToGroup’ on the server.
back-end C#
public class ChatHub : Hub
{
public async Task SendAll(string message)
{
await Clients.All.SendAsync("ReceiveAllMessage", message);
}
public async Task JoinGroup(string group)
{
await Groups.AddToGroupAsync(Context.ConnectionId, group);
}
public async Task SendMessageToGroup(string group, string message)
{
string time = DateTime.Now.ToString();
await Clients.Groups(group).SendAsync("ReceiveMessage", message, time);
}
public override async Task OnConnectedAsync()
{
string userId = "user32";
await Clients.Caller.SendAsync("UserConnected", userId);
await base.OnConnectedAsync();
}
}
reactjs:
const send = async () => {
console.log("send to group")
await Newconnection.invoke("SendMessageToGroup", cookies.Default, text)
await Newconnection.invoke("SendAll","3r2r");
const data = {
"message" : text,
"accesToken" : cookies.Default,
"isHelper" : false
}
const res = await axios.post('https://localhost:44332/api/LiveChat/Message',data)
if(res.status === 200)
console.log("succesful send message")
}