Skip to content

v6.1.0

Compare
Choose a tag to compare
@jondubois jondubois released this 06 Jul 21:09
· 501 commits to master since this release

Breaking change

Note that the affected feature was not publicly documented on the website. That's why this is only a minor release.

There is a change to the optional callback to the client socket.publish(channelName, data, callback) function.
The second argument to the callback used to be the data which was published to the channel (after all transformations had been carried-out by the middleware), now the second argument will be undefined by default.
The second argument now needs to be specified explicitly inside the MIDDLEWARE_PUBLISH_IN middleware like this:

scServer.addMiddleware(scServer.MIDDLEWARE_PUBLISH_IN, function (req, next) {
  // This is how you can send back data as the second argument to the client `socket.publish` callback.
  // Note that if you have multiple middleware functions in the MIDDLEWARE_PUBLISH_IN line, the 
  // next middleware function will be able to access the existing req.ackData property and modify it.
  // It's the final state of req.ackData which will be sent back to the client.
  req.ackData = {someCustomProperty: 'This is some data to send back'};
  next();
});

If you want to maintain the old behaviour without having to think, you can just add this middleware function in your code after all other middleware functions in the MIDDLEWARE_PUBLISH_IN line:

scServer.addMiddleware(scServer.MIDDLEWARE_PUBLISH_IN, function (req, next) {
  req.ackData = req.data;
  next();
});