Reputation: 1034
I'm developing an app with Angular on the client. The app has a set of slides which can be reordered, something like this:
<div ng-controller="SortableCTRL">
<ul id="sortable">
<li ng-repeat="item in sortableArray" ng-bind="item"></li>
</ul>
<button ng-click="add()">Add</button>
<hr>
<pre ng-bind="sortableArray|json"></pre>
</div>
js:
$scope.sortableArray = [
'One', 'Two', 'Three'
];
$scope.add = function() {
$scope.sortableArray.push('Item: '+$scope.sortableArray.length);
sortableEle.refresh();
}
$scope.dragStart = function(e, ui) {
ui.item.data('start', ui.item.index());
}
$scope.dragEnd = function(e, ui) {
var start = ui.item.data('start'),
end = ui.item.index();
$scope.sortableArray.splice(end, 0,
$scope.sortableArray.splice(start, 1)[0]);
$scope.$apply();
}
sortableEle = $('#sortable').sortable({
start: $scope.dragStart,
update: $scope.dragEnd
});
}
http://jsfiddle.net/dj_straycat/Q5FWt/3/
The app can be accessed by more than one person and therefore, it'll be useful to have push notifications when a slide has been added/reordered. On searching I found socket.io is the right way to go; however the company I work for hasn't approved socket.io yet. Is there a way to do this without using socket.io?
Upvotes: 1
Views: 2226
Reputation: 6187
First of all it's important to understand that the term "push notifications" means there is a server that has a service which pushes notifications from the server to the client, in our case the client is angular.
so the right question is, which server technology to use for push notifications, luckily for us we have a wide rang of server and push notification technology's.
in node.js we have socket.io, Microsoft's asp.net has signalR, in the end this services abstract the way we push notifications by using fallback meaning, if our browser supports websocket it will use this connection otherwise fallback to long pulling etc., so to make a long story short and answer your question, you don't have to use socket.io but you do need a server that provides you a good and easy service to push your data, you can even implement your own push service like this example.
Upvotes: 2
Reputation: 7632
Without sockets of some sort, you wouldn't be able to have the exact functionality. You'd need to implement a polling or heartbeat sort of solution. Every X minutes do a small check to the backend to see if any changes have happened.
It wouldn't be the same as real-time though. But it's probably the closest you could get in the mean-time.
If & when your company approves the service there seem to be a lot of examples using Angular + Socket. Alternatively, you could also look at doing something like FireBase - or rather AngularFire.
Upvotes: 5