Andres Roger
Andres Roger

Reputation: 23

Signalr send message to client in multiple tabs

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.

Upvotes: 1

Views: 1589

Answers (1)

Anders
Anders

Reputation: 17554

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?

Upvotes: 3

Related Questions