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

How to join/leave a socket.io room #40

Closed
rts-gordon opened this issue Apr 28, 2021 · 4 comments
Closed

How to join/leave a socket.io room #40

rts-gordon opened this issue Apr 28, 2021 · 4 comments

Comments

@rts-gordon
Copy link

Hi there,
I am studying the rust-socketio crate. In my case, I need to join a socket.io room and leave this room when something happened,
so I want to known, how to join and leave a special socket.io room, I didn't found the rust functions.

Thanks for a lot.

@1c3t3a
Copy link
Owner

1c3t3a commented Apr 28, 2021

Hi, thanks for using the crate! You're right, there are no functions concerning rooms, but that's because this crate currently only implements the client and rooms is a fully server side feature. That means managing rooms in any way is done on the server side, a client does not have any information about which room he's in or even which rooms exist on the server side. For further reading visit the official socket.io documentation. An example using this client would look something like this:

server code

// assume you've set up the server somehow
io.on('connection', function(socket) {
    // you can join (leave) a room by calling the join (leave) method
    socket.on('room', function(room) {
        socket.join(room);
    });
});

// this emits to all clients in the room
io.sockets.in("room1").emit('message', 'what is going on, party people?');

client code

use serde_json::json;
// ...
// assume you've connected the client and defined callbacks for certain events
let payload = json!("room1");
socket.emit("room", payload).expect("Server unreachable");

@rts-gordon
Copy link
Author

I see, rust-socketio is only a client crate.

Thanks a lot. @1c3t3a

@rts-gordon
Copy link
Author

Do you have any plan to implement socketio server side features?

@1c3t3a
Copy link
Owner

1c3t3a commented Apr 29, 2021

Actually yes, there is a tracking issue for this (#32). I will tackle it as soon as possible, but if you're interested, feel free to implement it ;)

@1c3t3a 1c3t3a closed this as completed May 3, 2021
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

2 participants