FeathersJS Channel Subscriptions

Matt Chaffe
The Feathers Flightpath
3 min readFeb 12, 2019

--

Photo by chuttersnap on Unsplash

FeathersJS Channels are a great way to handle real-time data. However, sometimes you might only want certain data on a certain page. For example, you may have a chatroom app which has multiple rooms and you only want to provide data for a room that a user is viewing.

On the server

To be able to handle channels on the fly, I am going to configure a custom service which will handle joining and leaving channels.

In the above snippet custom service class we use the create method to join the channel and the remove method to leave the channel.

Service

Now to configure the service to emit data to the channels, within the *-service.js file, we can configure a custom publish. This will emit data only to the channels which exist and will filter out the current user. So the user that created the message within the room, won’t get an .on('created')event when they create a new message, but all other subscribed users will get this.

--

--