I'm still getting the basics of SignalR down. I'd like to use it in different parts of my website, so I was thinking I could start the connection in the main layout, and add client methods in sub views.
As per this answer I have :
window.hub = $.connection.hub.start();
in my Layout.cshtml, and
window.hub.done(function () {
$.connection.notificationHub.server.joinScannerGroup(1);
alert("in sub view");
});
in my subview, which works. The hub is connected, and the method JoinScannerGroup()
is called. However, if i try to add:
$.connection.notificationHub.client.scanReceived = function (text) {
alert("scan received");
};
anywhere in the javascript for the subview, it never gets called. Maybe I'm undertanding it wrong, but I'd like to connect on the mainpage, and then allow any subpages to receive client calls.
Also, if I move the $.connection.start()
into the subview, it does work correctly. Am I understanding it wrong?