简体   繁体   English

与signalR成角度:到同一路由的多个集线器连接

[英]Angular with signalR: Multiple hubconnections to the same route

I have my client code as below. 我的客户代码如下。 I have a signalr route and hub connection name. 我有一个信号器路由和集线器连接名称。 I am able to connect to the hub and get events. 我能够连接到集线器并获取事件。 Now I need to connect to one more hub for the same route to get more events. 现在,我需要连接到同一路线的另一个集线器以获得更多事件。

  this.hubConnection = this.window.$.hubConnection();
    this.hubConnection.url = this.apiUrl  + "api/signalr";
    this.hubProxy = this.hubConnection.createHubProxy("Event1Hub");
    this.hubProxy = this.hubConnection.createHubProxy("Event2Hub"); // When I add this line it is overriding first hub and only connecting to Event2Hub.

I am using "signalr": "2.3.0", 我正在使用“ signalr”:“ 2.3.0”,

You are creating a proxy for Event1Hub and then reassining that object instance with proxy for Event2Hub . 您正在创建一个代理Event1Hub然后reassining该对象实例与代理的Event2Hub If you want to communicate with both hubs you'll have to initialize separate proxy objects in order for this to work. 如果要与两个集线器进行通信,则必须初始化单独的代理对象才能使其正常工作。

this.hubConnection = this.window.$.hubConnection();
this.hubConnection.url = this.apiUrl  + "api/signalr";
this.hubEvent1Proxy = this.hubConnection.createHubProxy("Event1Hub");
this.hubEvent2Proxy = this.hubConnection.createHubProxy("Event2Hub");

This way hubEvent1Proxy will provide Event1Hub communication while hubEvent2Proxy will provide Event2Hub communication. 这样, hubEvent1Proxy将提供Event1Hub通信,而hubEvent2Proxy将提供Event2Hub通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM