signalr - Connect to different Hubs on different pages -


i building single page app uses sammy.js, knockout.js , signalr. main page (index.html) loads additional html pages div based upon client side route.

i have 2 signalr hubs, 1 connected initial page server side push data , works fine. 1 of pages loaded when user navigates should connect different hub.

in main page doing following:

window.hubready = $.connection.hub.start()  var hub1 = $.connection.hub1; hub1.updatereceived = function () {      alert('data server'); }  window.hubready.done(function() {     hub1.server.start();  }); 

in second page have:

var hub2 = $.connection.hub2; hub2.updatereceived = function () {      alert('data server'); }  window.hubready.done(function() {     hub2.server.start();  }); 

however never receive updates in second page.

any idea going wrong?

in order receive updates hub must have @ least 1 client side function declared hub when connection started. judging libraries using i'm assuming have single page application , therefore don't instantiate hub2 data until connection has started.

so easy fix declare hub2 client side function alongside hub1 client side function before start called. if want add more client side functions after connection has started you'll have use .on method.

aka:

hub2.on("updatereceived", function () {     alert("data server"); }); 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -