var app = angular.module('myApp', ['ngWebSocket'])
.factory('MyData', function ($websocket) {
// Open a WebSocket connection
var dataStream = $websocket('ws://118.145.23.94/rwservice');
var collection = [];
dataStream.onMessage(function (message) {
collection.push(JSON.parse(message.data).data.desp);
});
var methods = {
collection: collection,
get: function () {
dataStream.send(JSON.stringify({action: 'get'}));
}
};
return methods;
})
.controller('customersCtrl', function ($scope, MyData) {
$scope.MyData = MyData;
});
;