【问题标题】:react native DDP connection for Android为 Android 反应原生 DDP 连接
【发布时间】:2015-10-27 05:43:06
【问题描述】:

我想使用 ddp-client npm 包将我的 react 原生 Android 应用程序连接到 Meteor 后端。这适用于 iOS 应用程序,但我如何将其配置为与 react 本机 Android 一起使用?我安装了最新的 RN 并安装了 ddp-client,但是当我调用 connect() 函数时它会引发错误。这是我在 index.android.js 中的代码:

let ddpclient = new DDPClient({
url: 'ws://localhost:3000/websocket'
});

console.log('DDP', ddpclient);
ddpclient.connect((error, wasReconnect) => {
  if (error) {
    console.log('DDP connection error!');
    return;
  }
  if (wasReconnect) {
    console.log('Reestablishment of a connection');
  }
  console.log('Connected!');
});
ddpclient.subscribe('messages', [], ()=> {
  console.log('messages complete:');
  console.log(ddpclient.collections.messages);
});

ddpclient.on('message', (msg) => {
  console.log('ddp message: ' + msg);
})

【问题讨论】:

    标签: android react-native ddp


    【解决方案1】:

    请使用 ip 地址 'ws://192.168:3000/websocket' 而不是 'ws://localhost:3000/websocket'

    【讨论】:

      【解决方案2】:

      所以这个repo 对这个问题有一个很好的解决方案,根据我的经验,它适用于 iOS 和 Android。

      所以我找到了一种解决方案,尽管我绝对确定它可以优化。通过这种方式,我能够在 React Native Android 应用程序上订阅 3 个单独的 Meteor 集合。就是这样:

      【讨论】:

      • 这有点特殊,但其他看似显而易见的技术只允许我订阅一个
      猜你喜欢
      • 2021-10-25
      • 2017-08-02
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多