Signalr 2.0.0的行为与以前的版本不同

时间:2013-11-04 07:55:51

标签: asp.net-web-api signalr

我已更新我的服务器解决方案以使用MVC 5和最新版本的signalr,并且有两个主要问题:

  1. 我已覆盖OnConnected函数,但未调用它。
  2. 未接收到客户端的消息,正在接收来自客户端的呼叫
  3. 这是客户端代码

    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
    };
    

    });

0 个答案:

没有答案