MobileChromeApps / cordova-plugin-chrome-apps-sockets-udp

BSD 3-Clause "New" or "Revised" License
80 stars 39 forks source link

how to use this in Angular Ionic application #5

Open TechWithRamaa opened 9 years ago

TechWithRamaa commented 9 years ago

How to integrate this into Angular or Ionic application?

jnsat commented 9 years ago

I also want to know. I tried doing it like this

angular.module('key', ['ionic'])
//.factory('udpfact')
.controller('keyctrl', ['$scope', 'chrome', function($scope, chrome) {
  //nothin
}])
  .run(function($ionicPlatform, $timeout) {
    alert("runnin");
    $ionicPlatform.ready(function() {
      alert('window.cordova: ' + Object.keys(window.cordova).join(', '));
      alert('window.cordova: ' + Object.keys(window.cordova.plugins).join(', '));
      alert(JSON.stringify(window.cordova));
      alert(JSON.stringify(window.cordova.plugins));

      alert("printed windows.cordova");
      $scope.sendcmd = function sendcmd(cmd) {
        alert("cmd: " + cmd);
        chrome.sockets.udp.create({}, function(socketInfo) {
          var socketId = socketInfo.socketId;
          chrome.sockets.udp.send(socketId, cmd,
            '10.0.0.9', 2390, function(sendInfo) {
              alert("sent " + sendInfo.bytesSent);
          });
        });
      };
  });
});

But it only shows one plugin (keyboard).

digitalcatnip commented 9 years ago

Hi,

I was able to use this in my Ionic application by referencing chrome.sockets.udp.. Don't use 'window.cordova.plugins' .

nutella commented 9 years ago

I've added this plugin with ionic plugin add, then I need to load any js or is automatic? Because if I try to run a sample app, I always get that chrome is not defined... What's wrong? Thanks...

digitalcatnip commented 9 years ago

Are you checking that chrome is defined in the $ionicPlatform.ready callback? It should be in your module.run function.

jnsat commented 9 years ago

Hi digitialcatnip, Thank you for your info. I am using chrome.sockets.udp. The plugin lines were to print a list of plugins loaded. It did not show chrome. Oh, so are you saying chrome should be passed to run and not controller?

nutella commented 9 years ago

Nice... Waiting for deviceready before using the plugin works for me! Thanks.

rohit-gandhe commented 7 years ago

@nutella Can you please paste your code here for reference?

nutella commented 7 years ago

You can look at: https://github.com/nutella/ionic-cordova-chrome-udp-example

rohit-gandhe commented 7 years ago

NICE! :)

Thanks!!!