rust-socketio icon indicating copy to clipboard operation
rust-socketio copied to clipboard

Emit with multiple parameters

Open david-sailplan opened this issue 2 years ago • 10 comments

The Client.emit and Client.emit_with_ack only seem to support a single data parameter

This causes issues for servers who are expecting multiple parameters for the data for these events

rust.rs

socket.emit_with_ack("foo", json!("{ack:true}", duration, callback) 

example_socketio_server.js

socket.on("foo", async (userId, body, callback)=>{})

no mater what is placed in data, it will place all data under the "userId" and no way to populate the body parameter.

Is there a workaround that could fix this?

david-sailplan avatar Oct 19 '22 22:10 david-sailplan

Do you use a special parser for this on the server side?

1c3t3a avatar Oct 20 '22 08:10 1c3t3a

No. We don't use any parser beyond the default behavior of the nodejs package server-side.

const io = socketio(server, { path: '/socket', transports: ['websocket'] })

As seen here the emit function takes an unbound number of arguments. This behavior is handled server side as per this example

david-sailplan avatar Oct 20 '22 15:10 david-sailplan

@david-sailplan https://github.com/1c3t3a/rust-socketio/blob/4ac27c7158a89375c503164857d86b1a1167116c/socketio/src/socket.rs#L105-L109 currently is limit to only two params, L108 accept a string, so there is a tricky way socket .emit("foo", "bar1\",\"bar2\", \"bar3"), you can have a try.

SSebo avatar Oct 21 '22 03:10 SSebo

@SSebo is there currently a better way to do this using "binary data/attachments"?

I know your todo list is probably long, but a proper interface for encoding multiple message parameters would be a great feature :)

syshriki9 avatar Oct 23 '22 23:10 syshriki9

@SSebo is there currently a better way to do this using "binary data/attachments"?

I know your todo list is probably long, but a proper interface for encoding multiple message parameters would be a great feature :)

@1c3t3a @nshaaban-cPacket they are the owners of this repo, I forward your message to them :)

SSebo avatar Oct 24 '22 01:10 SSebo

#249 I made a PR @david-sailplan @syshriki9 You can have a try.

SSebo avatar Oct 24 '22 10:10 SSebo

Wow that was fast!, Thanks @SSebo.

As David mentioned, it seems to work.

syshriki9 avatar Oct 24 '22 20:10 syshriki9

@SSebo @1c3t3a do you guys think this feature will make it into the master?

syshriki9 avatar Dec 05 '22 21:12 syshriki9

also. that…… hmmm well, now the .on can not accept mult payload, so …… anther old issue

shenjackyuanjie avatar Feb 20 '24 13:02 shenjackyuanjie

This issue is mostly done, likely able to close

shenjackyuanjie avatar Mar 31 '24 13:03 shenjackyuanjie