0

I am trying to use signalR in an existing MVC application. I am loading the scripts in order. I can see the jQuery and hubs scripts in the browser network console. But, I am getting an error saying chatHub is undefined. Surprisingly, when I try to debug the code and put a break point on

proxies.chatHub = this.createHubProxy('chatHub');

and after that when I go to console and type $.connectrion.chatHub I can see all the properties of the object. But, when I end the debugging, the $.connection gets undefined and then nothing works. Please help me with a solution. I have tried every link available for signalR and tried every possibility, but my problem seems to be different. I am using signalR-1.0.1.

Nithin
  • 1,376
  • 12
  • 29

1 Answers1

0

If you made your signalr host different than your project than it cannot find this properly

<script src="~/signalr/hubs"></script> 

So you need to specify like

<script src="http://localhost:{Your SignalR Host Port}/signalr/hubs"></script>

Also if you want to compare there is a fully working example in here. https://github.com/DenizGokce/SignalR

EDIT:

This is how signalr framework works you need to define a structure like OnlineClient in the hub and you need to bind those different connectionIds in the server side

public class OnlineClient{
      public Int SomeClientId; /*You Defined*/
      public List<String> ConnectionIds {get;set;}
}

public List<OnlineClient> _onlineClients = new List<OnlineClient>();

like this you need to manage your clients in the server side

Deniz Gokce
  • 71
  • 1
  • 6
  • Did you check the project you might find something helpful – Deniz Gokce Jul 12 '17 at 14:18
  • The problem is that I have two layouts on which I am using the signalR chatbox. One of them is a third party reporting app and on that it is causing the undefined error. The logic for chatapp is a shared resource and it works on one layout and doesn't work on the other. – Amit Mishra Jul 13 '17 at 05:31
  • each layout must connect individually if you consider each layout as webclient for signalr server than these layouts must have different clientId or connectionId could that be the problem? i dont know if you are trying to connect them from same clientId. – Deniz Gokce Jul 13 '17 at 10:14
  • how do I achieve this? – Amit Mishra Jul 13 '17 at 11:29
  • I debugged and found out that the client id and tokens being generated are different on these layouts. I don't know why as soon as I end the debugging the $.connection becomes undefined. – Amit Mishra Jul 13 '17 at 12:36
  • This is how signalr framework works you need to define a structure like OnlineClient in the hub and you need to bind those different connectionIds in the server side public class OnlineClient{ public Int SomeClientId; /*You Defined*/ public List ConnectiionIds {get;set;} } public List _onlineClients = new List(); like this you need to manage your clients in the server side – Deniz Gokce Jul 14 '17 at 07:42
  • I debugged the whole code and found that $.connection.chatHub works fine until the jquery.js loading at the end of it. – Amit Mishra Jul 14 '17 at 08:15