Search code examples
feathersjs

How to subscribe and listen to channels with feathers client?


Please point me on the right path. I use angular for the client and I get my data with:

  private getOrders(query: {}) {
    return from(this._feathers.service('orders').find({ query }));
  }

this works great and I get an observable in return.

But I don't know how to get the messages on the client side. For instance, the app template in channels.ts mentions something like this:

  app.service('messages').publish(() => {
    return [
      app.channel(`userIds/${data.createdBy}`),
      app.channel(`emails/${data.recipientEmail}`)
    ];
  });

Well, how can I get the data from the client for emails/${data.recipientEmail}? What is the syntax?


Solution

  • Things are actually pretty straight forward!

    My confusion was that I had experience with socket.io and I created a channel per each service I had back then.

    In feathers, the channels are a means of sending the data. So every service can post to any channel and it all depends to which channel you subscribe to! On the client side I had the confusion of how I can access that data thinking that I need a 'custom' channel name and method. This actually does not matter as the clients are subscribed to different channels and in the end data does come from a service and method in that service!

    I hope this makes sense and clears up confusion for people that are like me. :)

    This article clears things up: https://blog.feathersjs.com/feathersjs-channel-subscriptions-647c771ca6c8