0

I'm trying to figure out how to send a message to one client that is connected in multiple tabs using SignalR. The problem is when I send the message to the specific client, it only gets to the first tab instead of the current tab of the clients browser.

Here is some of my code:

ChatHub class:

public void SendToSpecific(string name, string message, string to, string chatlog, string chatlogTo, string mType)
    {
        Clients.Caller.broadcastMessage(name, message, chatlogTo, mType);
        Clients.Client(dic[to]).broadcastMessage(name, message, chatlog, mType);
    }

Jquery:

chat = $.connection.chatHub;

Startup.cs:

using Owin;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(testFoundation.Startup))]
namespace testFoundation
{
 public class Startup
 {
     public void Configuration(IAppBuilder app)
     {
        // Any connection or hub wire up and configuration should go here
        app.MapSignalR();
     }
 }
}

The question is, how can I send the message to the client browser active tab, if he's connected in multiple tabs?

Thanks.

1 Answers1

2

Clients.Client will send to one connection, each tab has its own connection. If you want to send to a specific User use

Clients.User

Sending to active tabs seem strange? If he switch tab the others wont be up to date?

Anders
  • 17,306
  • 10
  • 76
  • 144
  • That works perfect @Anders, thanks. Here is the new code in the chat hub: Clients.User(name).broadcastMessage(name, message, chatlogTo, mType); Clients.User(to).broadcastMessage(name, message, chatlog, mType); – Andres Roger Jan 29 '15 at 16:57