我有以下集线器类:
public class Dashboard : Hub, IDisconnect, IConnected
{
//Initialize Repoisotries
private IProfileRepository profileRepository;
private ISiteDataRepository siteDataRepository;
private readonly IHubContext matchContext = GlobalHost.ConnectionManager.GetHubContext<MatchMaker>();
//Constructor Injection for profile repository and site data repository
public Dashboard(IProfileRepository repo, ISiteDataRepository siteRepo)
{
profileRepository = repo;
siteDataRepository = siteRepo;
}
public Task Disconnect()
{
return null;
}
public Task Reconnect(IEnumerable<string> connections)
{
return null;
}
public Task Connect()
{
Debug.WriteLine(MatchMaker.onlineUsers.Count);
return null;
}
public void GetUserInfo()
{
Debug.WriteLine(MatchMaker.onlineUsers.Count);
}
}
}
我的信号器包括:
<script src="@Url.Content("~/signalr/hubs")" type="text/javascript"></script>
我像这样访问它:
$(function () {
//Create the proxy
var Dashboard = $.connection.dashboard;
$.connection.hub.start(function () {
Dashboard.getUserInfo();
});
});
当我调用Dashboard.getUserInfo()
该方法时,该方法被称为 find,但该Connect()
方法一开始就不会触发。