3

这个例子中,你使用这样的代码连接到 Meteor

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

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

4

1 回答 1

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

于 2017-09-25T10:48:37.570 回答