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

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

Ionic with UDP client with Cordova Plugin #14

Closed wjrivera closed 7 years ago

wjrivera commented 7 years ago

I used the following command to add the plugin to my project: https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp

Then I created a controller with a function below:

app.controller('ctrl3', function ($scope) {
  $scope.udpClient = function () {
    console.log("success");
    var data, addr, port;
    port = 5000;
    addr = "192.168.10.255";
    data = "hello";
    chrome.sockets.udp.create({}, function(socketInfo) {
      var socketId = socketInfo.socketId;
      chrome.sockets.udp.send(socketId, data,
        addr, port, function(sendInfo) {
          alert("sent " + sendInfo.bytesSent);
        });
    });
    $scope.Message = "Button Clicked";
  };
});

And I get an error:

Cannot read property 'udp' of undefined at Scope.$scope.udpClient Am I doing something wrong?

Cordova CLI: 6.3.1 Ionic Framework: 1.3.1 Ionic CLI: 1.7.16 OS: Windows 7 Pro Node: 4.4.7

Below is the whole code for app.js

var app = angular.module('ctrl1', ['ionic']);

app.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
//cordova.plugins.
//window.plugins.cordova-plugin-chrome-apps-sockets-udp.create()

  // Don't remove this line unless you know what you are doing. It stops the viewport
  // from snapping when text inputs are focused. Ionic handles this internally for
  // a much nicer keyboard experience.
  cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
  StatusBar.styleDefault();
}

console.log("Hello");
});
});

app.controller('ctrl2', function ($scope) {
$scope.dateToday = new Date();
$scope.x = 5;
$scope.y = 6;

});

app.controller('ctrl3', function ($scope) {
$scope.udpClient = function () {
console.log("success");

var data, addr, port;
port = 5000;
addr = "192.168.10.255";
data = "hello";

chrome.sockets.udp.create({}, function(socketInfo) {
  var socketId = socketInfo.socketId;
  chrome.sockets.udp.send(socketId, data,
    addr, port, function(sendInfo) {
      alert("sent " + sendInfo.bytesSent);
    });
});

$scope.Message = "Button Clicked";
};
});