ionic 4 - cordova-plugin-chrome-apps-sockets-udp

ionic 4 - cordova-plugin-chrome-apps-sockets-udp

我正在尝试为 android 和 ios 构建离子应用程序。 在这个应用程序中,我需要向服务器发送和接收 udp 数据包。 为此,我尝试使用 https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-udp

但我在 运行 真实设备 android 设备上不断收到此错误:

core.js:9110 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'bind' of undefined
TypeError: Cannot read property 'bind' of undefined 

导致此错误的代码是:

async broadcasting(messageSend)
{

    this.platform.ready().then(
        (readySource) => {
    var udp = require('udp-packet');
    chrome = window['chrome'];
    if(readySource == 'cordova')
    {
      const pack = udp.encode({
        sourceIp: '10.0.0.1',
        sourcePort: 58936,
        destinationIp: '85.214.60.74',
        destinationPort: 7810,
        data: new Buffer(messageSend)
      });

      (<any>window).chrome.sockets.udp.bind(123445, pack,'85.214.60.74',7810, function(result){
        console.log("result bind",result);
      });
      chrome.sockets.udp.send(123445, pack,'85.214.60.74',7810, function(result){
        console.log("result send",result);
      });
      chrome.sockets.udp.onReceive.addListener(function(result){
        console.log("result listener",result);
      });
    }
        });
}

知道我做错了什么吗?

我最后发现我只安装了 tcp 插件,我必须 运行 "cordova plugin add cordova-plugin-chrome-apps-sockets-udp" 才能让它工作。