【发布时间】:2019-02-11 07:27:44
【问题描述】:
我正在将 SignalR 添加到我的应用中。我可以从服务器向客户端发送消息,但不能从客户端调用集线器方法。这是我的集线器界面:
public interface IGeneralHub
{
Task BroadcastMessage(HubMessage msg); //string type, string payload);
Task JoinHub(List<int> ids);
}
和中心客户端:
public class AuctionHub : Hub<IGeneralHub>
{
public void Broadcast(HubMessage msg)
{
Clients.All.BroadcastMessage(msg);
}
public void JoinHub(List<int> ids)
{
foreach (var id in ids.Distinct())
Groups.AddToGroupAsync(Context.ConnectionId, id.ToString());
}
}
和客户端:
this.hubConnections = new signalR.HubConnectionBuilder()
.withUrl(`${environment.hubHost}/document/`)
.build();
this.hubConnections.start()
.then(() => console.log('Connection started'))
.catch(err => console.log('Error while starting connection: ' + err));
this.hubConnections.invoke('joinGroup', JSON.parse(localStorage.getItem('ws-document')));
我收到消息,但从未调用过joinGroup。我做错了什么?
【问题讨论】:
标签: c# asp.net-core signalr.client asp.net-core-signalr