I have single R version 2.2.1. I implement custom Id Provider
public class ChatUserIdProvider : IUserIdProvider
{
public string GetUserId(IRequest request)
{
if (request.User.Identity.IsAuthenticated)
{
Guid.Parse(request.User.Identity.GetUserId().ToString());
var userId = request.User.Identity.GetUserId().ToString();
return userId.ToString();
}
return "Un Known";
}
}
I made a simple chat app and every think OK, but when I try to send a message to multi users the client event not firing here is hub function
public void SendToMany(string msg, List<string> userIds)
{
try
{
//db things here
Clients.Users(userIds).sendMessage(msg);
}
catch (Exception ex)
{
Logs.Log(ex);
}
}
Startup
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new ChatUserIdProvider ());
app.MapSignalR();
Js
$(function () {
var chat = $.connection.chatHub;
chat.client.sendMessage= function (msg) {
$('.msgs').append('<div>'+ group.Name + '</div>');
$('#' + group.Id).click();
}
$.connection.hub.start();
})
function BrodCast() {
try {
var chatids = new Array();
$('.ckusergr').each(function () {
if ($(this).is(':checked')) {
chatids.push($(this).attr('iid'));
}
})
chat.server.sendToMany($('.txtmsg').val(), chatids);
} catch (e) {
console.log(e)
}
}
the problem with this line
public void SendToMany(string msg, List<string> userIds)
{
try
{
//db things here
Clients.Users(userIds).sendMessage(msg); // Her is the Problem
}
catch (Exception ex)
{
Logs.Log(ex);
}
}
if I change to become like this every thing work great.
public void SendToMany(string msg, List<string> userIds)
{
try
{
//db things here
foreach (string item in userIds)
{
Clients.User(item).sendMessage(msg);
}
}
catch (Exception ex)
{
Logs.Log(ex);
}
}