Sunday, 15 May 2011

angularjs - Connection state with doowb/angular-pusher -



angularjs - Connection state with doowb/angular-pusher -

i trying build angular project pusher using angular-pusher wrapper. it's working need observe when user loses net briefly can retrieve missed changes info server.

it looks way handle reload info on pusher.connection.state('connected'...) not seem work angular-pusher - receiving "pusher.connection" undefined.

here code:

angular.module('respondersapp', ['doowb.angular-pusher']). config(['pusherserviceprovider', function(pusherserviceprovider) { pusherserviceprovider .settoken('foooooooo') .setoptions({}); } ]); var respondercontroller = function($scope, $http, pusher) { $scope.responders = []; pusher.subscribe('responders', 'status', function (item) { // item updated. find in our list , update it. var found = false; (var = 0; < $scope.responders.length; i++) { if ($scope.responders[i].id === item.id) { found = true; $scope.responders[i] = item; break; } } if (!found) { $scope.responders.push(item); } }); pusher.subscribe('responders', 'unavail', function(item) { $scope.responders.splice($scope.responders.indexof(item), 1); }); var retrieveresponders = function () { // list of responders api located @ '/api/responders' console.log('getting responders'); $http.get('/app/dashboard/avail-responders') .success(function (responders) { $scope.responders = responders; }); }; $scope.updateitem = function (item) { console.log('updating item'); $http.post('/api/responders', item); }; // load responders retrieveresponders(); };

under setup how go monitoring connection state? i'm trying replicate firebase "catch up" functionality spotty connections, firebase not working overall me, confusing trying manage multiple info sets (not looking replace back-end @ all).

thanks!

it looks pusher dependency exposes subscribe , unsubscribe. see: https://github.com/doowb/angular-pusher/blob/gh-pages/angular-pusher.js#l86

however, if access pusherservice access pusher instance (the 1 provided pusher js library) using pusherservice.then. see: https://github.com/doowb/angular-pusher/blob/gh-pages/angular-pusher.js#l91

i'm not sure why pusherservice provides level of abstraction , why doesn't homecoming pusher instance. it's can add together of angular specific functionality ($rootscope.$broadcast , $rootscope.$digest).

maybe can set pusherservice dependency , access pusher instance using following?

pusherservice.then(function (pusher) { var state = pusher.connection.state; });

angularjs pusher

No comments:

Post a Comment