title: Ionic and WebSocket on Android
body: <p>I have a meteor application running on port 3000.<br/> Then I have a ionic application serving a simple client.<br/>I want to see the data adeed in the meteor application in in the ionic application.<br/>I created a service:</p>
  
  <pre><code>(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,
      };
  }
  })();
  </code></pre>
  
  <p>A controller:</p>
  
  <pre><code>angular.module('myApp').controller('MyController',
  function EventController($scope, myApi) {
     myApi.on(function (data) {
          $scope.history.push(data);
      });
      $scope.history = [];
  }
  );
  </code></pre>
  
  <p>A view:</p>
  
  <pre><code> &lt;div ng-controller="MyController" style="padding-left:20px; padding-right:20px"&gt;
      &lt;ul class="thumbnails"&gt;
          &lt;li ng-repeat="item in history"&gt;
              &lt;div class="row span9"&gt;
                 &lt;span&gt;Date: {{item.date}}&lt;/span&gt;
                 &lt;span&gt;Value: {{item.value}}&lt;/span&gt;
              &lt;/div&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>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 <code>ionic serve</code>.<br/>
  When I try a <code>ionic emulate android</code> I cannot see the data in the AVD and I have a 'ReferenceError: WebSocket is not defined' in the LogCat panel.<br/>I tried to install the 'cordova plugin add <a href="https://github.com/knowledgecode/WebSocket-for-Android.git" rel="nofollow">https://github.com/knowledgecode/WebSocket-for-Android.git</a>' but without success. How I can use websockets within a ionic application with the andorid target?</p>