angularjs - Destroying connection when $destroy in SignalR -
i have page running signalr, angular, , typescript. when current $scope
gets destroyed (like page change), try disconnect client signalr server:
controller.ts
$scope.$on("$destroy", () => service.disconnect());
my frontend service has function:
service.ts
public disconnect() { this.hub.disconnect(); }
so when change page, client disconnects hub. works perfectly, can see in console:
signalr: stopping connection.
signalr: closing websocket.
signalr: fired ajax abort async = true.
signalr: stopping monitoring of keep alive.
works perfectly. however, when load new state , connection gets set again, old connection somehow "kept", because tries connect twice. if go different page , again, tries connect 3 times.
edit
it seems statechanged
gets called multiple times. multiple times being amount of times connection setup has been called. hmm, wonder why that, when disconnect client hub. fixed simple if connected
variable set first time connecting, it's not good.
is there proper way disconnect client? should server/backend hub handle disconnection well? should else disconnect client hub, when $scope
destroyed?
why not using this.hub.stop();
Comments
Post a Comment