Multiple parameters in @SubscribeMessage functions
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
It seems that there is no support for socket adapters that pass multiple parameters to the message handler functions. This becomes an issue when trying to use acknowledgement functions in socket.io for example.
According to #249 this should be possible to do with a custom socket adapter, but I can’t get it to work. Somewhere along the way to the message handler the second parameter is dropped.
Expected behavior
I would like to be able to do something like this:
socket.emit('event', 'some data', function (response) { /*do something*/ });
and then the socket adapter should pass both the data and the function into the message handler function:
@SubscribeMessage('event')
onStart(client, data, ack) {
//Do stuff
ack('stuff completed');
}
I also posted about this here, but no one seems to have a working solution.
Environment
Nest version: 4.6.6
For Tooling issues:
- Node version: 8.10.0
- Platform: Mac
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
How to use the @nestjs/websockets.SubscribeMessage ...
To help you get started, we've selected a few @nestjs/websockets.SubscribeMessage examples, based on popular ways it is used in public projects.
Read more >Gateways | NestJS - A progressive Node.js framework
@SubscribeMessage('events') handleEvent(client: Socket, data: string): string ... In the example above, the handleEvent() function takes two arguments.
Read more >Socket.io acknowledgement in Nest.js
If the socket provider passes multiple arguments into the SubscribeMessage handler the request parameter will be an array with these ...
Read more >Subscribe and Unsubscribe from a Message Channel
In the component's JavaScript, import the message service features required ... The subscribe() method takes three required parameters, the message context, ...
Read more >Paho Python MQTT Client-Subscribe With Examples
The diagram below illustrates the subscribe message flow. The subscribe method accepts 2 parameters – A topic or topics and a QOS (quality ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@BorntraegerMarc Here’s a solution that works for me - not sure if it’s what you need as my experience with websockets is limited.
I have a minimal example here https://github.com/josiahdahl/nestjs-ws-callback-example. Clone it,
yarn install
,yarn run start
, then visitlocalhost:3000
and open your console to see the callback being handled.I wrote this module over nestjs, which do it under the hood so you don’t need to call ack callback explicitly, you only need to return value or throw error: https://www.npmjs.com/package/nestjs-socket-handlers-with-ack . Hope it helps