I have a meteor application running on port 3000.
Then I have a ionic application serving a simple client.
I want to see the data adeed in the meteor application in in the ionic application.
I created a service:
(function () {
angular.module('myApp').factory('myApi', ['$q', '$rootScope', myApi]);
function myApi($q, $rootScope) {
var options = {
endpoint: "ws://localhost:3000/websocket",
SocketConstructor: WebSocket
};
var ddp = new DDP(options);
ddp.on("connected", function () {
console.log("Connected");
ddp.sub("allHistory");
});
function on(callback) {
ddp.on("added", function (data) {
console.log("on added", data.fields.value);
var item = { value: data.fields.value, date: data.fields.date };
callback(item);
});
};
return {
on: on,
};
}
})();
A controller:
angular.module('myApp').controller('MyController',
function EventController($scope, myApi) {
myApi.on(function (data) {
$scope.history.push(data);
});
$scope.history = [];
}
);
A view:
<div ng-controller="MyController" style="padding-left:20px; padding-right:20px">
<ul class="thumbnails">
<li ng-repeat="item in history">
<div class="row span9">
<span>Date: {{item.date}}</span>
<span>Value: {{item.value}}</span>
</div>
</li>
</ul>
</div>
Everything works using a web client: I can to get data from the meteor application (using the DDP protocol with the ddp.js implementation) on a web client running the command ionic serve
.
When I try a ionic emulate android
I cannot see the data in the AVD and I have a 'ReferenceError: WebSocket is not defined' in the LogCat panel.
I tried to install the 'cordova plugin add https://github.com/knowledgecode/WebSocket-for-Android.git' but without success. How I can use websockets within a ionic application with the andorid target?