tgoldenberg/meteor-react-native-chat-example

Subscribe and Publish

Closed this issue · 1 comments

I have a sample apps like this, there a problem on subscribing a message..
I run on android, i replace localhost to the ip of my meteor server and its connected and i can send message to the server but in getting message in server and i would like to display it on GUI theres and error.

in my native:

let self = this;
console.log('subscribe');
ddp.subscribe('messages', [])
  .then(() => {
    let messagesObserver = ddp.collections.observe(() => {
      let messages = [];
      if (ddp.collections.messages) {
        messages = ddp.collections.messages.find({});
         console.log(ddp.collections.messages);
      }
      return messages;
    });
    this.setState({messagesObserver: messagesObserver})
    messagesObserver.subscribe((results) => {
      this.setState({messages: results});
      this.refs.invertible.scrollTo(0);
    })
  })

in my server:

//publish to client and subscribe
Meteor.publish('messages', function() {
console.log('Publishing Messages', Messages.find().count());
return Messages.find();
});

here's the error:
error