2017-10-12 1 views
2

$(document).readyハンドラまたはその略語$(function()でSignalRコールバックを.NET C#サーバ側ハブからJavaScriptクライアント側にラッピングする理由トリガされていないこの特定のコールバック(startdoneの取り扱いや切断作業に関係なく、彼らのラップやないさ...):なぜ私のJS SignalRコールバックをラップするのですか?

サーバー側 - C#のハブ:

public class AppointmentHub : Hub 
{ 
    public void RefreshSchedulers(string ownerConnectionId, string userId) 
    { 
     Clients.User(userId).refreshScheduler(ownerConnectionId); 
    } 
} 

クライアント側 - JavaScriptのハブプロキシ+コールバック:

[...] 

function getSchedulerInstance() { 
    return $('#scheduler').scheduler('instance'); 
} 

$(function() { 

     // If I move this handler below out of the jQuery document ready ($(function()) ... it works... why? 
     $.connection.appointmentHub.client.refreshScheduler = function(ownerConnectionId) { 
      if (getAppointmentHubConnectionId() !== ownerConnectionId) { 
       getSchedulerInstance().repaint(); 
      } 
     }; 

     $.connection.appointmentHub.connection.disconnected(function() { 
      setTimeout(function() { 
       $.connection.appointmentHub.connection.start(); 
       }, 
       500); 
     }); 

     $.connection.appointmentHub.connection.logging = true; 

     $.connection.appointmentHub.connection.start().done(function() { 
     }); 

}); 

function getAppointmentHubConnectionId() { 
    return $.connection.appointmentHub.connection.id; 
} 

function refreshScheduler() { 
    $.connection.appointmentHub.server.refreshSchedulers(getAppointmentHubConnectionId(), '@User.Identity.GetUserId()'); 
} 

[...] 

// Stuff below works 
function onAppointmentDeleted(e) { 
    ui.notify("Appointment deleted.", "success", 600); 
    refreshScheduler(); 
} 

function onAppointmentUpdated(e) { 
    refreshScheduler(); 
} 

function onAppointmentAdded(e) { 
    refreshScheduler(); 
} 

ハブがrefreshSchedulerを呼び出すデバッグモードでチェックしたので、すべてが問題なくなるはずです。

[EDIT]
は、いくつかのログを追加しました:それは動作しますいくつかの理由から$.connection.appointmentHub.connection.logging = true;

クライアント1(グーグルクローム)

[18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: webSockets transport starting. 
jquery.signalR-2.2.2.min.js:9 [18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:52539/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=83lZVSflIHfvK0aJmXokuuQ9lC5%2F4WV6wtzkGcWKXBLrVPhQWC41mduPmu%2FMs3XM%2BezlduQ%2FKoSodH9HouPXECFS69bvKe770QV8iJbFusZPIgxLbFsLNOT8cWDsuV30hUE5QoFhjqBWto7%2BUAYnww%3D%3D&connectionData=%5B%7B%22name%22%3A%22userhub%22%7D%5D&tid=7'. 
jquery.signalR-2.2.2.min.js:9 [18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: Websocket opened. 
jquery.signalR-2.2.2.min.js:9 [18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: webSockets transport connected. Initiating start request. 
jquery.signalR-2.2.2.min.js:9 [18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: The start request succeeded. Transitioning to the connected state. 
jquery.signalR-2.2.2.min.js:9 [18:55:20 GMT-0400 (Eastern Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000 
jquery.signalR-2.2.2.min.js:9 [18:55:53 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking appointmenthub.RefreshSchedulers 
jquery.signalR-2.2.2.min.js:9 [18:55:53 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked appointmenthub.RefreshSchedulers 
jquery.signalR-2.2.2.min.js:9 [18:56:03 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking appointmenthub.RefreshSchedulers 
jquery.signalR-2.2.2.min.js:9 [18:56:03 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked appointmenthub.RefreshSchedulers 

クライアント2(Internet Explorerの11)

[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'appointmenthub'. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'userhub'. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22appointmenthub%22%7D%2C%7B%22name%22%3A%22userhub%22%7D%5D'. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: webSockets transport starting. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:52539/signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=rWeJC23FIMc%2FXJcoF4kw3DNAJIDLk6tZXgKAMe2qWo6jq3TWwwDm0FqgWq%2F7CE3VGer%2FPVKi7hYOqryGcMVvTE1%2BGuBdNhYn76X1u1rw5p3AHuFOn%2BxPFPca0%2FDnYIcV3P5bxQUDZG1IqZL6MGw12w%3D%3D&connectionData=%5B%7B%22name%22%3A%22appointmenthub%22%7D%2C%7B%22name%22%3A%22userhub%22%7D%5D&tid=4'. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Websocket opened. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: webSockets transport connected. Initiating start request. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: The start request succeeded. Transitioning to the connected state. 
[18:55:34 GMT-0400 (Eastern Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000 
[18:55:53 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'refreshScheduler' on hub 'AppointmentHub'. 
[18:55:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking appointmenthub.RefreshSchedulers 
[18:55:57 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'refreshScheduler' on hub 'AppointmentHub'. 
[18:55:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked appointmenthub.RefreshSchedulers 
[18:55:59 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking appointmenthub.RefreshSchedulers 
[18:55:59 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'refreshScheduler' on hub 'AppointmentHub'. 
[18:55:59 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked appointmenthub.RefreshSchedulers 
[18:56:01 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking appointmenthub.RefreshSchedulers 
[18:56:01 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'refreshScheduler' on hub 'AppointmentHub'. 
[18:56:01 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked appointmenthub.RefreshSchedulers 
[18:56:03 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'refreshScheduler' on hub 'AppointmentHub'. 

をクロムからIE11へ、しかしそれ以外の方法ではない... ブラウズには関係ないと思う私はIEの別のタブを開いてOperaに接続しようとしましたが、Chromeから最初のインスタンスIE11まではまだ最初のインスタンスです...ハンドラを準備中の修正から外して、本当に何が起こっているのか分かりません。

+0

ページがDOMに完全に解析される前にrefreshSchedulerを呼び出そうとしていますか? refreshSchedulerの定義はドキュメントの準備ができた状態で作成されているため、その時点以降は存在せず、ロジックが実行されます。それとも、この方法で正しく実行されると言っていますか?その内部に何か誤りがありますか? – Taplar

+0

@Taplar呼び出しは、ページが完全にロードされた後にのみ実行されます。 – Youna

+0

コンソールに表示されているエラーはなんですか? – Taplar

答えて

0

接続を開始する前にハンドラを登録する必要があります。 documentationに詳細が含まれています。

+0

私のコードでは、私の最初の投稿を更新しようとしていることが分かりました。ある特定のブラウザから別のブラウザへの作業を除いて、まだ動作しませんでした – Youna

関連する問題