i creating new channel when new user connects to the app.
app.on('connection', connection => {
app.channel('anonymous').join(connection);
app.channel(socket${connection.userId}).join(connection);
console.log('new connection established');
});
And i will have a custom event in user service named notifyuser. i need to emit this only for specific users that i am sending channel names when requesting. Not sure how to archive this with feathers?
You can publish service specific events by returning the channels that you need. The data of the custom event should include the information that you need to identify the channel you want to send to (the connection information is available in a service call as params.connection):
app.service('myservice').publish('notifyuser', data => {
return app.channel(`socket/${data.userId}`);
});
This works well when you know the channel name at the time of receiving connection events. But how to join clients to channels outside the event handlers for connection and login events?
Please see: https://github.com/feathersjs/feathers/issues/1659
Most helpful comment
You can publish service specific events by returning the channels that you need. The data of the custom event should include the information that you need to identify the channel you want to send to (the connection information is available in a service call as params.connection):