javascriptsocket.iopostmanfeathersjs

Can't listen to event sent from feathers server to client


I'm building a server which uses feathers and socketio.

I'm trying to use feathers channels mechanism to notify relevant users (connections) on relevant events.
Users belong to groups, so upon connecting to the server, I add the connection to the appropriate channels.
Upon publishing, inside app.publish, I'm getting the right data and see that the connection is attached to the channel, but can't figure out how to listen to it on the client.

This is a simplified channels.js:

app.on('connection', async (connection) => {
    connection.userGroups.forEach((group) => {
        app.channel(`group.groupId`).join(connection);
    }
    app.channel('1').join(connection); // dummy channel
}

app.publish((data, context) => {
    console.log(app.channel('1')); // output shown below
   
    return app.channel('1');
});

I'm using Postman as the client, sending a patch request, and listening to event named rooms patched (rooms is my service name) as described in feathers docs. No event is arriving.
If I'm using the raw socketio instance and emitting from there, everything seems to work fine and I get the event in the client

app.io.sockets.in('some room').emit('rooms patched', data);

but as I understand it, it overrides the whole mechanism of channels.

By examining the output from app.publish

Channel {
  _events: [Object: null prototype] {
    empty: [Function: bound onceWrapper] { listener: [Function (anonymous)] }
  },
  _eventsCount: 1,
  _maxListeners: undefined,
  connections: [
    {
      provider: 'socketio',
      headers: [Object],
      userInfo: [Object],
      userGroups: [Array]
    }
  ],
  data: null,
  [Symbol(kCapture)]: false
}

we can see that the connection is there.

Can anyone help me figure this problem out?


Solution

  • It was a typo

    app.channel(`group.groupId`).join(connection);
    

    instead of

    app.channel(group.groupId).join(connection);