当用户连接到集线器类时,不会触发public Task Connect()

时间:2012-08-09 21:00:17

标签: c# javascript jquery asp.net signalr

我有以下集线器类:

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()方法从不会首先触发。

1 个答案:

答案 0 :(得分:1)

我发现了什么问题......一旦我添加了这样的方法:

$(function () {
//Create the proxy
var Dashboard = $.connection.dashboard;

Dashboard.someMethod = function(message){
}

$.connection.hub.start(function () {
    Dashboard.getUserInfo();

});
});

我的Connect()功能开始触发,不知道你需要一个客户端功能来激活连接。