meteor - 如何处理 react-native-meteor DDP 连接失败?

标签 meteor react-native react-native-meteor

this example你用这样的代码连接到 Meteor

Meteor.connect('ws://192.168.X.X:3000/websocket');//do this only once

这是一个异步方法,因此,它不返回任何内容,也不接受回调,Meteor.status() 将返回 connected == false 。所以我能看到的唯一解决方案是将此检查包装到 setTimeout 回调中,并将超时设置为 5s。然后,如果 Meteor.status().connected 仍然是 false 以在 UI 中显示错误。有更好的解决方案吗?

最佳答案

在 react-native-meteor 上,您可以访问 DDP 协议(protocol),因此您可以像这样检查 DDP 状态:

Meteor.ddp.on('connected', () => {
  console.info('Conection con server stablished.');
});

Meteor.ddp.on('disconnected', () => {
  console.info('Disconnected from server.');
});

您还可以监听此处公开的所有 DDP 事件 https://github.com/mondora/ddp.js/#public-events

关于meteor - 如何处理 react-native-meteor DDP 连接失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224471/

相关文章:

meteor - choco Meteor 安装 - 自定义/不同的安装位置

css - 如何阻止 meteor 自动合并我的 css 文件?

javascript - 如何在react-native中从AsyncStorage中删除特定项目?

react-native - 如何在 React Native Expo 应用程序中集成 i18n-js

react-native - react 原生可触摸突出显示和可触摸的原生反馈,以制作我的菜单项

javascript - 将 this.unblock() 与 Meteor percolate 一起使用 :synced-cron

javascript - Meteor session.set/get 和 jquery 模式