我已更新我的服务器解决方案以使用MVC 5和最新版本的signalr,并且有两个主要问题:
OnConnected
函数,但未调用它。这是客户端代码
define(['jquery', 'toastr', 'Q'], function($, toastr, Q) {
var incidentHubProxy;
var deferred = Q.defer();
var connect = function() {
var connection = $.hubConnection(localStorage.url);
$.connection.hub.logging = true;
incidentHubProxy = connection.createHubProxy('notification');
connection.start()
.done(function () {
toastr.success('Now connected, connection ID=' + connection.id);
setInterval(function () {
incidentHubProxy.invoke('ping');
}, 3000);
deferred.resolve();
})
.fail(function () { toastr.error('Could not connect'); });
incidentHubProxy.on('notify', function (data) {
toastr.info(data.topic);
toastr.info(data.data);
});
incidentHubProxy.on('pong', function (data) {
toastr.info('got pong');
});
return deferred.promise;
};
var joinGroup = function (groupName) {
incidentHubProxy.invoke('joinGroup', groupName);
};
return {
connect: connect,
joinGroup: joinGroup
};
});
我已将代码更新为仍然无法正常工作
define(['jquery','toastr','Q'],函数($,toastr,Q){
var incidentHubProxy;
var deferred = Q.defer();
var connect = function() {
var connection = $.hubConnection(localStorage.url);
$.connection.hub.logging = true;
incidentHubProxy = connection.createHubProxy('notification');
incidentHubProxy.notify = function(data) {
toastr.info(data.topic);
toastr.info(data.data);
};
incidentHubProxy.pong = function(data) {
toastr.info('got pong');
};
connection.start()
.done(function () {
toastr.success('Now connected, connection ID=' + connection.id);
setInterval(function () {
incidentHubProxy.invoke('ping');
}, 3000);
deferred.resolve();
})
.fail(function () { toastr.error('Could not connect'); });
return deferred.promise;
};
var joinGroup = function (groupName) {
incidentHubProxy.invoke('joinGroup', groupName);
};
return {
connect: connect,
joinGroup: joinGroup
};
});