2013-02-11 94 views
0

我/我最近升级/从signalR 0.5.3升级到1.0.x的RC2和我创造我的连接有问题。SignalR 0.5.3升级到1.0.x的问题

的问题是,我打的异常:

类型错误:RES是空

connection.appRelativeUrl = res.Url;

我的脚本来创建连接已被剥夺的权利恢复到默认的演示代码:

 var connection = $.connection('/signalr'); 

     connection.start(function() { 
      console.log("connection started!"); 
     }); 

不过我得到的错误。当我踏进jquery.signalr.js文件,我打了连接代码:

var url = connection.url + "/negotiate"; 
connection.log("Negotiating with '" + url + "'."); 
$.ajax({ 
     url: url, 
     global: false, 
     cache: false, 
     type: "GET", 
     data: {}, 
     dataType: connection.ajaxDataType, 
     error: function (error) { 
       $(connection).triggerHandler(events.onError, [error.responseText]); 
       deferred.reject("SignalR: Error during negotiation request: " + error.responseText); 
       // Stop the connection if negotiate failed 
       connection.stop(); 
      }, 
      success: function (res) { 
       var keepAliveData = connection.keepAliveData; 
       connection.appRelativeUrl = res.Url; 

我得到最后一行和RES参数为null,其轰炸了我的连接尝试。我更新了所有signalR依赖关系,更改了所有集线器客户端调用以使用集线器中的其他客户端/服务器属性。

我/ signalr /正在创建枢纽js脚本,并拥有所有正确的方法映射到服务器端毂的方法我认为可用。 js文件如下:

/*! 
    * ASP.NET SignalR JavaScript Library v1.0.0 
    * http://signalr.net/ 
    * 
    * Copyright Microsoft Open Technologies, Inc. All rights reserved. 
    * Licensed under the Apache 2.0 
    * https://github.com/SignalR/SignalR/blob/master/LICENSE.md 
    * 
    */ 

    /// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" /> 
    /// <reference path="jquery.signalR.js" /> 

     (function ($, window) { 
     /// <param name="$" type="jQuery" /> 

    "use strict"; 

    if (typeof ($.signalR) !== "function") { 
     throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/hubs."); 
    } 

    var signalR = $.signalR; 

    function makeProxyCallback(hub, callback) { 
     return function() { 
      // Call the client hub method 
      callback.apply(hub, $.makeArray(arguments)); 
     }; 
    } 

    function registerHubProxies(instance, shouldSubscribe) { 
     var key, hub, memberKey, memberValue, subscriptionMethod; 

     for (key in instance) { 
      if (instance.hasOwnProperty(key)) { 
       hub = instance[key]; 

       if (!(hub.hubName)) { 
        // Not a client hub 
        continue; 
       } 

       if (shouldSubscribe) { 
        // We want to subscribe to the hub events 
        subscriptionMethod = hub.on; 
       } 
       else { 
        // We want to unsubscribe from the hub events 
        subscriptionMethod = hub.off; 
       } 

       // Loop through all members on the hub and find client hub functions to subscribe/unsubscribe 
       for (memberKey in hub.client) { 
        if (hub.client.hasOwnProperty(memberKey)) { 
         memberValue = hub.client[memberKey]; 

         if (!$.isFunction(memberValue)) { 
          // Not a client hub function 
          continue; 
         } 

         subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue)); 
        } 
       } 
      } 
     } 
    } 

    $.hubConnection.prototype.createHubProxies = function() { 
     var proxies = {}; 
     this.starting(function() { 
      // Register the hub proxies as subscribed 
      // (instance, shouldSubscribe) 
      registerHubProxies(proxies, true); 

      this._registerSubscribedHubs(); 
     }).disconnected(function() { 
      // Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs. 
      // (instance, shouldSubscribe) 
      registerHubProxies(proxies, false); 
     }); 

     proxies.chatHub = this.createHubProxy('chatHub'); 
     proxies.chatHub.client = { }; 
     proxies.chatHub.server = { 
      exitChat: function (chatId) { 
      /// <summary>Calls the ExitChat method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"chatId\" type=\"String\">Server side type is System.String</param> 
       return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["ExitChat"], $.makeArray(arguments))); 
      }, 

      getChat: function (chatId) { 
      /// <summary>Calls the GetChat method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"chatId\" type=\"String\">Server side type is System.String</param> 
       return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["GetChat"], $.makeArray(arguments))); 
      }, 

      joinChat: function (chatId, inviteeUserIds, groupId) { 
      /// <summary>Calls the JoinChat method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"chatId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"inviteeUserIds\" type=\"Object\">Server side type is System.String[]</param> 
      /// <param name=\"groupId\" type=\"String\">Server side type is System.String</param> 
       return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["JoinChat"], $.makeArray(arguments))); 
      }, 

      sendChatMessage: function (chatId, messageId, message) { 
      /// <summary>Calls the SendChatMessage method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"chatId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"messageId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"message\" type=\"String\">Server side type is System.String</param> 
       return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["SendChatMessage"], $.makeArray(arguments))); 
      }, 

      typing: function (chatId, isTyping) { 
      /// <summary>Calls the Typing method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"chatId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"isTyping\" type=\"\">Server side type is System.Boolean</param> 
       return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["Typing"], $.makeArray(arguments))); 
      } 
     }; 

     proxies.debugHub = this.createHubProxy('debugHub'); 
     proxies.debugHub.client = { }; 
     proxies.debugHub.server = { 
      registerWithDebugger: function() { 
      /// <summary>Calls the RegisterWithDebugger method on the server-side DebugHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
       return proxies.debugHub.invoke.apply(proxies.debugHub, $.merge(["RegisterWithDebugger"], $.makeArray(arguments))); 
      } 
     }; 

     proxies.groupHub = this.createHubProxy('groupHub'); 
     proxies.groupHub.client = { }; 
     proxies.groupHub.server = { 
      joinGroup: function (userId, groupId) { 
      /// <summary>Calls the JoinGroup method on the server-side GroupHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"userId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"groupId\" type=\"String\">Server side type is System.String</param> 
       return proxies.groupHub.invoke.apply(proxies.groupHub, $.merge(["JoinGroup"], $.makeArray(arguments))); 
      }, 

      joinGroups: function (userId) { 
      /// <summary>Calls the JoinGroups method on the server-side GroupHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"userId\" type=\"String\">Server side type is System.String</param> 
       return proxies.groupHub.invoke.apply(proxies.groupHub, $.merge(["JoinGroups"], $.makeArray(arguments))); 
      }, 

      leaveGroup: function (userId, groupId) { 
      /// <summary>Calls the LeaveGroup method on the server-side GroupHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"userId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"groupId\" type=\"String\">Server side type is System.String</param> 
       return proxies.groupHub.invoke.apply(proxies.groupHub, $.merge(["LeaveGroup"], $.makeArray(arguments))); 
      } 
     }; 

     proxies.userHub = this.createHubProxy('userHub'); 
     proxies.userHub.client = { }; 
     proxies.userHub.server = { 
      registerUserClient: function (userId) { 
      /// <summary>Calls the RegisterUserClient method on the server-side UserHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"userId\" type=\"String\">Server side type is System.String</param> 
       return proxies.userHub.invoke.apply(proxies.userHub, $.merge(["RegisterUserClient"], $.makeArray(arguments))); 
      }, 

      updateUserClientStatus: function (userId, latestHeartbeat, latestInteractivity) { 
      /// <summary>Calls the UpdateUserClientStatus method on the server-side UserHub hub.&#10;Returns a jQuery.Deferred() promise.</summary> 
      /// <param name=\"userId\" type=\"String\">Server side type is System.String</param> 
      /// <param name=\"latestHeartbeat\" type=\"Object\">Server side type is System.DateTime</param> 
      /// <param name=\"latestInteractivity\" type=\"Object\">Server side type is System.DateTime</param> 
       return proxies.userHub.invoke.apply(proxies.userHub, $.merge(["UpdateUserClientStatus"], $.makeArray(arguments))); 
      } 
     }; 

     return proxies; 
    }; 

    signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false }); 
    $.extend(signalR, signalR.hub.createHubProxies()); 

    }(window.jQuery, window)); 

任何想法?

+1

我只是想相同的代码,这一切为我工作。你有任何自定义信号或路线配置? – 2013-02-11 04:49:52

+0

我要确认这一点,但我认为我的开发机器环境完全是SNAFU – HCdev 2013-02-11 06:35:52

回答

0

原来有什么不妥上面的代码。从SignalR 0.5.3到1.0.x的迁移顺利进行。问题是我的开发环境相当混乱。

有在我们的案例一台庞大的疑难杂症 - 我们也使用RavenDB。在不同版本的NewtonSoft JSON上都存在依赖关系。

如果您处于同时使用这两种技术的情况,请注意将先前版本的NewtonsoftJson中格式化的JSON对象从一个传递到另一个,因为生成的JSON序列化对象不向后兼容。

你必须从乌鸦传递到SignalR JS客户端时,手动映射。