3

In this example you connect to Meteor with code like this

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

This is an asynchronous method and, as result, it returns nothing and it also doesn't accept a callback and Meteor.status() right after it will return connected == false. So the only solution I can see is to wrap this check into setTimeout callback with timeout set to, say 5s. Then, in case Meteor.status().connected is still false to show an error in UI. Is there a better solution?

humkins
  • 9,635
  • 11
  • 57
  • 75

1 Answers1

3

On react-native-meteor you have access to DDP protocol so you can check for DDP status like this:

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

And

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

You can also listen for all DDP events exposed here https://github.com/mondora/ddp.js/#public-events

razor7
  • 2,165
  • 2
  • 19
  • 32