如何处理react本机meteor DDP连接故障?

如何处理react本机meteor DDP连接故障?,meteor,react-native,react-native-meteor,Meteor,React Native,React Native Meteor,你用这样的代码连接到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中显

你用这样的代码连接到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协议,以便检查DDP状态,如下所示:

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


您还可以收听此处公开的所有DDP事件

Hi!你解决这个问题了吗?如果DDP连接丢失,有一个事件来调度将是非常好的…嗨。没有,还没有解决。
Meteor.ddp.on('disconnected', () => {
  console.info('Disconnected from server.');
});