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

时间:2017-04-05 07:21:57

标签: 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中显示错误。有更好的解决方案吗?

1 个答案:

答案 0 :(得分:3)

在react-native-meteor上,您可以访问DDP协议,因此您可以检查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