RocketChat / Rocket.Chat.js.SDK

Utility for apps and bots to interact with Rocket.Chat via DDP and/or API
MIT License
136 stars 95 forks source link

Need to subscribe to stream-notify-logged #98

Closed andrecavallari closed 4 years ago

andrecavallari commented 4 years ago

Well, I need to subscribe to stream-notify-logged listening to 'user-status', then I used the method: await driver.subscribe('stream-notify-logged', 'user-status') But, how to listen to the changes on this?

I tryed the following:

driver.asteroid.getCollection('stream-notify-logged').on('change', (_id) => {
  console.log(_id);
})

But only returns a string "id" when any user changes it's status

Any ideas??

andrecavallari commented 4 years ago

Well, got this working, but I really think that should be improved the documentation, maybe latter I submit a PR improving this doc.

For anyone trying to do the same:

await driver.subscribe('stream-notify-logged', 'user-status')
const userStatusCollection = driver.asteroid.getCollection( 'stream-notify-logged' )

userStatusCollection.reactiveQuery({}).on('change', function(_id) {
  const query = userStatusCollection.reactiveQuery({ _id }).result[0].args[0]
  const [userId, username, status] = query
  console.log(userId, username, status)
})