Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit with multiple parameters #246

Open
david-sailplan opened this issue Oct 19, 2022 · 10 comments
Open

Emit with multiple parameters #246

david-sailplan opened this issue Oct 19, 2022 · 10 comments

Comments

@david-sailplan
Copy link

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 david-sailplan changed the title Emission with multiple parameters Emit with multiple parameters Oct 19, 2022
@1c3t3a
Copy link
Owner

1c3t3a commented Oct 20, 2022

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

@david-sailplan
Copy link
Author

david-sailplan commented Oct 20, 2022

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

@SSebo
Copy link
Contributor

SSebo commented Oct 21, 2022

@david-sailplan

let payload = if serde_json::from_str::<serde_json::Value>(&str_data).is_ok() {
format!("[\"{}\",{}]", String::from(event), str_data)
} else {
format!("[\"{}\",\"{}\"]", String::from(event), str_data)
};
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.

@syshriki9
Copy link

@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 :)

@SSebo
Copy link
Contributor

SSebo commented Oct 24, 2022

@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
Copy link
Contributor

SSebo commented Oct 24, 2022

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

@syshriki9
Copy link

Wow that was fast!, Thanks @SSebo.

As David mentioned, it seems to work.

@syshriki9
Copy link

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

@shenjackyuanjie
Copy link
Contributor

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

@shenjackyuanjie
Copy link
Contributor

This issue is mostly done, likely able to close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants